Search in sources :

Example 1 with TernaryOperator

use of org.apache.sysml.runtime.matrix.operators.TernaryOperator in project incubator-systemml by apache.

the class TernarySPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = !input1.isMatrix() ? null : sec.getBinaryBlockRDDHandleForVariable(input1.getName());
    JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = !input2.isMatrix() ? null : sec.getBinaryBlockRDDHandleForVariable(input2.getName());
    JavaPairRDD<MatrixIndexes, MatrixBlock> in3 = !input3.isMatrix() ? null : sec.getBinaryBlockRDDHandleForVariable(input3.getName());
    MatrixBlock m1 = input1.isMatrix() ? null : new MatrixBlock(ec.getScalarInput(input1).getDoubleValue());
    MatrixBlock m2 = input2.isMatrix() ? null : new MatrixBlock(ec.getScalarInput(input2).getDoubleValue());
    MatrixBlock m3 = input3.isMatrix() ? null : new MatrixBlock(ec.getScalarInput(input3).getDoubleValue());
    TernaryOperator op = (TernaryOperator) _optr;
    JavaPairRDD<MatrixIndexes, MatrixBlock> out = null;
    if (input1.isMatrix() && !input2.isMatrix() && !input3.isMatrix())
        out = in1.mapValues(new TernaryFunctionMSS(op, m1, m2, m3));
    else if (!input1.isMatrix() && input2.isMatrix() && !input3.isMatrix())
        out = in2.mapValues(new TernaryFunctionSMS(op, m1, m2, m3));
    else if (!input1.isMatrix() && !input2.isMatrix() && input3.isMatrix())
        out = in3.mapValues(new TernaryFunctionSSM(op, m1, m2, m3));
    else if (input1.isMatrix() && input2.isMatrix() && !input3.isMatrix())
        out = in1.join(in2).mapValues(new TernaryFunctionMMS(op, m1, m2, m3));
    else if (input1.isMatrix() && !input2.isMatrix() && input3.isMatrix())
        out = in1.join(in3).mapValues(new TernaryFunctionMSM(op, m1, m2, m3));
    else if (!input1.isMatrix() && input2.isMatrix() && input3.isMatrix())
        out = in2.join(in3).mapValues(new TernaryFunctionSMM(op, m1, m2, m3));
    else
        // all matrices
        out = in1.join(in2).join(in3).mapValues(new TernaryFunctionMMM(op, m1, m2, m3));
    // set output RDD
    updateTernaryOutputMatrixCharacteristics(sec);
    sec.setRDDHandleForVariable(output.getName(), out);
    if (input1.isMatrix())
        sec.addLineageRDD(output.getName(), input1.getName());
    if (input2.isMatrix())
        sec.addLineageRDD(output.getName(), input2.getName());
    if (input3.isMatrix())
        sec.addLineageRDD(output.getName(), input3.getName());
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)

Example 2 with TernaryOperator

use of org.apache.sysml.runtime.matrix.operators.TernaryOperator in project incubator-systemml by apache.

the class TernaryCPInstruction method parseInstruction.

public static TernaryCPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand operand1 = new CPOperand(parts[1]);
    CPOperand operand2 = new CPOperand(parts[2]);
    CPOperand operand3 = new CPOperand(parts[3]);
    CPOperand outOperand = new CPOperand(parts[4]);
    TernaryOperator op = InstructionUtils.parseTernaryOperator(opcode);
    return new TernaryCPInstruction(op, operand1, operand2, operand3, outOperand, opcode, str);
}
Also used : TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator)

Example 3 with TernaryOperator

use of org.apache.sysml.runtime.matrix.operators.TernaryOperator in project incubator-systemml by apache.

the class TernaryInstruction method parseInstruction.

public static TernaryInstruction parseInstruction(String str) {
    InstructionUtils.checkNumFields(str, 4);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand in1 = new CPOperand(parts[1]);
    CPOperand in2 = new CPOperand(parts[2]);
    CPOperand in3 = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    TernaryOperator op = InstructionUtils.parseTernaryOperator(opcode);
    return new TernaryInstruction(op, in1, in2, in3, out, str);
}
Also used : TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Example 4 with TernaryOperator

use of org.apache.sysml.runtime.matrix.operators.TernaryOperator in project incubator-systemml by apache.

the class TernaryInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    MatrixBlock lm1 = input1.isMatrix() ? (MatrixBlock) cachedValues.getFirst(ixinput1).getValue() : m1;
    MatrixBlock lm2 = input2.isMatrix() ? (MatrixBlock) cachedValues.getFirst(ixinput2).getValue() : m2;
    MatrixBlock lm3 = input3.isMatrix() ? (MatrixBlock) cachedValues.getFirst(ixinput3).getValue() : m3;
    MatrixIndexes ixin = input1.isMatrix() ? cachedValues.getFirst(ixinput1).getIndexes() : input2.isMatrix() ? cachedValues.getFirst(ixinput2).getIndexes() : cachedValues.getFirst(ixinput3).getIndexes();
    // prepare output
    IndexedMatrixValue out = new IndexedMatrixValue(new MatrixIndexes(), new MatrixBlock());
    out.getIndexes().setIndexes(ixin);
    // process instruction
    TernaryOperator op = (TernaryOperator) optr;
    lm1.ternaryOperations(op, lm2, lm3, (MatrixBlock) out.getValue());
    // put the output value in the cache
    cachedValues.add(ixoutput, out);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 5 with TernaryOperator

use of org.apache.sysml.runtime.matrix.operators.TernaryOperator in project incubator-systemml by apache.

the class TernarySPInstruction method parseInstruction.

public static TernarySPInstruction parseInstruction(String str) {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    CPOperand operand1 = new CPOperand(parts[1]);
    CPOperand operand2 = new CPOperand(parts[2]);
    CPOperand operand3 = new CPOperand(parts[3]);
    CPOperand outOperand = new CPOperand(parts[4]);
    TernaryOperator op = InstructionUtils.parseTernaryOperator(opcode);
    return new TernarySPInstruction(op, operand1, operand2, operand3, outOperand, opcode, str);
}
Also used : TernaryOperator(org.apache.sysml.runtime.matrix.operators.TernaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand)

Aggregations

TernaryOperator (org.apache.sysml.runtime.matrix.operators.TernaryOperator)5 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)2 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)2 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)1 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)1