use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project incubator-systemml by apache.
the class FileCPInstruction method parseInstruction.
public static FileCPInstruction parseInstruction(String str) throws DMLRuntimeException {
String opcode = InstructionUtils.getOpCode(str);
int _arity = 2;
if (opcode.equalsIgnoreCase("rm"))
_arity = 1;
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
// there is no output, so we just have _arity
InstructionUtils.checkNumFields(parts, _arity);
String in1, in2;
opcode = parts[0];
FileOperationCode focode = getFileOperationCode(opcode);
in1 = parts[1];
in2 = null;
if (_arity == 2)
in2 = parts[2];
if (opcode.equalsIgnoreCase("rm")) {
return new FileCPInstruction(new SimpleOperator(RemoveFile.getRemoveFileFnObject()), focode, in1, in2, _arity, opcode, str);
} else if (opcode.equalsIgnoreCase("mv")) {
return new FileCPInstruction(new SimpleOperator(RenameFile.getRenameFileFnObject()), focode, in1, in2, _arity, opcode, str);
}
return null;
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator 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.matrix.operators.SimpleOperator 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.matrix.operators.SimpleOperator in project incubator-systemml by apache.
the class QuantileSortSPInstruction method parseInstruction.
public static QuantileSortSPInstruction 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 QuantileSortSPInstruction(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 QuantileSortSPInstruction(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 SortSPInstruction: " + str);
}
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator 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.");
}
}
Aggregations