Search in sources :

Example 6 with BinaryOperator

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

the class BinUaggChainSPInstruction method parseInstruction.

public static BinUaggChainSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    //parse instruction parts (without exec type)
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    InstructionUtils.checkNumFields(parts, 4);
    String opcode = parts[0];
    BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[1]);
    AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[2]);
    CPOperand in = new CPOperand(parts[3]);
    CPOperand out = new CPOperand(parts[4]);
    return new BinUaggChainSPInstruction(in, out, bop, uaggop, opcode, str);
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 7 with BinaryOperator

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

the class ScalarScalarBuiltinCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    ScalarObject so1 = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
    ScalarObject so2 = ec.getScalarInput(input2.getName(), input2.getValueType(), input2.isLiteral());
    BinaryOperator dop = (BinaryOperator) _optr;
    ScalarObject sores = null;
    //compute output value, incl implicit type promotion if necessary
    if (so1 instanceof StringObject || so2 instanceof StringObject)
        throw new DMLRuntimeException("Binary builtin '" + getOpcode() + "' not supported over string inputs.");
    else if (so1 instanceof DoubleObject || so2 instanceof DoubleObject || output.getValueType() == ValueType.DOUBLE)
        sores = new DoubleObject(dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue()));
    else if (so1 instanceof IntObject || so2 instanceof IntObject)
        sores = new IntObject((long) dop.fn.execute(so1.getLongValue(), so2.getLongValue()));
    else
        //all boolean
        throw new DMLRuntimeException("Binary builtin '" + getOpcode() + "' not supported over boolean inputs.");
    ec.setScalarOutput(output.getName(), sores);
}
Also used : BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 8 with BinaryOperator

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

the class ScalarScalarRelationalCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    ScalarObject so1 = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
    ScalarObject so2 = ec.getScalarInput(input2.getName(), input2.getValueType(), input2.isLiteral());
    ValueComparisonFunction vcomp = ((ValueComparisonFunction) ((BinaryOperator) _optr).fn);
    boolean rval = false;
    //compute output value, incl implicit type promotion if necessary
    if (so1 instanceof StringObject || so2 instanceof StringObject)
        rval = vcomp.compare(so1.getStringValue(), so2.getStringValue());
    else if (so1 instanceof DoubleObject || so2 instanceof DoubleObject)
        rval = vcomp.compare(so1.getDoubleValue(), so2.getDoubleValue());
    else if (so1 instanceof IntObject || so2 instanceof IntObject)
        rval = vcomp.compare(so1.getLongValue(), so2.getLongValue());
    else
        //all boolean
        rval = vcomp.compare(so1.getBooleanValue(), so2.getBooleanValue());
    //set boolean output value
    ec.setScalarOutput(output.getName(), new BooleanObject(rval));
}
Also used : ValueComparisonFunction(org.apache.sysml.runtime.functionobjects.ValueComparisonFunction) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator)

Example 9 with BinaryOperator

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

the class UaggOuterChainCPInstruction method parseInstruction.

public static UaggOuterChainCPInstruction 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 UaggOuterChainCPInstruction(bop, uaggop, aop, in1, in2, out, opcode, str);
    } else {
        throw new DMLRuntimeException("UaggOuterChainCPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
}
Also used : AggregateUnaryOperator(org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) CorrectionLocationType(org.apache.sysml.lops.PartialAggregate.CorrectionLocationType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 10 with BinaryOperator

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

the class ScalarScalarArithmeticCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    ScalarObject so1 = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
    ScalarObject so2 = ec.getScalarInput(input2.getName(), input2.getValueType(), input2.isLiteral());
    BinaryOperator dop = (BinaryOperator) _optr;
    ScalarObject sores = null;
    //compute output value, incl implicit type promotion if necessary
    if (so1 instanceof StringObject || so2 instanceof StringObject) {
        if (//not string concatenation
        !getOpcode().equals("+"))
            throw new DMLRuntimeException("Arithmetic '" + getOpcode() + "' not supported over string inputs.");
        sores = new StringObject(dop.fn.execute(so1.getLanguageSpecificStringValue(), so2.getLanguageSpecificStringValue()));
    } else if (so1 instanceof DoubleObject || so2 instanceof DoubleObject || output.getValueType() == ValueType.DOUBLE) {
        sores = new DoubleObject(dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue()));
    } else if (so1 instanceof IntObject || so2 instanceof IntObject) {
        double tmp = dop.fn.execute(so1.getLongValue(), so2.getLongValue());
        if (//cast to long if no overflow, otherwise controlled exception
        tmp > Long.MAX_VALUE)
            throw new DMLRuntimeException("Integer operation created numerical result overflow (" + tmp + " > " + Long.MAX_VALUE + ").");
        sores = new IntObject((long) tmp);
    } else {
        //all boolean
        //NOTE: boolean-boolean arithmetic treated as double for consistency with R
        sores = new DoubleObject(dop.fn.execute(so1.getDoubleValue(), so2.getDoubleValue()));
    }
    ec.setScalarOutput(output.getName(), sores);
}
Also used : BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)30 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)8 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)8 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 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 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)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 Pointer (jcuda.Pointer)1 CacheType (org.apache.sysml.lops.AppendM.CacheType)1 ValueType (org.apache.sysml.parser.Expression.ValueType)1