use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project incubator-systemml by apache.
the class ParameterizedBuiltinSPInstruction method parseInstruction.
public static ParameterizedBuiltinSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
// first part is always the opcode
String opcode = parts[0];
if (opcode.equalsIgnoreCase("mapgroupedagg")) {
CPOperand target = new CPOperand(parts[1]);
CPOperand groups = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
HashMap<String, String> paramsMap = new HashMap<>();
paramsMap.put(Statement.GAGG_TARGET, target.getName());
paramsMap.put(Statement.GAGG_GROUPS, groups.getName());
paramsMap.put(Statement.GAGG_NUM_GROUPS, parts[4]);
Operator op = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
} else {
// 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("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 ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
} else if (opcode.equalsIgnoreCase("rmempty")) {
boolean bRmEmptyBC = false;
if (parts.length > 6)
bRmEmptyBC = Boolean.parseBoolean(parts[5]);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, bRmEmptyBC);
} else if (opcode.equalsIgnoreCase("rexpand") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("transformapply") || opcode.equalsIgnoreCase("transformdecode")) {
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, false);
} else {
throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
}
}
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project incubator-systemml by apache.
the class IndexingCPInstruction method parseInstruction.
public static IndexingCPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (opcode.equalsIgnoreCase(RightIndex.OPCODE)) {
if (parts.length == 7) {
CPOperand in, rl, ru, cl, cu, out;
in = new CPOperand(parts[1]);
rl = new CPOperand(parts[2]);
ru = new CPOperand(parts[3]);
cl = new CPOperand(parts[4]);
cu = new CPOperand(parts[5]);
out = new CPOperand(parts[6]);
if (in.getDataType() == DataType.MATRIX)
return new MatrixIndexingCPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, opcode, str);
else if (in.getDataType() == DataType.FRAME)
return new FrameIndexingCPInstruction(new SimpleOperator(null), in, rl, ru, cl, cu, out, opcode, str);
else
throw new DMLRuntimeException("Can index only on Frames or Matrices");
} else {
throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
}
} else if (opcode.equalsIgnoreCase(LeftIndex.OPCODE)) {
if (parts.length == 8) {
CPOperand lhsInput, rhsInput, rl, ru, cl, cu, out;
lhsInput = new CPOperand(parts[1]);
rhsInput = new CPOperand(parts[2]);
rl = new CPOperand(parts[3]);
ru = new CPOperand(parts[4]);
cl = new CPOperand(parts[5]);
cu = new CPOperand(parts[6]);
out = new CPOperand(parts[7]);
if (lhsInput.getDataType() == DataType.MATRIX)
return new MatrixIndexingCPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
else if (lhsInput.getDataType() == DataType.FRAME)
return new FrameIndexingCPInstruction(new SimpleOperator(null), lhsInput, rhsInput, rl, ru, cl, cu, out, opcode, str);
else
throw new DMLRuntimeException("Can index only on Frames or Matrices");
} else {
throw new DMLRuntimeException("Invalid number of operands in instruction: " + str);
}
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a MatrixIndexingCPInstruction: " + str);
}
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project systemml by apache.
the class AggregateUnaryCPInstruction method parseInstruction.
public static AggregateUnaryCPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
if (opcode.equalsIgnoreCase("nrow") || opcode.equalsIgnoreCase("ncol") || opcode.equalsIgnoreCase("length") || opcode.equalsIgnoreCase("exists")) {
return new AggregateUnaryCPInstruction(new SimpleOperator(Builtin.getBuiltinFnObject(opcode)), in1, out, AUType.valueOf(opcode.toUpperCase()), opcode, str);
} else {
// DEFAULT BEHAVIOR
AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode, Integer.parseInt(parts[3]));
return new AggregateUnaryCPInstruction(aggun, in1, out, AUType.DEFAULT, opcode, str);
}
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project 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") || opcode.equalsIgnoreCase("lowertri") || opcode.equalsIgnoreCase("uppertri")) {
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.matrix.operators.SimpleOperator in project systemml by apache.
the class ParameterizedBuiltinSPInstruction method parseInstruction.
public static ParameterizedBuiltinSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
// first part is always the opcode
String opcode = parts[0];
if (opcode.equalsIgnoreCase("mapgroupedagg")) {
CPOperand target = new CPOperand(parts[1]);
CPOperand groups = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
HashMap<String, String> paramsMap = new HashMap<>();
paramsMap.put(Statement.GAGG_TARGET, target.getName());
paramsMap.put(Statement.GAGG_GROUPS, groups.getName());
paramsMap.put(Statement.GAGG_NUM_GROUPS, parts[4]);
Operator op = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
return new ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
} else {
// 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("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 ParameterizedBuiltinSPInstruction(op, paramsMap, out, opcode, str, false);
} else if (opcode.equalsIgnoreCase("rmempty")) {
boolean bRmEmptyBC = false;
if (parts.length > 6)
bRmEmptyBC = Boolean.parseBoolean(parts[5]);
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, bRmEmptyBC);
} else if (opcode.equalsIgnoreCase("rexpand") || opcode.equalsIgnoreCase("replace") || opcode.equalsIgnoreCase("lowertri") || opcode.equalsIgnoreCase("uppertri") || opcode.equalsIgnoreCase("transformapply") || opcode.equalsIgnoreCase("transformdecode")) {
func = ParameterizedBuiltin.getParameterizedBuiltinFnObject(opcode);
return new ParameterizedBuiltinSPInstruction(new SimpleOperator(func), paramsMap, out, opcode, str, false);
} else {
throw new DMLRuntimeException("Unknown opcode (" + opcode + ") for ParameterizedBuiltin Instruction.");
}
}
}
Aggregations