use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class PlusMultCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
String output_name = output.getName();
//get all the inputs
MatrixBlock matrix1 = ec.getMatrixInput(input1.getName());
MatrixBlock matrix2 = ec.getMatrixInput(input2.getName());
ScalarObject scalar = ec.getScalarInput(input3.getName(), input3.getValueType(), input3.isLiteral());
//execution
((ValueFunctionWithConstant) ((BinaryOperator) _optr).fn).setConstant(scalar.getDoubleValue());
MatrixBlock out = (MatrixBlock) matrix1.binaryOperations((BinaryOperator) _optr, matrix2, new MatrixBlock());
//release the matrices
ec.releaseMatrixInput(input1.getName());
ec.releaseMatrixInput(input2.getName());
ec.setMatrixOutput(output_name, out);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class PlusMultCPInstruction method parseInstruction.
public static PlusMultCPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
CPOperand operand1 = new CPOperand(parts[1]);
//put the second matrix (parts[3]) in Operand2 to make using Binary matrix operations easier
CPOperand operand2 = new CPOperand(parts[3]);
CPOperand operand3 = new CPOperand(parts[2]);
CPOperand outOperand = new CPOperand(parts[4]);
BinaryOperator bOperator = new BinaryOperator(opcode.equals("+*") ? PlusMultiply.getPlusMultiplyFnObject() : MinusMultiply.getMinusMultiplyFnObject());
return new PlusMultCPInstruction(bOperator, operand1, operand2, operand3, outOperand, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class MatrixMatrixRelationalCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
MatrixBlock inBlock1 = ec.getMatrixInput(input1.getName());
MatrixBlock inBlock2 = ec.getMatrixInput(input2.getName());
String output_name = output.getName();
BinaryOperator bop = (BinaryOperator) _optr;
MatrixBlock retBlock = (MatrixBlock) inBlock1.binaryOperations(bop, inBlock2, new MatrixBlock());
ec.releaseMatrixInput(input1.getName());
ec.releaseMatrixInput(input2.getName());
// Ensure right dense/sparse output representation (guarded by released input memory)
if (checkGuardedRepresentationChange(inBlock1, inBlock2, retBlock)) {
retBlock.examSparsity();
}
ec.setMatrixOutput(output_name, retBlock);
}
use of org.apache.sysml.runtime.matrix.operators.BinaryOperator in project incubator-systemml by apache.
the class BuiltinBinarySPInstruction method parseInstruction.
public static BuiltinBinarySPInstruction parseInstruction(String str) throws DMLRuntimeException {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = null;
boolean isBroadcast = false;
VectorType vtype = null;
ValueFunction func = null;
if (//map builtin function
str.startsWith("SPARK" + Lop.OPERAND_DELIMITOR + "map")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
func = Builtin.getBuiltinFnObject(opcode.substring(3));
vtype = VectorType.valueOf(parts[5]);
isBroadcast = true;
} else //default builtin function
{
opcode = parseBinaryInstruction(str, in1, in2, out);
func = Builtin.getBuiltinFnObject(opcode);
}
//sanity check value function
if (func == null)
throw new DMLRuntimeException("Failed to create builtin value function for opcode: " + opcode);
// Determine appropriate Function Object based on opcode
if (//MATRIX-SCALAR
in1.getDataType() != in2.getDataType()) {
return new MatrixScalarBuiltinSPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str);
} else //MATRIX-MATRIX
{
if (isBroadcast)
return new MatrixBVectorBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, vtype, opcode, str);
else
return new MatrixMatrixBuiltinSPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str);
}
}
Aggregations