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 incubator-systemml by apache.
the class BooleanUnaryCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
// 1) Obtain data objects associated with inputs
ScalarObject so = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
// 2) Compute the result value & make an appropriate data object
SimpleOperator dop = (SimpleOperator) _optr;
boolean rval = dop.fn.execute(so.getBooleanValue());
ScalarObject sores = (ScalarObject) new BooleanObject(rval);
// 3) Put the result value into ProgramBlock
ec.setScalarOutput(output.getName(), sores);
}
use of org.apache.sysml.runtime.matrix.operators.SimpleOperator in project incubator-systemml by apache.
the class ScalarBuiltinCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
String opcode = getOpcode();
SimpleOperator dop = (SimpleOperator) _optr;
ScalarObject sores = null;
ScalarObject so = null;
//get the scalar input
so = ec.getScalarInput(input1.getName(), input1.getValueType(), input1.isLiteral());
//core execution
if (opcode.equalsIgnoreCase("print")) {
String outString = so.getLanguageSpecificStringValue();
// The flag will be set, for example, when SystemML is invoked in fenced mode from Jaql.
if (!DMLScript.suppressPrint2Stdout())
System.out.println(outString);
// String that is printed on stdout will be inserted into symbol table (dummy, not necessary!)
sores = new StringObject(outString);
} else if (opcode.equalsIgnoreCase("stop")) {
throw new DMLScriptException(so.getStringValue());
} else {
//Inputs for all builtins other than PRINT are treated as DOUBLE.
if (so instanceof IntObject && output.getValueType() == ValueType.INT) {
long rval = (long) dop.fn.execute(so.getLongValue());
sores = (ScalarObject) new IntObject(rval);
} else {
double rval = dop.fn.execute(so.getDoubleValue());
sores = (ScalarObject) new DoubleObject(rval);
}
}
ec.setScalarOutput(output.getName(), sores);
}
Aggregations