use of org.apache.sysml.runtime.matrix.data.MatrixValue 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) throws DMLRuntimeException {
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<IndexedMatrixValue>();
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.data.MatrixValue in project incubator-systemml by apache.
the class MMCJMRReducerWithAggregator method reduce.
@Override
public void reduce(TaggedFirstSecondIndexes indexes, Iterator<MatrixValue> values, OutputCollector<Writable, Writable> out, Reporter report) throws IOException {
long start = System.currentTimeMillis();
commonSetup(report);
//perform aggregate (if necessary, only for binary cell)
MatrixValue aggregateValue = null;
if (valueClass == MatrixBlock.class) {
//multiple blocks for same indexes impossible
aggregateValue = values.next();
} else // MatrixCell.class
{
aggregateValue = performAggregateInstructions(indexes, values);
if (aggregateValue == null)
return;
}
int tag = indexes.getTag();
long firstIndex = indexes.getFirstIndex();
long secondIndex = indexes.getSecondIndex();
//for a different k
if (prevFirstIndex != firstIndex) {
cache.resetCache(true);
prevFirstIndex = firstIndex;
} else if (prevTag > tag)
throw new RuntimeException("tag is not ordered correctly: " + prevTag + " > " + tag);
prevTag = tag;
//perform cross-product binagg
processJoin(tag, secondIndex, aggregateValue);
report.incrCounter(Counters.COMBINE_OR_REDUCE_TIME, System.currentTimeMillis() - start);
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.
the class AppendMInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input1);
if (blkList == null)
return;
//right now this only deals with appending matrix with number of column <= blockColFactor
for (IndexedMatrixValue in1 : blkList) {
if (in1 == null)
continue;
//check for boundary block
int blen = _cbind ? blockColFactor : blockRowFactor;
long lastBlockColIndex = (long) Math.ceil((double) _offset / blen);
//case 1: pass through of non-boundary blocks
MatrixIndexes ix = in1.getIndexes();
if ((_cbind ? ix.getColumnIndex() : ix.getRowIndex()) != lastBlockColIndex) {
cachedValues.add(output, in1);
} else //case 2: pass through full input block and rhs block
if (_cbind && in1.getValue().getNumColumns() == blen || !_cbind && in1.getValue().getNumRows() == blen) {
//output lhs block
cachedValues.add(output, in1);
//output shallow copy of rhs block
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
if (_cbind) {
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1), dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue()));
} else {
cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex() + 1, ix.getColumnIndex()), dcInput.getDataBlock(1, (int) ix.getColumnIndex()).getValue()));
}
} else //case 3: append operation on boundary block
{
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
//allocate space for the output value
ArrayList<IndexedMatrixValue> outlist = new ArrayList<IndexedMatrixValue>(2);
IndexedMatrixValue first = cachedValues.holdPlace(output, valueClass);
first.getIndexes().setIndexes(ix);
outlist.add(first);
MatrixValue value_in2 = null;
if (_cbind) {
value_in2 = dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue();
if (in1.getValue().getNumColumns() + value_in2.getNumColumns() > blen) {
IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
second.getIndexes().setIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1);
outlist.add(second);
}
} else {
//rbind
value_in2 = dcInput.getDataBlock(1, (int) ix.getRowIndex()).getValue();
if (in1.getValue().getNumRows() + value_in2.getNumRows() > blen) {
IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
second.getIndexes().setIndexes(ix.getRowIndex() + 1, ix.getColumnIndex());
outlist.add(second);
}
}
OperationsOnMatrixValues.performAppend(in1.getValue(), value_in2, outlist, blockRowFactor, blockColFactor, _cbind, true, 0);
}
}
}
use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.
the class BinUaggChainInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException {
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
if (blkList == null)
return;
for (IndexedMatrixValue imv : blkList) {
if (imv == null)
continue;
MatrixIndexes inIx = imv.getIndexes();
MatrixValue inVal = imv.getValue();
//allocate space for the intermediate and output value
IndexedMatrixValue iout = cachedValues.holdPlace(output, valueClass);
MatrixIndexes outIx = iout.getIndexes();
MatrixValue outVal = iout.getValue();
//process instruction
OperationsOnMatrixValues.performAggregateUnary(inIx, inVal, _tmpIx, _tmpVal, _uaggOp, blockRowFactor, blockColFactor);
((MatrixBlock) _tmpVal).dropLastRowsOrColums(_uaggOp.aggOp.correctionLocation);
OperationsOnMatrixValues.performBinaryIgnoreIndexes(inVal, _tmpVal, outVal, _bOp);
outIx.setIndexes(inIx);
}
}
Aggregations