use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class UaggOuterChainSPInstruction method parseInstruction.
public static UaggOuterChainSPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (opcode.equalsIgnoreCase(UAggOuterChain.OPCODE)) {
AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
CPOperand in1 = new CPOperand(parts[3]);
CPOperand in2 = new CPOperand(parts[4]);
CPOperand out = new CPOperand(parts[5]);
//derive aggregation operator from unary operator
String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(parts[1]);
CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(parts[1]);
String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
return new UaggOuterChainSPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
} else {
throw new DMLRuntimeException("UaggOuterChainSPInstruction.parseInstruction():: Unknown opcode " + opcode);
}
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BinaryInstruction method parseInstruction.
public static BinaryInstruction parseInstruction(String str) throws DMLRuntimeException {
InstructionUtils.checkNumFields(str, 3);
String[] parts = InstructionUtils.getInstructionParts(str);
byte in1, in2, out;
String opcode = parts[0];
in1 = Byte.parseByte(parts[1]);
in2 = Byte.parseByte(parts[2]);
out = Byte.parseByte(parts[3]);
BinaryOperator bop = InstructionUtils.parseBinaryOperator(opcode);
if (bop != null)
return new BinaryInstruction(bop, in1, in2, out, str);
else
return null;
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BinaryMInstruction 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;
for (IndexedMatrixValue in1 : blkList) {
//allocate space for the output value
//try to avoid coping as much as possible
IndexedMatrixValue out;
if ((output != input1 && output != input2))
out = cachedValues.holdPlace(output, valueClass);
else
out = tempValue;
//get second
DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
IndexedMatrixValue in2 = null;
if (_vectorType == VectorType.COL_VECTOR)
in2 = dcInput.getDataBlock((int) in1.getIndexes().getRowIndex(), 1);
else
//_vectorType == VectorType.ROW_VECTOR
in2 = dcInput.getDataBlock(1, (int) in1.getIndexes().getColumnIndex());
//process instruction
out.getIndexes().setIndexes(in1.getIndexes());
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.operators.BinaryOperator in project incubator-systemml by apache.
the class BinUaggChainInstruction method parseInstruction.
public static BinUaggChainInstruction parseInstruction(String str) throws DMLRuntimeException {
//check number of fields (2/3 inputs, output, type)
InstructionUtils.checkNumFields(str, 4);
//parse instruction parts (without exec type)
String[] parts = InstructionUtils.getInstructionParts(str);
BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[1]);
AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[2]);
byte in1 = Byte.parseByte(parts[3]);
byte out = Byte.parseByte(parts[4]);
return new BinUaggChainInstruction(bop, uaggop, in1, out, str);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BinarySPInstruction method processMatrixMatrixBinaryInstruction.
/**
* Common binary matrix-matrix process instruction
*
* @param ec execution context
* @throws DMLRuntimeException if DMLRuntimeException occurs
*/
protected void processMatrixMatrixBinaryInstruction(ExecutionContext ec) throws DMLRuntimeException {
SparkExecutionContext sec = (SparkExecutionContext) ec;
//sanity check dimensions
checkMatrixMatrixBinaryCharacteristics(sec);
// Get input RDDs
String rddVar1 = input1.getName();
String rddVar2 = input2.getName();
JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(rddVar1);
JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(rddVar2);
MatrixCharacteristics mc1 = sec.getMatrixCharacteristics(rddVar1);
MatrixCharacteristics mc2 = sec.getMatrixCharacteristics(rddVar2);
BinaryOperator bop = (BinaryOperator) _optr;
//vector replication if required (mv or outer operations)
boolean rowvector = (mc2.getRows() == 1 && mc1.getRows() > 1);
long numRepLeft = getNumReplicas(mc1, mc2, true);
long numRepRight = getNumReplicas(mc1, mc2, false);
if (numRepLeft > 1)
in1 = in1.flatMapToPair(new ReplicateVectorFunction(false, numRepLeft));
if (numRepRight > 1)
in2 = in2.flatMapToPair(new ReplicateVectorFunction(rowvector, numRepRight));
//execute binary operation
JavaPairRDD<MatrixIndexes, MatrixBlock> out = in1.join(in2).mapValues(new MatrixMatrixBinaryOpFunction(bop));
//set output RDD
updateBinaryOutputMatrixCharacteristics(sec);
sec.setRDDHandleForVariable(output.getName(), out);
sec.addLineageRDD(output.getName(), rddVar1);
sec.addLineageRDD(output.getName(), rddVar2);
}
Aggregations