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 SpoofCellwise method executeDenseAggMxx.
private double executeDenseAggMxx(double[] a, SideInput[] b, double[] scalars, int m, int n, boolean sparseSafe, int rl, int ru) throws DMLRuntimeException {
//safe aggregation for min/max w/ handling of zero entries
//note: sparse safe with zero value as min/max handled outside
double ret = (_aggOp == AggOp.MIN) ? Double.MAX_VALUE : -Double.MAX_VALUE;
ValueFunction vfun = getAggFunction();
for (int i = rl, ix = rl * n; i < ru; i++) for (int j = 0; j < n; j++, ix++) {
double aval = (a != null) ? a[ix] : 0;
if (aval != 0 || !sparseSafe)
ret = vfun.execute(ret, genexec(aval, b, scalars, m, n, i, j));
}
return ret;
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class SpoofCellwise method executeDenseRowAggMxx.
private long executeDenseRowAggMxx(double[] a, SideInput[] b, double[] scalars, double[] c, int m, int n, boolean sparseSafe, int rl, int ru) throws DMLRuntimeException {
double initialVal = (_aggOp == AggOp.MIN) ? Double.MAX_VALUE : -Double.MAX_VALUE;
ValueFunction vfun = getAggFunction();
long lnnz = 0;
if (a == null && !sparseSafe) {
//empty
for (int i = rl; i < ru; i++) {
double tmp = initialVal;
for (int j = 0; j < n; j++) tmp = vfun.execute(tmp, genexec(0, b, scalars, m, n, i, j));
lnnz += ((c[i] = tmp) != 0) ? 1 : 0;
}
} else if (a != null) {
//general case
for (int i = rl, ix = rl * n; i < ru; i++) {
double tmp = initialVal;
for (int j = 0; j < n; j++, ix++) if (a[ix] != 0 || !sparseSafe)
tmp = vfun.execute(tmp, genexec(a[ix], b, scalars, m, n, i, j));
if (sparseSafe && UtilFunctions.containsZero(a, ix - n, n))
tmp = vfun.execute(tmp, 0);
lnnz += ((c[i] = tmp) != 0) ? 1 : 0;
}
}
return lnnz;
}
Aggregations