use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class CumulativeAggregateInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
if (blkList == null)
return;
for (IndexedMatrixValue in1 : blkList) {
if (in1 == null)
continue;
MatrixIndexes inix = in1.getIndexes();
// output allocation
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
// process instruction
OperationsOnMatrixValues.performAggregateUnary(inix, in1.getValue(), out.getIndexes(), out.getValue(), ((AggregateUnaryOperator) optr), blockRowFactor, blockColFactor);
if (((AggregateUnaryOperator) optr).aggOp.correctionExists)
((MatrixBlock) out.getValue()).dropLastRowsOrColumns(((AggregateUnaryOperator) optr).aggOp.correctionLocation);
// cumsum expand partial aggregates
long rlenOut = (long) Math.ceil((double) _mcIn.getRows() / blockRowFactor);
long rixOut = (long) Math.ceil((double) inix.getRowIndex() / blockRowFactor);
int rlenBlk = (int) Math.min(rlenOut - (rixOut - 1) * blockRowFactor, blockRowFactor);
int clenBlk = out.getValue().getNumColumns();
int posBlk = (int) ((inix.getRowIndex() - 1) % blockRowFactor);
MatrixBlock outBlk = new MatrixBlock(rlenBlk, clenBlk, false);
outBlk.copy(posBlk, posBlk, 0, clenBlk - 1, (MatrixBlock) out.getValue(), true);
MatrixIndexes outIx = out.getIndexes();
outIx.setIndexes(rixOut, outIx.getColumnIndex());
out.set(outIx, outBlk);
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class CumulativeSplitInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
if (blkList == null)
return;
for (IndexedMatrixValue in1 : blkList) {
if (in1 == null)
continue;
MatrixIndexes inix = in1.getIndexes();
MatrixBlock blk = (MatrixBlock) in1.getValue();
long rixOffset = (inix.getRowIndex() - 1) * blockRowFactor;
boolean firstBlk = (inix.getRowIndex() == 1);
boolean lastBlk = (inix.getRowIndex() == _lastRowBlockIndex);
// introduce offsets w/ init value for first row
if (firstBlk) {
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
((MatrixBlock) out.getValue()).reset(1, blk.getNumColumns());
if (_initValue != 0) {
for (int j = 0; j < blk.getNumColumns(); j++) ((MatrixBlock) out.getValue()).appendValue(0, j, _initValue);
}
out.getIndexes().setIndexes(1, inix.getColumnIndex());
}
// output splitting (shift by one), preaggregated offset used by subsequent block
for (int i = 0; i < blk.getNumRows(); i++) if (// ignore last row
!(lastBlk && i == (blk.getNumRows() - 1))) {
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
MatrixBlock tmpBlk = (MatrixBlock) out.getValue();
tmpBlk.reset(1, blk.getNumColumns());
blk.slice(i, i, 0, blk.getNumColumns() - 1, tmpBlk);
out.getIndexes().setIndexes(rixOffset + i + 2, inix.getColumnIndex());
}
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class OperationsOnMatrixValues method performSlice.
public static void performSlice(IndexedMatrixValue in, IndexRange ixrange, int brlen, int bclen, ArrayList<IndexedMatrixValue> outlist) {
long cellIndexTopRow = UtilFunctions.computeCellIndex(in.getIndexes().getRowIndex(), brlen, 0);
long cellIndexBottomRow = UtilFunctions.computeCellIndex(in.getIndexes().getRowIndex(), brlen, in.getValue().getNumRows() - 1);
long cellIndexLeftCol = UtilFunctions.computeCellIndex(in.getIndexes().getColumnIndex(), bclen, 0);
long cellIndexRightCol = UtilFunctions.computeCellIndex(in.getIndexes().getColumnIndex(), bclen, in.getValue().getNumColumns() - 1);
long cellIndexOverlapTop = Math.max(cellIndexTopRow, ixrange.rowStart);
long cellIndexOverlapBottom = Math.min(cellIndexBottomRow, ixrange.rowEnd);
long cellIndexOverlapLeft = Math.max(cellIndexLeftCol, ixrange.colStart);
long cellIndexOverlapRight = Math.min(cellIndexRightCol, ixrange.colEnd);
// check if block is outside the indexing range
if (cellIndexOverlapTop > cellIndexOverlapBottom || cellIndexOverlapLeft > cellIndexOverlapRight) {
return;
}
IndexRange tmpRange = new IndexRange(UtilFunctions.computeCellInBlock(cellIndexOverlapTop, brlen), UtilFunctions.computeCellInBlock(cellIndexOverlapBottom, brlen), UtilFunctions.computeCellInBlock(cellIndexOverlapLeft, bclen), UtilFunctions.computeCellInBlock(cellIndexOverlapRight, bclen));
int rowCut = UtilFunctions.computeCellInBlock(ixrange.rowStart, brlen);
int colCut = UtilFunctions.computeCellInBlock(ixrange.colStart, bclen);
int rowsInLastBlock = (int) ((ixrange.rowEnd - ixrange.rowStart + 1) % brlen);
if (rowsInLastBlock == 0)
rowsInLastBlock = brlen;
int colsInLastBlock = (int) ((ixrange.colEnd - ixrange.colStart + 1) % bclen);
if (colsInLastBlock == 0)
colsInLastBlock = bclen;
long resultBlockIndexTop = UtilFunctions.computeBlockIndex(cellIndexOverlapTop - ixrange.rowStart + 1, brlen);
long resultBlockIndexBottom = UtilFunctions.computeBlockIndex(cellIndexOverlapBottom - ixrange.rowStart + 1, brlen);
long resultBlockIndexLeft = UtilFunctions.computeBlockIndex(cellIndexOverlapLeft - ixrange.colStart + 1, bclen);
long resultBlockIndexRight = UtilFunctions.computeBlockIndex(cellIndexOverlapRight - ixrange.colStart + 1, bclen);
int boundaryRlen = brlen;
int boundaryClen = bclen;
long finalBlockIndexBottom = UtilFunctions.computeBlockIndex(ixrange.rowEnd - ixrange.rowStart + 1, brlen);
long finalBlockIndexRight = UtilFunctions.computeBlockIndex(ixrange.colEnd - ixrange.colStart + 1, bclen);
if (resultBlockIndexBottom == finalBlockIndexBottom)
boundaryRlen = rowsInLastBlock;
if (resultBlockIndexRight == finalBlockIndexRight)
boundaryClen = colsInLastBlock;
// allocate space for the output value
for (long r = resultBlockIndexTop; r <= resultBlockIndexBottom; r++) for (long c = resultBlockIndexLeft; c <= resultBlockIndexRight; c++) {
IndexedMatrixValue out = new IndexedMatrixValue(new MatrixIndexes(), new MatrixBlock());
out.getIndexes().setIndexes(r, c);
outlist.add(out);
}
// execute actual slice operation
in.getValue().slice(outlist, tmpRange, rowCut, colCut, brlen, bclen, boundaryRlen, boundaryClen);
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class OperationsOnMatrixValues method performMapGroupedAggregate.
public static void performMapGroupedAggregate(Operator op, IndexedMatrixValue inTarget, MatrixBlock groups, int ngroups, int brlen, int bclen, ArrayList<IndexedMatrixValue> outlist) {
MatrixIndexes ix = inTarget.getIndexes();
MatrixBlock target = (MatrixBlock) inTarget.getValue();
// execute grouped aggregate operations
MatrixBlock out = groups.groupedAggOperations(target, null, new MatrixBlock(), ngroups, op);
if (out.getNumRows() <= brlen && out.getNumColumns() <= bclen) {
// single output block
outlist.add(new IndexedMatrixValue(new MatrixIndexes(1, ix.getColumnIndex()), out));
} else {
// multiple output blocks (by op def, single column block )
for (int blockRow = 0; blockRow < (int) Math.ceil(out.getNumRows() / (double) brlen); blockRow++) {
int maxRow = (blockRow * brlen + brlen < out.getNumRows()) ? brlen : out.getNumRows() - blockRow * brlen;
int row_offset = blockRow * brlen;
// copy submatrix to block
MatrixBlock tmp = out.slice(row_offset, row_offset + maxRow - 1, 0, out.getNumColumns() - 1, new MatrixBlock());
// append block to result cache
outlist.add(new IndexedMatrixValue(new MatrixIndexes(blockRow + 1, ix.getColumnIndex()), tmp));
}
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class OperationsOnMatrixValues method performSlice.
@SuppressWarnings("rawtypes")
public static ArrayList performSlice(IndexRange ixrange, int brlen, int bclen, int iix, int jix, MatrixBlock in) {
IndexedMatrixValue imv = new IndexedMatrixValue(new MatrixIndexes(iix, jix), (MatrixBlock) in);
ArrayList<IndexedMatrixValue> outlist = new ArrayList<>();
performSlice(imv, ixrange, brlen, bclen, outlist);
return SparkUtils.fromIndexedMatrixBlockToPair(outlist);
}
Aggregations