use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-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 incubator-systemml by apache.
the class GroupedAggregateMInstruction 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(input1);
if (blkList == null)
return;
for (IndexedMatrixValue in1 : blkList) {
if (in1 == null)
continue;
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
// get all inputs
MatrixIndexes ix = in1.getIndexes();
MatrixBlock groups = (MatrixBlock) dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue();
// output blocked result
int brlen = dcInput.getNumRowsPerBlock();
int bclen = dcInput.getNumColsPerBlock();
// execute map grouped aggregate operations
ArrayList<IndexedMatrixValue> outlist = new ArrayList<>();
OperationsOnMatrixValues.performMapGroupedAggregate(getOperator(), in1, groups, _ngroups, brlen, bclen, outlist);
// output all result blocks
for (IndexedMatrixValue out : outlist) {
cachedValues.add(output, out);
}
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-systemml by apache.
the class PMMJMRInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
// get both matrix inputs (left side always permutation)
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input1);
IndexedMatrixValue in2 = cachedValues.getFirst(input2);
IndexedMatrixValue in1 = dcInput.getDataBlock((int) in2.getIndexes().getRowIndex(), 1);
MatrixBlock mb1 = (MatrixBlock) in1.getValue();
MatrixBlock mb2 = (MatrixBlock) in2.getValue();
// compute target block indexes
long minPos = UtilFunctions.toLong(mb1.minNonZero());
long maxPos = UtilFunctions.toLong(mb1.max());
long rowIX1 = (minPos - 1) / blockRowFactor + 1;
long rowIX2 = (maxPos - 1) / blockRowFactor + 1;
boolean multipleOuts = (rowIX1 != rowIX2);
if (// at least one row selected
minPos >= 1) {
// output sparsity estimate
double spmb1 = OptimizerUtils.getSparsity(mb1.getNumRows(), 1, mb1.getNonZeros());
long estnnz = (long) (spmb1 * mb2.getNonZeros());
boolean sparse = MatrixBlock.evalSparseFormatInMemory(blockRowFactor, mb2.getNumColumns(), estnnz);
// compute and allocate output blocks
IndexedMatrixValue out1 = cachedValues.holdPlace(output, valueClass);
IndexedMatrixValue out2 = multipleOuts ? cachedValues.holdPlace(output, valueClass) : null;
out1.getValue().reset(blockRowFactor, mb2.getNumColumns(), sparse);
if (out2 != null)
out2.getValue().reset(UtilFunctions.computeBlockSize(_rlen, rowIX2, blockRowFactor), mb2.getNumColumns(), sparse);
// compute core matrix permutation (assumes that out1 has default blocksize,
// hence we do a meta data correction afterwards)
mb1.permutationMatrixMultOperations(mb2, out1.getValue(), (out2 != null) ? out2.getValue() : null);
((MatrixBlock) out1.getValue()).setNumRows(UtilFunctions.computeBlockSize(_rlen, rowIX1, blockRowFactor));
out1.getIndexes().setIndexes(rowIX1, in2.getIndexes().getColumnIndex());
if (out2 != null)
out2.getIndexes().setIndexes(rowIX2, in2.getIndexes().getColumnIndex());
// empty block output filter (enabled by compiler consumer operation is in CP)
if (!_outputEmptyBlocks && out1.getValue().isEmpty() && (out2 == null || out2.getValue().isEmpty())) {
cachedValues.remove(output);
}
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-systemml by apache.
the class ParameterizedBuiltinMRInstruction 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)
for (IndexedMatrixValue imv : blkList) {
if (imv == null)
continue;
if (_opcode.equalsIgnoreCase("replace")) {
MatrixValue in = imv.getValue();
MatrixIndexes inIX = imv.getIndexes();
// allocate space for the output value
IndexedMatrixValue iout = null;
if (output == input)
iout = tempValue;
else
iout = cachedValues.holdPlace(output, valueClass);
iout.getIndexes().setIndexes(inIX);
MatrixValue out = iout.getValue();
// process instruction
in.replaceOperations(out, _pattern, _replace);
// put the output value in the cache
if (iout == tempValue)
cachedValues.add(output, iout);
} else if (_opcode.equalsIgnoreCase("rexpand")) {
// process instruction
ArrayList<IndexedMatrixValue> out = new ArrayList<>();
LibMatrixReorg.rexpand(imv, _max, _dirRows, _cast, _ignore, blockRowFactor, blockColFactor, out);
// put the output values in the cache
for (IndexedMatrixValue lout : out) cachedValues.add(output, lout);
}
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-systemml by apache.
the class RemoveEmptyMRInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
// get input and offsets
IndexedMatrixValue inData = cachedValues.getFirst(input1);
IndexedMatrixValue inOffset = cachedValues.getFirst(input2);
MatrixIndexes ix = inData.getIndexes();
MatrixValue mb = inData.getValue();
if (_len > 0) {
// execute remove empty operations
ArrayList<IndexedMatrixValue> out = new ArrayList<>();
LibMatrixReorg.rmempty(inData, inOffset, _rmRows, _len, blockRowFactor, blockColFactor, out);
// put results into cache map
for (IndexedMatrixValue imv : out) cachedValues.add(output, imv);
} else {
int n = _emptyRet ? 1 : 0;
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(_rmRows ? 1 : ix.getRowIndex(), _rmRows ? ix.getColumnIndex() : 1), new MatrixBlock(_rmRows ? n : mb.getNumRows(), _rmRows ? mb.getNumColumns() : n, false)));
}
}
Aggregations