use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class UnaryMatrixSPInstruction method parseInstruction.
public static UnarySPInstruction parseInstruction(String str) {
CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = parseUnaryInstruction(str, in, out);
return new UnaryMatrixSPInstruction(InstructionUtils.parseUnaryOperator(opcode), in, out, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class ExternalFunctionInvocationInstruction method verifyAndAttachOutputs.
private void verifyAndAttachOutputs(ExecutionContext ec, PackageFunction fun, CPOperand[] outputs) {
for (int i = 0; i < outputs.length; i++) {
CPOperand output = outputs[i];
switch(fun.getFunctionOutput(i).getType()) {
case Matrix:
Matrix m = (Matrix) fun.getFunctionOutput(i);
MatrixObject newVar = createOutputMatrixObject(m);
ec.setVariable(output.getName(), newVar);
break;
case Scalar:
Scalar s = (Scalar) fun.getFunctionOutput(i);
ScalarObject scalarObject = null;
switch(s.getScalarType()) {
case Integer:
scalarObject = new IntObject(Long.parseLong(s.getValue()));
break;
case Double:
scalarObject = new DoubleObject(Double.parseDouble(s.getValue()));
break;
case Boolean:
scalarObject = new BooleanObject(Boolean.parseBoolean(s.getValue()));
break;
case Text:
scalarObject = new StringObject(s.getValue());
break;
default:
throw new DMLRuntimeException("Unknown scalar value type '" + s.getScalarType() + "' of output '" + output.getName() + "'.");
}
ec.setVariable(output.getName(), scalarObject);
break;
default:
throw new DMLRuntimeException("Unsupported data type: " + fun.getFunctionOutput(i).getType().name());
}
}
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class EvalFunction method execute.
@Override
public void execute(ExecutionContext ec) {
String fname = ((Scalar) getFunctionInput(0)).getValue();
MatrixObject in = ((Matrix) getFunctionInput(1)).getMatrixObject();
ArrayList<String> inputs = new ArrayList<>();
inputs.add("A");
ArrayList<String> outputs = new ArrayList<>();
outputs.add("B");
ExecutionContext ec2 = ExecutionContextFactory.createContext(ec.getProgram());
CPOperand inName = new CPOperand("TMP", org.apache.sysml.parser.Expression.ValueType.DOUBLE, DataType.MATRIX);
ec2.setVariable("TMP", in);
FunctionCallCPInstruction fcpi = new FunctionCallCPInstruction(null, fname, new CPOperand[] { inName }, inputs, outputs, "eval func");
fcpi.processInstruction(ec2);
MatrixObject out = (MatrixObject) ec2.getVariable("B");
_ret = new Matrix(out, ValueType.Double);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand in project incubator-systemml by apache.
the class PlusMultSPInstruction method parseInstruction.
public static PlusMultSPInstruction parseInstruction(String str) throws DMLRuntimeException {
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 PlusMultSPInstruction(bOperator, operand1, operand2, operand3, outOperand, opcode, str);
}
use of org.apache.sysml.runtime.instructions.cp.CPOperand 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