use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class ParameterizedBuiltinCPInstruction method parseInstruction.
public static ParameterizedBuiltinCPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
// first part is always the opcode
String opcode = parts[0];
// last part is always the output
CPOperand out = new CPOperand(parts[parts.length - 1]);
// process remaining parts and build a hash map
HashMap<String, String> paramsMap = constructParameterMap(parts);
// determine the appropriate value function
ValueFunction func = null;
if (opcode.equalsIgnoreCase("cdf")) {
if (paramsMap.get("dist") == null)
throw new DMLRuntimeException("Invalid distribution: " + str);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
// Determine appropriate Function Object based on opcode
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("invcdf")) {
if (paramsMap.get("dist") == null)
throw new DMLRuntimeException("Invalid distribution: " + str);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode, paramsMap.get("dist"));
// Determine appropriate Function Object based on opcode
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("groupedagg")) {
// check for mandatory arguments
String fnStr = paramsMap.get("fn");
if (fnStr == null)
throw new DMLRuntimeException("Function parameter is missing in groupedAggregate.");
if (fnStr.equalsIgnoreCase("centralmoment")) {
if (paramsMap.get("order") == null)
throw new DMLRuntimeException("Mandatory \"order\" must be specified when fn=\"centralmoment\" in groupedAggregate.");
}
Operator op = GroupedAggregateInstruction.parseGroupedAggOperator(fnStr, paramsMap.get("order"));
return new ParameterizedBuiltinCPInstruction(op, paramsMap, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rmempty") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("rexpand")) {
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinCPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str);
} else if (opcode.equals("transform") || opcode.equals("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformmeta")) {
return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
} else if (opcode.equals("toString")) {
return new ParameterizedBuiltinCPInstruction(null, paramsMap, out, opcode, str);
} else {
throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
}
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class BuiltinUnaryCPInstruction method parseInstruction.
public static BuiltinUnaryCPInstruction parseInstruction(String str) throws DMLRuntimeException {
CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = null;
ValueFunction func = null;
//print or stop or cumulative aggregates
if (parts.length == 4) {
opcode = parts[0];
in.split(parts[1]);
out.split(parts[2]);
func = Builtin.getBuiltinFnObject(opcode);
if (Arrays.asList(new String[] { "ucumk+", "ucum*", "ucummin", "ucummax" }).contains(opcode))
return new MatrixBuiltinCPInstruction(new UnaryOperator(func, Integer.parseInt(parts[3])), in, out, opcode, str);
else
return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
} else //2+1, general case
{
opcode = parseUnaryInstruction(str, in, out);
func = Builtin.getBuiltinFnObject(opcode);
if (in.getDataType() == DataType.SCALAR)
return new ScalarBuiltinCPInstruction(new SimpleOperator(func), in, out, opcode, str);
else if (in.getDataType() == DataType.MATRIX)
return new MatrixBuiltinCPInstruction(new UnaryOperator(func), in, out, opcode, str);
}
return null;
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class BuiltinBinaryCPInstruction method parseInstruction.
public static BuiltinBinaryCPInstruction 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 = parseBinaryInstruction(str, in1, in2, out);
checkOutputDataType(in1, in2, out);
// Determine appropriate Function Object based on opcode
ValueFunction func = Builtin.getBuiltinFnObject(opcode);
if (in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR)
return new ScalarScalarBuiltinCPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str);
else if (in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX)
return new MatrixMatrixBuiltinCPInstruction(new BinaryOperator(func), in1, in2, out, opcode, str);
else
return new MatrixScalarBuiltinCPInstruction(new RightScalarOperator(func, 0), in1, in2, out, opcode, str);
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class BuiltinMultipleCPInstruction method parseInstruction.
public static BuiltinMultipleCPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
String outputString = parts[parts.length - 1];
CPOperand outputOperand = new CPOperand(outputString);
String[] inputStrings = null;
CPOperand[] inputOperands = null;
if (parts.length > 2) {
inputStrings = Arrays.copyOfRange(parts, 1, parts.length - 1);
inputOperands = new CPOperand[parts.length - 2];
for (int i = 0; i < inputStrings.length; i++) {
inputOperands[i] = new CPOperand(inputStrings[i]);
}
}
if (MultipleCP.OperationType.PRINTF.toString().equalsIgnoreCase(opcode)) {
ValueFunction func = Builtin.getBuiltinFnObject(opcode);
return new ScalarBuiltinMultipleCPInstruction(new SimpleOperator(func), opcode, str, outputOperand, inputOperands);
}
throw new DMLRuntimeException("Opcode (" + opcode + ") not recognized in BuiltinMultipleCPInstruction");
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction 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