use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class AggregateBinaryInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
IndexedMatrixValue in1 = cachedValues.getFirst(input1);
IndexedMatrixValue in2 = cachedValues.getFirst(input2);
if (_opcode.equals(MapMult.OPCODE)) {
// check empty inputs (data for different instructions)
if (_cacheType.isRight() ? in1 == null : in2 == null)
return;
// one of the input is from distributed cache.
processMapMultInstruction(valueClass, cachedValues, in1, in2, blockRowFactor, blockColFactor);
} else // generic matrix mult
{
// check empty inputs (data for different instructions)
if (in1 == null || in2 == null)
return;
// allocate space for the output value
IndexedMatrixValue out;
if (output == input1 || output == input2)
out = tempValue;
else
out = cachedValues.holdPlace(output, valueClass);
// process instruction
OperationsOnMatrixValues.performAggregateBinary(in1.getIndexes(), (MatrixBlock) in1.getValue(), in2.getIndexes(), (MatrixBlock) in2.getValue(), out.getIndexes(), (MatrixBlock) out.getValue(), ((AggregateBinaryOperator) optr));
// put the output value in the cache
if (out == tempValue)
cachedValues.add(output, out);
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project 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) {
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 w/ awareness of zero rows or columns
int blen = _cbind ? blockColFactor : blockRowFactor;
long lastBlockColIndex = Math.max((long) Math.ceil((double) _offset / blen), 1);
// 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<>(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.getColumnIndex()).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.mapred.IndexedMatrixValue in project systemml by apache.
the class AppendRInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int brlen, int bclen) {
// get both inputs
IndexedMatrixValue left = cachedValues.getFirst(input1);
IndexedMatrixValue right = cachedValues.getFirst(input2);
// check non-existing block
if (left == null || right == null)
throw new DMLRuntimeException("Missing append input: isNull(left): " + (left == null) + ", isNull(right): " + (right == null));
// core append operation
MatrixBlock mbLeft = (MatrixBlock) left.getValue();
MatrixBlock mbRight = (MatrixBlock) right.getValue();
MatrixBlock ret = mbLeft.append(mbRight, new MatrixBlock(), _cbind);
// put result into cache
cachedValues.add(output, new IndexedMatrixValue(left.getIndexes(), ret));
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class BinaryInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
IndexedMatrixValue in1 = cachedValues.getFirst(input1);
IndexedMatrixValue in2 = cachedValues.getFirst(input2);
if (in1 == null && in2 == null)
return;
// allocate space for the output value
// try to avoid coping as much as possible
IndexedMatrixValue out;
if ((output != input1 && output != input2) || (output == input1 && in1 == null) || (output == input2 && in2 == null))
out = cachedValues.holdPlace(output, valueClass);
else
out = tempValue;
// if one of the inputs is null, then it is a all zero block
MatrixIndexes finalIndexes = null;
if (in1 == null) {
in1 = zeroInput;
in1.getValue().reset(in2.getValue().getNumRows(), in2.getValue().getNumColumns());
finalIndexes = in2.getIndexes();
} else
finalIndexes = in1.getIndexes();
if (in2 == null) {
in2 = zeroInput;
in2.getValue().reset(in1.getValue().getNumRows(), in1.getValue().getNumColumns());
}
// process instruction
out.getIndexes().setIndexes(finalIndexes);
OperationsOnMatrixValues.performBinaryIgnoreIndexes(in1.getValue(), in2.getValue(), out.getValue(), ((BinaryOperator) optr));
// put the output value in the cache
if (out == tempValue)
cachedValues.add(output, out);
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project systemml by apache.
the class CtableInstruction method processInstruction.
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue zeroInput, HashMap<Byte, CTableMap> resultMaps, HashMap<Byte, MatrixBlock> resultBlocks, int blockRowFactor, int blockColFactor) {
IndexedMatrixValue in1, in2, in3 = null;
in1 = cachedValues.getFirst(input1);
CTableMap ctableResult = null;
MatrixBlock ctableResultBlock = null;
if (knownOutputDims()) {
if (resultBlocks != null) {
ctableResultBlock = resultBlocks.get(output);
if (ctableResultBlock == null) {
// From MR, output of ctable is set to be sparse since it is built from a single input block.
ctableResultBlock = new MatrixBlock((int) _outputDim1, (int) _outputDim2, true);
resultBlocks.put(output, ctableResultBlock);
}
} else {
throw new DMLRuntimeException("Unexpected error in processing table instruction.");
}
} else {
// prepare aggregation maps
ctableResult = resultMaps.get(output);
if (ctableResult == null) {
ctableResult = new CTableMap();
resultMaps.put(output, ctableResult);
}
}
// get inputs and process instruction
switch(_op) {
case CTABLE_TRANSFORM:
{
in2 = cachedValues.getFirst(input2);
in3 = cachedValues.getFirst(input3);
if (in1 == null || in2 == null || in3 == null)
return;
OperationsOnMatrixValues.performCtable(in1.getIndexes(), in1.getValue(), in2.getIndexes(), in2.getValue(), in3.getIndexes(), in3.getValue(), ctableResult, ctableResultBlock, optr);
break;
}
case CTABLE_TRANSFORM_SCALAR_WEIGHT:
{
// 3rd input is a scalar
in2 = cachedValues.getFirst(input2);
if (in1 == null || in2 == null)
return;
OperationsOnMatrixValues.performCtable(in1.getIndexes(), in1.getValue(), in2.getIndexes(), in2.getValue(), scalar_input3, ctableResult, ctableResultBlock, optr);
break;
}
case CTABLE_EXPAND_SCALAR_WEIGHT:
{
// 2nd and 3rd input is a scalar
if (in1 == null)
return;
OperationsOnMatrixValues.performCtable(in1.getIndexes(), in1.getValue(), scalar_input2, (scalar_input3 == 1), blockRowFactor, ctableResult, ctableResultBlock, optr);
break;
}
case CTABLE_TRANSFORM_HISTOGRAM:
{
// 2nd and 3rd inputs are scalars
if (in1 == null)
return;
OperationsOnMatrixValues.performCtable(in1.getIndexes(), in1.getValue(), scalar_input2, scalar_input3, ctableResult, ctableResultBlock, optr);
break;
}
case CTABLE_TRANSFORM_WEIGHTED_HISTOGRAM:
{
// 2nd and 3rd inputs are scalars
in3 = cachedValues.getFirst(input3);
if (in1 == null || in3 == null)
return;
OperationsOnMatrixValues.performCtable(in1.getIndexes(), in1.getValue(), scalar_input2, in3.getIndexes(), in3.getValue(), ctableResult, ctableResultBlock, optr);
break;
}
default:
throw new DMLRuntimeException("Unrecognized opcode in Tertiary Instruction: " + instString);
}
}
Aggregations