use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class SpoofMultiAggregate method aggregatePartialResults.
public static void aggregatePartialResults(AggOp[] aggOps, MatrixBlock c, MatrixBlock b) {
ValueFunction[] vfun = getAggFunctions(aggOps);
for (int k = 0; k < aggOps.length; k++) {
if (vfun[k] instanceof KahanFunction) {
KahanObject kbuff = new KahanObject(c.quickGetValue(0, k), 0);
KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
kplus.execute2(kbuff, b.quickGetValue(0, k));
c.quickSetValue(0, k, kbuff._sum);
} else {
double cval = c.quickGetValue(0, k);
double bval = b.quickGetValue(0, k);
c.quickSetValue(0, k, vfun[k].execute(cval, bval));
}
}
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class SpoofMultiAggregate method aggregatePartialResults.
private void aggregatePartialResults(double[] c, ArrayList<double[]> pret) {
ValueFunction[] vfun = getAggFunctions(_aggOps);
for (int k = 0; k < _aggOps.length; k++) {
if (vfun[k] instanceof KahanFunction) {
KahanObject kbuff = new KahanObject(0, 0);
KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
for (double[] tmp : pret) kplus.execute2(kbuff, tmp[k]);
c[k] = kbuff._sum;
} else {
for (double[] tmp : pret) c[k] = vfun[k].execute(c[k], tmp[k]);
}
}
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class UnaryCPInstruction method parseInstruction.
public static UnaryCPInstruction 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 = 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 UnaryMatrixCPInstruction(new UnaryOperator(func, Integer.parseInt(parts[3])), in, out, opcode, str);
else
return new UnaryScalarCPInstruction(null, in, out, opcode, str);
} else {
// 2+1, general case
opcode = parseUnaryInstruction(str, in, out);
if (in.getDataType() == DataType.SCALAR)
return new UnaryScalarCPInstruction(InstructionUtils.parseUnaryOperator(opcode), in, out, opcode, str);
else if (in.getDataType() == DataType.MATRIX)
return new UnaryMatrixCPInstruction(LibCommonsMath.isSupportedUnaryOperation(opcode) ? null : InstructionUtils.parseUnaryOperator(opcode), in, out, opcode, str);
}
return null;
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction in project incubator-systemml by apache.
the class BuiltinBinaryGPUInstruction method parseInstruction.
public static BuiltinBinaryGPUInstruction parseInstruction(String str) {
CPOperand in1 = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
CPOperand in2 = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
CPOperand out = new CPOperand("", Expression.ValueType.UNKNOWN, Expression.DataType.UNKNOWN);
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 3);
String opcode = parts[0];
in1.split(parts[1]);
in2.split(parts[2]);
out.split(parts[3]);
// check for valid data type of output
if ((in1.getDataType() == Expression.DataType.MATRIX || in2.getDataType() == Expression.DataType.MATRIX) && out.getDataType() != Expression.DataType.MATRIX)
throw new DMLRuntimeException("Element-wise matrix operations between variables " + in1.getName() + " and " + in2.getName() + " must produce a matrix, which " + out.getName() + " is not");
// Determine appropriate Function Object based on opcode
ValueFunction func = Builtin.getBuiltinFnObject(opcode);
boolean isMatrixMatrix = in1.getDataType() == Expression.DataType.MATRIX && in2.getDataType() == Expression.DataType.MATRIX;
boolean isMatrixScalar = (in1.getDataType() == Expression.DataType.MATRIX && in2.getDataType() == Expression.DataType.SCALAR) || (in1.getDataType() == Expression.DataType.SCALAR && in2.getDataType() == Expression.DataType.MATRIX);
if (in1.getDataType() == Expression.DataType.SCALAR && in2.getDataType() == Expression.DataType.SCALAR)
throw new DMLRuntimeException("GPU : Unsupported GPU builtin operations on 2 scalars");
else if (isMatrixMatrix && opcode.equals("solve"))
return new MatrixMatrixBuiltinGPUInstruction(new BinaryOperator(func), in1, in2, out, opcode, str, 2);
else if (isMatrixScalar && (opcode.equals("min") || opcode.equals("max")))
return new ScalarMatrixBuiltinGPUInstruction(new BinaryOperator(func), in1, in2, out, opcode, str, 2);
else
throw new DMLRuntimeException("GPU : Unsupported GPU builtin operations on a matrix and a scalar:" + opcode);
}
use of org.apache.sysml.runtime.functionobjects.ValueFunction 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.");
}
}
}
Aggregations