use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue 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) {
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).dropLastRowsOrColumns(_uaggOp.aggOp.correctionLocation);
OperationsOnMatrixValues.performBinaryIgnoreIndexes(inVal, _tmpVal, outVal, _bOp);
outIx.setIndexes(inIx);
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-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 incubator-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);
}
}
use of org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue in project incubator-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 incubator-systemml by apache.
the class CumulativeOffsetInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
// original data
IndexedMatrixValue in1 = cachedValues.getFirst(input1);
// offset row vector
IndexedMatrixValue in2 = cachedValues.getFirst(input2);
if (in1 == null || in2 == null)
throw new DMLRuntimeException("Unexpected empty input (left=" + ((in1 == null) ? "null" : in1.getIndexes()) + ", right=" + ((in2 == null) ? "null" : in2.getIndexes()) + ").");
// prepare inputs and outputs
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
MatrixBlock data = (MatrixBlock) in1.getValue();
MatrixBlock offset = (MatrixBlock) in2.getValue();
MatrixBlock blk = (MatrixBlock) out.getValue();
blk.reset(data.getNumRows(), data.getNumColumns());
// blockwise offset aggregation and prefix sum computation
// cp data
MatrixBlock data2 = new MatrixBlock(data);
// 1-based
MatrixBlock fdata2 = data2.slice(0, 0, 0, data2.getNumColumns() - 1, new MatrixBlock());
// sum offset to first row
fdata2.binaryOperationsInPlace(_bop, offset);
// 0-based
data2.copy(0, 0, 0, data2.getNumColumns() - 1, fdata2, true);
// compute columnwise prefix sums/prod/min/max
data2.unaryOperations(_uop, blk);
// set output indexes
out.getIndexes().setIndexes(in1.getIndexes());
}
Aggregations