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);
}
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);
}
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));
}
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);
}
}
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);
}
Aggregations