Repository: incubator-systemml Updated Branches: refs/heads/master 2ccd00c01 -> 50541d32e
[SYSTEMML-413] Cleanup matrix block (remove maxrow/col, canonical reset) Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/50541d32 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/50541d32 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/50541d32 Branch: refs/heads/master Commit: 50541d32e008e6dc8fbcd7f59a4d3ce25586d168 Parents: 2ccd00c Author: Matthias Boehm <[email protected]> Authored: Mon Aug 15 21:47:09 2016 -0700 Committer: Matthias Boehm <[email protected]> Committed: Tue Aug 16 10:12:42 2016 -0700 ---------------------------------------------------------------------- .../spark/utils/FrameRDDConverterUtils.java | 10 +- .../sysml/runtime/matrix/data/CM_N_COVCell.java | 39 +-- .../runtime/matrix/data/LibMatrixBincell.java | 6 +- .../runtime/matrix/data/LibMatrixDatagen.java | 4 +- .../sysml/runtime/matrix/data/MatrixBlock.java | 264 ++++++------------- .../sysml/runtime/matrix/data/MatrixCell.java | 24 +- .../sysml/runtime/matrix/data/MatrixValue.java | 7 +- .../matrix/data/OperationsOnMatrixValues.java | 6 +- .../mapred/MRBaseForCommonInstructions.java | 29 +- 9 files changed, 120 insertions(+), 269 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/FrameRDDConverterUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/FrameRDDConverterUtils.java b/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/FrameRDDConverterUtils.java index c243eeb..3bd163c 100644 --- a/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/FrameRDDConverterUtils.java +++ b/src/main/java/org/apache/sysml/runtime/instructions/spark/utils/FrameRDDConverterUtils.java @@ -841,7 +841,7 @@ public class FrameRDDConverterUtils //Global index within frame blocks long colixLow = (int)((matrixIndexes.getColumnIndex()-1)*_bclen+1); - long colixHigh = Math.min(colixLow+matrixBlock.getMaxColumn()-1, _clen); + long colixHigh = Math.min(colixLow+matrixBlock.getNumColumns()-1, _clen); //Index within a local matrix block int iColLowMat = UtilFunctions.computeCellInBlock(colixLow, _bclen); @@ -850,18 +850,18 @@ public class FrameRDDConverterUtils FrameBlock tmpBlock = DataConverter.convertToFrameBlock(matrixBlock); int iRowLow = 0; //Index within a local frame block - while(iRowLow < matrixBlock.getMaxRow()) { - int iRowHigh = Math.min(iRowLow+_maxRowsPerBlock-1, matrixBlock.getMaxRow()-1); + while(iRowLow < matrixBlock.getNumRows()) { + int iRowHigh = Math.min(iRowLow+_maxRowsPerBlock-1, matrixBlock.getNumRows()-1); FrameBlock tmpBlock2 = null; //All rows from matrix block can fit into single frame block, no need for slicing - if(iRowLow == 0 && iRowHigh == matrixBlock.getMaxRow()-1) + if(iRowLow == 0 && iRowHigh == matrixBlock.getNumRows()-1) tmpBlock2 = tmpBlock; else tmpBlock2 = tmpBlock.sliceOperations(iRowLow, iRowHigh, iColLowMat, iColHighMat, tmpBlock2); //If Matrix has only one column block, then simply assigns converted block to frame block - if(colixLow == 0 && colixHigh == matrixBlock.getMaxColumn()-1) + if(colixLow == 0 && colixHigh == matrixBlock.getNumColumns()-1) ret.add(new Tuple2<Long, FrameBlock>(rowix+iRowLow, tmpBlock2)); else { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/CM_N_COVCell.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/CM_N_COVCell.java b/src/main/java/org/apache/sysml/runtime/matrix/data/CM_N_COVCell.java index 58bd529..7da4979 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/CM_N_COVCell.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/CM_N_COVCell.java @@ -89,16 +89,6 @@ public class CM_N_COVCell extends MatrixValue implements WritableComparable } @Override - public int getMaxColumn() throws DMLRuntimeException { - return 1; - } - - @Override - public int getMaxRow() throws DMLRuntimeException { - return 1; - } - - @Override public long getNonZeros() { return 1; } @@ -150,42 +140,25 @@ public class CM_N_COVCell extends MatrixValue implements WritableComparable } @Override - public void reset() { - } + public void reset() {} @Override - public void reset(int rl, int cl) { - - } + public void reset(int rl, int cl) {} @Override - public void reset(int rl, int cl, boolean sp) { - } + public void reset(int rl, int cl, boolean sp) {} - public void reset(int rl, int cl, boolean sp, long nnzs) - { - } + @Override + public void reset(int rl, int cl, boolean sp, long nnzs) {} @Override - public void resetDenseWithValue(int rl, int cl, double v) { - throw new RuntimeException("operation not supported fro WeightedCell"); - } + public void reset(int rl, int cl, double v) {} @Override public MatrixValue scalarOperations(ScalarOperator op, MatrixValue result) throws DMLRuntimeException { throw new DMLRuntimeException("operation not supported fro WeightedCell"); } - - @Override - public void setMaxColumn(int c) throws DMLRuntimeException { - - } - - @Override - public void setMaxRow(int r) throws DMLRuntimeException { - - } @Override public void setValue(int r, int c, double v) { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java index 8e7d330..648b63d 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixBincell.java @@ -765,7 +765,7 @@ public class LibMatrixBincell if( ret.sparse ) ret.allocateSparseRowsBlock(); - if(LibMatrixOuterAgg.isCompareOperator(op) && SortUtils.isSorted(0, m2.getMaxColumn(), DataConverter.convertToDoubleVector(m2))) { + if(LibMatrixOuterAgg.isCompareOperator(op) && SortUtils.isSorted(0, m2.getNumColumns(), DataConverter.convertToDoubleVector(m2))) { performBinOuterOperation(m1, m2, ret, op); } else { for(int r=0; r<rlen; r++) { @@ -902,7 +902,7 @@ public class LibMatrixBincell //TODO performance improvement for relational operations like ">" //sort rhs by val, compute cutoff and memset 1/0 for halfs - if(LibMatrixOuterAgg.isCompareOperator(op) && SortUtils.isSorted(0, m2.getMaxColumn(), DataConverter.convertToDoubleVector(m2))) { + if(LibMatrixOuterAgg.isCompareOperator(op) && SortUtils.isSorted(0, m2.getNumColumns(), DataConverter.convertToDoubleVector(m2))) { performBinOuterOperation(m1, m2, ret, op); } else { for(int r=0; r<rlen; r++) { @@ -1033,7 +1033,7 @@ public class LibMatrixBincell //compute 0 op constant once and set into dense output double val = op.executeScalar(0); if( val != 0 ) - ret.init(val, ret.rlen, ret.clen); + ret.reset(ret.rlen, ret.clen, val); return; } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDatagen.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDatagen.java b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDatagen.java index c59b3e7..f13515a 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDatagen.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/LibMatrixDatagen.java @@ -316,7 +316,7 @@ public class LibMatrixDatagen else if( !out.sparse && sparsity==1.0d && (min == max //equal values, dense || (Double.isNaN(min) && Double.isNaN(max))) ) //min == max == NaN { - out.init(min, out.rlen, out.clen); + out.reset(out.rlen, out.clen, min); return; } } @@ -407,7 +407,7 @@ public class LibMatrixDatagen return; } else if( !out.sparse && sparsity==1.0d && min == max ) { //equal values - out.init(min, out.rlen, out.clen); + out.reset(out.rlen, out.clen, min); return; } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java index 8bd7b79..ccd28af 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java @@ -121,10 +121,6 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab //sparse-block-specific attributes (allocation only) protected int estimatedNNzsPerRow = -1; - - //ctable-specific attributes - protected int maxrow = -1; - protected int maxcolumn = -1; //grpaggregate-specific attributes (optional) protected int numGroups = -1; @@ -137,57 +133,34 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab // Matrix Constructors // - public MatrixBlock() - { - rlen = 0; - clen = 0; - sparse = true; - nonZeros = 0; - maxrow = 0; - maxcolumn = 0; + public MatrixBlock() { + this(0, 0, true, -1); } - public MatrixBlock(int rl, int cl, boolean sp) - { - rlen = rl; - clen = cl; - sparse = sp; - nonZeros = 0; - maxrow = 0; - maxcolumn = 0; + + public MatrixBlock(int rl, int cl, boolean sp) { + this(rl, cl, sp, -1); } - public MatrixBlock(int rl, int cl, long estnnzs) - { - this(rl, cl, false, estnnzs); - - // Adjust sparsity based on estimated non-zeros - double denseSize = estimateSizeDenseInMemory(rl, cl); - double sparseSize = estimateSizeSparseInMemory(rl, cl, (double)estnnzs/(rl*cl)); - this.sparse = (denseSize < sparseSize ? false : true); - + public MatrixBlock(int rl, int cl, long estnnz) { + this(rl, cl, evalSparseFormatInMemory(rl, cl, estnnz), estnnz); } - public MatrixBlock(int rl, int cl, boolean sp, long estnnzs) - { - this(rl, cl, sp); - estimatedNNzsPerRow=(int)Math.ceil((double)estnnzs/(double)rl); + public MatrixBlock(int rl, int cl, boolean sp, long estnnz) { + reset(rl, cl, sp, estnnz, 0); } - public MatrixBlock(MatrixBlock that) - { - this.copy(that); + public MatrixBlock(MatrixBlock that) { + copy(that); } - public MatrixBlock(MatrixBlock that, SparseBlock.Type stype, boolean deep) - { + public MatrixBlock(MatrixBlock that, SparseBlock.Type stype, boolean deep) { + this(that.rlen, that.clen, that.sparse); + //sanity check sparse matrix block if( !that.isInSparseFormat() ) throw new RuntimeException("Sparse matrix block expected."); //deep copy and change sparse block type - rlen = that.rlen; - clen = that.clen; - sparse = that.sparse; nonZeros = that.nonZeros; estimatedNNzsPerRow = that.estimatedNNzsPerRow; sparseBlock = SparseBlockFactory @@ -198,87 +171,82 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab // Initialization methods // (reset, init, allocate, etc) - public void reset() - { - reset(-rlen); - } - - public void reset(long estnnzs) - { - estimatedNNzsPerRow=(int)Math.ceil((double)estnnzs/(double)rlen); - if(sparse) - { - resetSparse(); - } - else - { - if(denseBlock!=null) - { - if(denseBlock.length<rlen*clen) - denseBlock=null; - else - Arrays.fill(denseBlock, 0, rlen*clen, 0); - } - } - nonZeros=0; - - //operation-specific attributes - maxrow = rlen; - maxcolumn = clen; - numGroups = -1; + @Override + public void reset() { + reset(rlen, clen, sparse, -1, 0); } + @Override public void reset(int rl, int cl) { - rlen=rl; - clen=cl; - nonZeros=0; - reset(); + reset(rl, cl, sparse, -1, 0); } - public void reset(int rl, int cl, long estnnzs) { - rlen=rl; - clen=cl; - nonZeros=0; - reset(estnnzs); + public void reset(int rl, int cl, long estnnz) { + reset(rl, cl, evalSparseFormatInMemory(rl, cl, estnnz), estnnz, 0); } - + + @Override public void reset(int rl, int cl, boolean sp) { - sparse=sp; - reset(rl, cl); + reset(rl, cl, sp, -1, 0); } - public void reset(int rl, int cl, boolean sp, long estnnzs) { - sparse=sp; - reset(rl, cl, estnnzs); + @Override + public void reset(int rl, int cl, boolean sp, long estnnz) { + reset(rl, cl, sp, estnnz, 0); } - public void resetSparse() { - if(sparseBlock != null) { - sparseBlock.reset(estimatedNNzsPerRow, clen); - } + @Override + public void reset(int rl, int cl, double val) { + reset(rl, cl, false, -1, val); } - public void resetDenseWithValue(int rl, int cl, double v) - throws DMLRuntimeException - { - estimatedNNzsPerRow=-1; - rlen=rl; - clen=cl; - sparse=false; + /** + * Internal canonical reset of dense and sparse matrix blocks. + * + * @param rl number of rows + * @param cl number of columns + * @param sp sparse representation + * @param estnnz estimated number of non-zeros + * @param val initialization value + */ + private void reset(int rl, int cl, boolean sp, long estnnz, double val) { + //reset basic meta data + rlen = rl; + clen = cl; + sparse = (val == 0) ? sp : false; + nonZeros = (val == 0) ? 0 : rl*cl; + estimatedNNzsPerRow = (estnnz < 0 || !sparse) ? -1 : + (int)Math.ceil((double)estnnz/(double)rlen); - if(v==0) - { - reset(); - return; + //reset sparse/dense blocks + if( sparse ) { + resetSparse(); + } + else { + resetDense(val); } - //allocate dense block - allocateDenseBlock(); - - //init with constant value (non-zero, see above) - int limit = rlen * clen; - Arrays.fill(denseBlock, 0, limit, v); - nonZeros=limit; + //reset operation-specific attributes + numGroups = -1; + diag = false; + } + + private void resetSparse() { + if(sparseBlock == null) + return; + sparseBlock.reset(estimatedNNzsPerRow, clen); + } + + private void resetDense(double val) { + //handle to dense block allocation + if( denseBlock != null && denseBlock.length<rlen*clen && val==0) + denseBlock = null; + else if( val != 0 ) + allocateDenseBlock(false); + + //reset dense block to given value + if( denseBlock != null ) + Arrays.fill(denseBlock, 0, rlen*clen, val); } /** @@ -305,9 +273,6 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab for(int i=0, ix=0; i < r; i++, ix+=clen) System.arraycopy(arr[i], 0, denseBlock, ix, arr[i].length); recomputeNonZeros(); - - maxrow = r; - maxcolumn = c; } /** @@ -333,47 +298,6 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab //copy and compute nnz System.arraycopy(arr, 0, denseBlock, 0, arr.length); recomputeNonZeros(); - - maxrow = r; - maxcolumn = c; - } - - /** - * - * @param val - * @param r - * @param c - * @throws DMLRuntimeException - */ - public void init(double val, int r, int c) - throws DMLRuntimeException - { - //input checks - if ( sparse ) - throw new DMLRuntimeException("MatrixBlockDSM.init() can be invoked only on matrices with dense representation."); - if( r*c > rlen*clen ) - throw new DMLRuntimeException("MatrixBlockDSM.init() invoked with too large dimensions ("+r+","+c+") vs ("+rlen+","+clen+")"); - - if( val != 0 ) { - //allocate or resize dense block - allocateDenseBlock(); - - if( r*c == rlen*clen ) { //FULL MATRIX INIT - //memset value - Arrays.fill(denseBlock, val); - } - else { //PARTIAL MATRIX INIT - //rowwise memset value - for(int i=0, ix=0; i < r; i++, ix+=clen) - Arrays.fill(denseBlock, ix, ix+c, val); - } - - //set non zeros to input dims - nonZeros = r*c; - } - - maxrow = r; - maxcolumn = c; } /** @@ -547,38 +471,6 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab return (rlen == 1 || clen == 1); } - - /** - * Return the maximum row encountered WITHIN the current block - * - */ - public int getMaxRow() { - if (!sparse) - return getNumRows(); - else - return maxrow; - } - - public void setMaxRow(int r) { - maxrow = r; - } - - - /** - * Return the maximum column encountered WITHIN the current block - * - */ - public int getMaxColumn() { - if (!sparse) - return getNumColumns(); - else - return maxcolumn; - } - - public void setMaxColumn(int c) { - maxcolumn = c; - } - @Override public boolean isEmpty() { return isEmptyBlock(false); @@ -3008,13 +2900,13 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab //(otherwise full init with val0, no need for computation) if( isEmptyBlock(false) ) { if( val0 != 0 ) - ret.init(val0, m, n); + ret.reset(m, n, val0); return; } //redirection to sparse safe operation w/ init by val0 if( sparse && val0 != 0 ) - ret.init(val0, m, n); + ret.reset(m, n, val0); sparseUnaryOperations(op, ret); } @@ -4569,7 +4461,7 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab { //initialize result if(op.aggOp.initialValue!=0) - result.resetDenseWithValue(result.rlen, result.clen, op.aggOp.initialValue); + result.reset(result.rlen, result.clen, op.aggOp.initialValue); CellIndex tempCellIndex = new CellIndex(-1,-1); KahanObject buffer=new KahanObject(0,0); @@ -4621,7 +4513,7 @@ public class MatrixBlock extends MatrixValue implements CacheBlock, Externalizab { //initialize if(op.aggOp.initialValue!=0) - result.resetDenseWithValue(result.rlen, result.clen, op.aggOp.initialValue); + result.reset(result.rlen, result.clen, op.aggOp.initialValue); CellIndex tempCellIndex = new CellIndex(-1,-1); KahanObject buffer=new KahanObject(0,0); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixCell.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixCell.java b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixCell.java index 92794aa..62db808 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixCell.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixCell.java @@ -154,8 +154,8 @@ public class MatrixCell extends MatrixValue implements WritableComparable, Seria } @Override - public void resetDenseWithValue(int rl, int cl, double v) { - value=0; + public void reset(int rl, int cl, double v) { + value=v; } @Override @@ -295,26 +295,6 @@ public class MatrixCell extends MatrixValue implements WritableComparable, Seria } @Override - public int getMaxColumn() throws DMLRuntimeException { - throw new DMLRuntimeException("getMaxColumn() can not be executed on cells"); - } - - @Override - public int getMaxRow() throws DMLRuntimeException { - throw new DMLRuntimeException("getMaxRow() can not be executed on cells"); - } - - @Override - public void setMaxColumn(int c) throws DMLRuntimeException { - throw new DMLRuntimeException("setMaxColumn() can not be executed on cells"); - } - - @Override - public void setMaxRow(int r) throws DMLRuntimeException { - throw new DMLRuntimeException("setMaxRow() can not be executed on cells"); - } - - @Override public void incrementalAggregate(AggregateOperator aggOp, MatrixValue correction, MatrixValue newWithCorrection) throws DMLRuntimeException { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixValue.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixValue.java b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixValue.java index dd8fd17..ae63b6d 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixValue.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixValue.java @@ -92,17 +92,12 @@ public abstract class MatrixValue implements WritableComparable public abstract boolean isInSparseFormat(); public abstract boolean isEmpty(); - - public abstract int getMaxRow() throws DMLRuntimeException;; - public abstract int getMaxColumn() throws DMLRuntimeException;; - public abstract void setMaxRow(int _r) throws DMLRuntimeException; - public abstract void setMaxColumn(int _c) throws DMLRuntimeException;; public abstract void reset(); public abstract void reset(int rl, int cl); public abstract void reset(int rl, int cl, boolean sp); public abstract void reset(int rl, int cl, boolean sp, long nnzs); - public abstract void resetDenseWithValue(int rl, int cl, double v) throws DMLRuntimeException ; + public abstract void reset(int rl, int cl, double v) throws DMLRuntimeException ; public abstract void copy(MatrixValue that); public abstract void copy(MatrixValue that, boolean sp); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java b/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java index a105e6d..a467cfc 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/OperationsOnMatrixValues.java @@ -239,8 +239,8 @@ public class OperationsOnMatrixValues correction.reset(corRow, corCol, false); } else { - valueOut.resetDenseWithValue(outRow, outCol, op.initialValue); - correction.resetDenseWithValue(corRow, corCol, op.initialValue); + valueOut.reset(outRow, outCol, op.initialValue); + correction.reset(corRow, corCol, op.initialValue); } } @@ -249,7 +249,7 @@ public class OperationsOnMatrixValues if(op.initialValue==0) valueOut.reset(rlen, clen, sparseHint); else - valueOut.resetDenseWithValue(rlen, clen, op.initialValue); + valueOut.reset(rlen, clen, op.initialValue); } } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/50541d32/src/main/java/org/apache/sysml/runtime/matrix/mapred/MRBaseForCommonInstructions.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/mapred/MRBaseForCommonInstructions.java b/src/main/java/org/apache/sysml/runtime/matrix/mapred/MRBaseForCommonInstructions.java index 78d1613..cdefc22 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/mapred/MRBaseForCommonInstructions.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/mapred/MRBaseForCommonInstructions.java @@ -29,7 +29,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.mapred.MapReduceBase; import org.apache.hadoop.mapred.Reporter; - import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat; import org.apache.sysml.runtime.controlprogram.parfor.stat.InfrastructureAnalyzer; @@ -50,6 +49,8 @@ import org.apache.sysml.runtime.instructions.mr.ReorgInstruction; import org.apache.sysml.runtime.instructions.mr.UnaryMRInstructionBase; import org.apache.sysml.runtime.instructions.mr.ZeroOutInstruction; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; +import org.apache.sysml.runtime.matrix.data.MatrixBlock; +import org.apache.sysml.runtime.matrix.data.MatrixCell; import org.apache.sysml.runtime.matrix.data.MatrixIndexes; import org.apache.sysml.runtime.matrix.data.MatrixValue; @@ -131,14 +132,8 @@ public class MRBaseForCommonInstructions extends MapReduceBase // compute dimensions for the resulting matrix // find the maximum row index and column index encountered in current output block/cell - long maxrow=0, maxcol=0; - - try { - maxrow = value.getMaxRow(); - maxcol = value.getMaxColumn(); - } catch (DMLRuntimeException e) { - throw new IOException(e); - } + long maxrow = getMaxDimension(indexes, value, true); + long maxcol = getMaxDimension(indexes, value, false); if ( maxrow > resultsMaxRowDims[i] ) resultsMaxRowDims[i] = maxrow; @@ -333,4 +328,20 @@ public class MRBaseForCommonInstructions extends MapReduceBase } } } + + /** + * Returns the maximum row or column dimension of the given key and value pair. + * + * @param key + * @param value + * @param row + * @return + */ + private long getMaxDimension( MatrixIndexes key, MatrixValue value, boolean row ) { + if( value instanceof MatrixCell ) + return row ? key.getRowIndex() : key.getColumnIndex(); + else if( value instanceof MatrixBlock ) + return row ? value.getNumRows() : value.getNumColumns(); + return 0; + } }
