Search in sources :

Example 6 with DataGenMethod

use of org.apache.sysml.hops.Hop.DataGenMethod in project systemml by apache.

the class RandSPInstruction method parseInstruction.

public static RandSPInstruction parseInstruction(String str) {
    String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = s[0];
    DataGenMethod method = DataGenMethod.INVALID;
    if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
        method = DataGenMethod.RAND;
        InstructionUtils.checkNumFields(str, 12);
    } else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
        method = DataGenMethod.SEQ;
        // 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
        InstructionUtils.checkNumFields(str, 8);
    } else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
        method = DataGenMethod.SAMPLE;
        // 7 operands: range, size, replace, seed, rpb, cpb, outvar
        InstructionUtils.checkNumFields(str, 7);
    }
    Operator op = null;
    // output is specified by the last operand
    CPOperand out = new CPOperand(s[s.length - 1]);
    if (method == DataGenMethod.RAND) {
        CPOperand rows = new CPOperand(s[1]);
        CPOperand cols = new CPOperand(s[2]);
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        double minValue = !s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[5]).doubleValue() : -1;
        double maxValue = !s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[6]).doubleValue() : -1;
        double sparsity = !s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[7]).doubleValue() : -1;
        long seed = !s[8].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Long.valueOf(s[8]).longValue() : -1;
        String dir = s[9];
        String pdf = s[10];
        String pdfParams = !s[11].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? s[11] : null;
        return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, dir, pdf, pdfParams, opcode, str);
    } else if (method == DataGenMethod.SEQ) {
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        CPOperand from = new CPOperand(s[5]);
        CPOperand to = new CPOperand(s[6]);
        CPOperand incr = new CPOperand(s[7]);
        CPOperand in = null;
        return new RandSPInstruction(op, method, in, out, null, null, rpb, cpb, from, to, incr, opcode, str);
    } else if (method == DataGenMethod.SAMPLE) {
        double max = !s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? Double.valueOf(s[1]) : 0;
        CPOperand rows = new CPOperand(s[2]);
        CPOperand cols = new CPOperand("1", ValueType.INT, DataType.SCALAR);
        boolean replace = (!s[3].contains(Lop.VARIABLE_NAME_PLACEHOLDER) && Boolean.valueOf(s[3]));
        long seed = Long.parseLong(s[4]);
        int rpb = Integer.parseInt(s[5]);
        int cpb = Integer.parseInt(s[6]);
        return new RandSPInstruction(op, method, null, out, rows, cols, rpb, cpb, max, replace, seed, opcode, str);
    } else
        throw new DMLRuntimeException("Unrecognized data generation method: " + method);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DataGenMethod(org.apache.sysml.hops.Hop.DataGenMethod) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 Operator (org.apache.sysml.runtime.matrix.operators.Operator)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DataGenOp (org.apache.sysml.hops.DataGenOp)2 DataOp (org.apache.sysml.hops.DataOp)2 Hop (org.apache.sysml.hops.Hop)2 ReorgOp (org.apache.sysml.hops.ReorgOp)2 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)2