use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class ParameterizedBuiltinCPInstruction method parseInstruction.
public static ParameterizedBuiltinCPInstruction parseInstruction(String str) {
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("transformapply") || opcode.equals("transformdecode") || opcode.equals("transformcolmap") || 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.DMLRuntimeException in project incubator-systemml by apache.
the class QuantilePickCPInstruction method parseInstruction.
public static QuantilePickCPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (!opcode.equalsIgnoreCase("qpick"))
throw new DMLRuntimeException("Unknown opcode while parsing a QuantilePickCPInstruction: " + str);
// instruction parsing
if (parts.length == 4) {
// instructions of length 4 originate from unary - mr-iqm
// TODO this should be refactored to use pickvaluecount lops
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
OperationTypes ptype = OperationTypes.IQM;
boolean inmem = false;
return new QuantilePickCPInstruction(null, in1, in2, out, ptype, inmem, opcode, str);
} else if (parts.length == 5) {
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
OperationTypes ptype = OperationTypes.valueOf(parts[3]);
boolean inmem = Boolean.parseBoolean(parts[4]);
return new QuantilePickCPInstruction(null, in1, out, ptype, inmem, opcode, str);
} else if (parts.length == 6) {
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
OperationTypes ptype = OperationTypes.valueOf(parts[4]);
boolean inmem = Boolean.parseBoolean(parts[5]);
return new QuantilePickCPInstruction(null, in1, in2, out, ptype, inmem, opcode, str);
}
return null;
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class QuantileSortCPInstruction method parseInstruction.
public static QuantileSortCPInstruction parseInstruction(String str) {
CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand in2 = null;
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (opcode.equalsIgnoreCase(SortKeys.OPCODE)) {
if (parts.length == 3) {
// Example: sort:mVar1:mVar2 (input=mVar1, output=mVar2)
parseUnaryInstruction(str, in1, out);
return new QuantileSortCPInstruction(new SimpleOperator(null), in1, out, opcode, str);
} else if (parts.length == 4) {
// Example: sort:mVar1:mVar2:mVar3 (input=mVar1, weights=mVar2, output=mVar3)
in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
parseUnaryInstruction(str, in1, in2, out);
return new QuantileSortCPInstruction(new SimpleOperator(null), in1, in2, out, opcode, str);
} else {
throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
}
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a QuantileSortCPInstruction: " + str);
}
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class ReorgCPInstruction method parseInstruction.
public static ReorgCPInstruction parseInstruction(String str) {
CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (opcode.equalsIgnoreCase("r'")) {
InstructionUtils.checkNumFields(str, 2, 3);
in.split(parts[1]);
out.split(parts[2]);
int k = Integer.parseInt(parts[3]);
return new ReorgCPInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject(), k), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rev")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgCPInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rdiag")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgCPInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rsort")) {
InstructionUtils.checkNumFields(parts, 5);
in.split(parts[1]);
out.split(parts[5]);
CPOperand col = new CPOperand(parts[2]);
CPOperand desc = new CPOperand(parts[3]);
CPOperand ixret = new CPOperand(parts[4]);
return new ReorgCPInstruction(new ReorgOperator(new SortIndex(1, false, false)), in, out, col, desc, ixret, opcode, str);
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
}
}
use of org.apache.sysml.runtime.DMLRuntimeException in project incubator-systemml by apache.
the class UaggOuterChainCPInstruction method parseInstruction.
public static UaggOuterChainCPInstruction parseInstruction(String str) {
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);
}
}
Aggregations