Search in sources :

Example 1 with ValueFunction

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;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) UnaryOperator(org.apache.sysml.runtime.matrix.operators.UnaryOperator)

Example 2 with ValueFunction

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);
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) BinaryOperator(org.apache.sysml.runtime.matrix.operators.BinaryOperator) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator)

Example 3 with ValueFunction

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");
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) SimpleOperator(org.apache.sysml.runtime.matrix.operators.SimpleOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with ValueFunction

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;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction)

Example 5 with ValueFunction

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;
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction)

Aggregations

ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)52 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)17 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)10 SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)9 KahanPlus (org.apache.sysml.runtime.functionobjects.KahanPlus)8 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)7 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)6 IJV (org.apache.sysml.runtime.matrix.data.IJV)6 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)4 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)4 Operator (org.apache.sysml.runtime.matrix.operators.Operator)4 UnaryOperator (org.apache.sysml.runtime.matrix.operators.UnaryOperator)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Builtin (org.apache.sysml.runtime.functionobjects.Builtin)2 BuiltinCode (org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode)2