Search in sources :

Example 31 with BinaryOperator

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);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) ValueFunctionWithConstant(org.apache.sysml.runtime.functionobjects.ValueFunctionWithConstant) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 32 with BinaryOperator

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);
}
Also used : BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 33 with BinaryOperator

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);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 34 with BinaryOperator

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);
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) VectorType(org.apache.sysml.lops.BinaryM.VectorType) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)34 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)10 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)5 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)5 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)4 CorrectionLocationType (org.apache.sysml.lops.PartialAggregate.CorrectionLocationType)3 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)3 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)3 VectorType (org.apache.sysml.lops.BinaryM.VectorType)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)2 ValueComparisonFunction (org.apache.sysml.runtime.functionobjects.ValueComparisonFunction)2 ValueFunctionWithConstant (org.apache.sysml.runtime.functionobjects.ValueFunctionWithConstant)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)2 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)2 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)2 Method (java.lang.reflect.Method)1