use of org.apache.sysml.runtime.matrix.operators.BinaryOperator 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.operators.BinaryOperator in project incubator-systemml by apache.
the class BinaryMInstruction method parseInstruction.
public static BinaryMInstruction parseInstruction(String str) {
InstructionUtils.checkNumFields(str, 5);
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]);
CacheType ctype = CacheType.valueOf(parts[4]);
VectorType vtype = VectorType.valueOf(parts[5]);
BinaryOperator bop = InstructionUtils.parseExtendedBinaryOperator(opcode);
return new BinaryMInstruction(bop, in1, in2, ctype, vtype, out, str);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class UaggOuterChainInstruction method parseInstruction.
public static UaggOuterChainInstruction parseInstruction(String str) {
// check number of fields (2/3 inputs, output, type)
InstructionUtils.checkNumFields(str, 5);
// parse instruction parts (without exec type)
String[] parts = InstructionUtils.getInstructionParts(str);
AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
byte in1 = Byte.parseByte(parts[3]);
byte in2 = Byte.parseByte(parts[4]);
byte out = Byte.parseByte(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 UaggOuterChainInstruction(bop, uaggop, aop, in1, in2, out, str);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BinarySPInstruction method processMatrixBVectorBinaryInstruction.
protected void processMatrixBVectorBinaryInstruction(ExecutionContext ec, VectorType vtype) {
SparkExecutionContext sec = (SparkExecutionContext) ec;
// sanity check dimensions
checkMatrixMatrixBinaryCharacteristics(sec);
// get input RDDs
String rddVar = input1.getName();
String bcastVar = input2.getName();
JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(rddVar);
PartitionedBroadcast<MatrixBlock> in2 = sec.getBroadcastForVariable(bcastVar);
MatrixCharacteristics mc1 = sec.getMatrixCharacteristics(rddVar);
MatrixCharacteristics mc2 = sec.getMatrixCharacteristics(bcastVar);
BinaryOperator bop = (BinaryOperator) _optr;
boolean isOuter = (mc1.getRows() > 1 && mc1.getCols() == 1 && mc2.getRows() == 1 && mc2.getCols() > 1);
// execute map binary operation
JavaPairRDD<MatrixIndexes, MatrixBlock> out = null;
if (isOuter) {
out = in1.flatMapToPair(new OuterVectorBinaryOpFunction(bop, in2));
} else {
// default
// note: we use mappartition in order to preserve partitioning information for
// binary mv operations where the keys are guaranteed not to change, the reason
// why we cannot use mapValues is the need for broadcast key lookups.
// alternative: out = in1.mapToPair(new MatrixVectorBinaryOpFunction(bop, in2, vtype));
out = in1.mapPartitionsToPair(new MatrixVectorBinaryOpPartitionFunction(bop, in2, vtype), true);
}
// set output RDD
updateBinaryOutputMatrixCharacteristics(sec);
sec.setRDDHandleForVariable(output.getName(), out);
sec.addLineageRDD(output.getName(), rddVar);
sec.addLineageBroadcast(output.getName(), bcastVar);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BinaryMatrixMatrixCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
String opcode = getOpcode();
if (LibCommonsMath.isSupportedMatrixMatrixOperation(opcode)) {
MatrixBlock solution = LibCommonsMath.matrixMatrixOperations(ec.getMatrixObject(input1.getName()), (MatrixObject) ec.getVariable(input2.getName()), opcode);
ec.setMatrixOutput(output.getName(), solution, getExtendedOpcode());
return;
}
// Read input matrices
MatrixBlock inBlock1 = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
MatrixBlock inBlock2 = ec.getMatrixInput(input2.getName(), getExtendedOpcode());
// Perform computation using input matrices, and produce the result matrix
BinaryOperator bop = (BinaryOperator) _optr;
MatrixBlock retBlock = (MatrixBlock) (inBlock1.binaryOperations(bop, inBlock2, new MatrixBlock()));
// Release the memory occupied by input matrices
ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
ec.releaseMatrixInput(input2.getName(), getExtendedOpcode());
// Ensure right dense/sparse output representation (guarded by released input memory)
if (checkGuardedRepresentationChange(inBlock1, inBlock2, retBlock)) {
retBlock.examSparsity();
}
// Attach result matrix with MatrixObject associated with output_name
ec.setMatrixOutput(output.getName(), retBlock, getExtendedOpcode());
}
Aggregations