Search in sources :

Example 1 with DataGenMethod

use of org.apache.sysml.hops.Hop.DataGenMethod in project incubator-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)

Example 2 with DataGenMethod

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

the class DMLTranslator method processDataExpression.

/**
 * Construct Hops from parse tree : Process ParameterizedExpression in a
 * read/write/rand statement
 *
 * @param source data expression
 * @param target data identifier
 * @param hops map of high-level operators
 * @return high-level operator
 */
private Hop processDataExpression(DataExpression source, DataIdentifier target, HashMap<String, Hop> hops) {
    // this expression has multiple "named" parameters
    HashMap<String, Hop> paramHops = new HashMap<>();
    // -- construct hops for all input parameters
    // -- store them in hashmap so that their "name"s are maintained
    Hop pHop = null;
    for (String paramName : source.getVarParams().keySet()) {
        pHop = processExpression(source.getVarParam(paramName), null, hops);
        paramHops.put(paramName, pHop);
    }
    Hop currBuiltinOp = null;
    if (target == null) {
        target = createTarget(source);
    }
    // construct hop based on opcode
    switch(source.getOpCode()) {
        case READ:
            currBuiltinOp = new DataOp(target.getName(), target.getDataType(), target.getValueType(), DataOpTypes.PERSISTENTREAD, paramHops);
            ((DataOp) currBuiltinOp).setFileName(((StringIdentifier) source.getVarParam(DataExpression.IO_FILENAME)).getValue());
            break;
        case WRITE:
            currBuiltinOp = new DataOp(target.getName(), target.getDataType(), target.getValueType(), DataOpTypes.PERSISTENTWRITE, hops.get(target.getName()), paramHops);
            break;
        case RAND:
            // We limit RAND_MIN, RAND_MAX, RAND_SPARSITY, RAND_SEED, and RAND_PDF to be constants
            DataGenMethod method = (paramHops.get(DataExpression.RAND_MIN).getValueType() == ValueType.STRING) ? DataGenMethod.SINIT : DataGenMethod.RAND;
            currBuiltinOp = new DataGenOp(method, target, paramHops);
            break;
        case MATRIX:
            ArrayList<Hop> tmp = new ArrayList<>();
            tmp.add(0, paramHops.get(DataExpression.RAND_DATA));
            tmp.add(1, paramHops.get(DataExpression.RAND_ROWS));
            tmp.add(2, paramHops.get(DataExpression.RAND_COLS));
            tmp.add(3, paramHops.get(DataExpression.RAND_BY_ROW));
            currBuiltinOp = new ReorgOp(target.getName(), target.getDataType(), target.getValueType(), ReOrgOp.RESHAPE, tmp);
            break;
        default:
            LOG.error(source.printErrorLocation() + "processDataExpression():: Unknown operation:  " + source.getOpCode());
            throw new ParseException(source.printErrorLocation() + "processDataExpression():: Unknown operation:  " + source.getOpCode());
    }
    // set identifier meta data (incl dimensions and blocksizes)
    setIdentifierParams(currBuiltinOp, source.getOutput());
    if (source.getOpCode() == DataExpression.DataOp.READ)
        ((DataOp) currBuiltinOp).setInputBlockSizes(target.getRowsInBlock(), target.getColumnsInBlock());
    currBuiltinOp.setParseInfo(source);
    return currBuiltinOp;
}
Also used : HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) ReorgOp(org.apache.sysml.hops.ReorgOp) DataGenMethod(org.apache.sysml.hops.Hop.DataGenMethod) DataOp(org.apache.sysml.hops.DataOp)

Example 3 with DataGenMethod

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

the class DataGenCPInstruction method parseInstruction.

public static DataGenCPInstruction parseInstruction(String str) {
    DataGenMethod method = DataGenMethod.INVALID;
    String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = s[0];
    if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
        method = DataGenMethod.RAND;
        InstructionUtils.checkNumFields(s, 12);
    } else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
        method = DataGenMethod.SEQ;
        // 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
        InstructionUtils.checkNumFields(s, 8);
    } else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
        method = DataGenMethod.SAMPLE;
        // 7 operands: range, size, replace, seed, rpb, cpb, outvar
        InstructionUtils.checkNumFields(s, 7);
    }
    CPOperand out = new CPOperand(s[s.length - 1]);
    Operator op = null;
    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 pdf = s[9];
        String pdfParams = !s[10].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? s[10] : null;
        int k = Integer.parseInt(s[11]);
        return new DataGenCPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, pdf, pdfParams, k, 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]);
        return new DataGenCPInstruction(op, method, null, 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 DataGenCPInstruction(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) DataGenMethod(org.apache.sysml.hops.Hop.DataGenMethod) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with DataGenMethod

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

the class DMLTranslator method processDataExpression.

/**
 * Construct Hops from parse tree : Process ParameterizedExpression in a
 * read/write/rand statement
 *
 * @param source data expression
 * @param target data identifier
 * @param hops map of high-level operators
 * @return high-level operator
 */
private Hop processDataExpression(DataExpression source, DataIdentifier target, HashMap<String, Hop> hops) {
    // this expression has multiple "named" parameters
    HashMap<String, Hop> paramHops = new HashMap<>();
    // -- construct hops for all input parameters
    // -- store them in hashmap so that their "name"s are maintained
    Hop pHop = null;
    for (String paramName : source.getVarParams().keySet()) {
        pHop = processExpression(source.getVarParam(paramName), null, hops);
        paramHops.put(paramName, pHop);
    }
    Hop currBuiltinOp = null;
    if (target == null) {
        target = createTarget(source);
    }
    // construct hop based on opcode
    switch(source.getOpCode()) {
        case READ:
            currBuiltinOp = new DataOp(target.getName(), target.getDataType(), target.getValueType(), DataOpTypes.PERSISTENTREAD, paramHops);
            ((DataOp) currBuiltinOp).setFileName(((StringIdentifier) source.getVarParam(DataExpression.IO_FILENAME)).getValue());
            break;
        case WRITE:
            currBuiltinOp = new DataOp(target.getName(), target.getDataType(), target.getValueType(), DataOpTypes.PERSISTENTWRITE, hops.get(target.getName()), paramHops);
            break;
        case RAND:
            // We limit RAND_MIN, RAND_MAX, RAND_SPARSITY, RAND_SEED, and RAND_PDF to be constants
            DataGenMethod method = (paramHops.get(DataExpression.RAND_MIN).getValueType() == ValueType.STRING) ? DataGenMethod.SINIT : DataGenMethod.RAND;
            currBuiltinOp = new DataGenOp(method, target, paramHops);
            break;
        case MATRIX:
            ArrayList<Hop> tmp = new ArrayList<>();
            tmp.add(0, paramHops.get(DataExpression.RAND_DATA));
            tmp.add(1, paramHops.get(DataExpression.RAND_ROWS));
            tmp.add(2, paramHops.get(DataExpression.RAND_COLS));
            tmp.add(3, paramHops.get(DataExpression.RAND_BY_ROW));
            currBuiltinOp = new ReorgOp(target.getName(), target.getDataType(), target.getValueType(), ReOrgOp.RESHAPE, tmp);
            break;
        default:
            LOG.error(source.printErrorLocation() + "processDataExpression():: Unknown operation:  " + source.getOpCode());
            throw new ParseException(source.printErrorLocation() + "processDataExpression():: Unknown operation:  " + source.getOpCode());
    }
    // set identifier meta data (incl dimensions and blocksizes)
    setIdentifierParams(currBuiltinOp, source.getOutput());
    if (source.getOpCode() == DataExpression.DataOp.READ)
        ((DataOp) currBuiltinOp).setInputBlockSizes(target.getRowsInBlock(), target.getColumnsInBlock());
    currBuiltinOp.setParseInfo(source);
    return currBuiltinOp;
}
Also used : HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) ReorgOp(org.apache.sysml.hops.ReorgOp) DataGenMethod(org.apache.sysml.hops.Hop.DataGenMethod) DataOp(org.apache.sysml.hops.DataOp)

Example 5 with DataGenMethod

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

the class DataGenCPInstruction method parseInstruction.

public static DataGenCPInstruction parseInstruction(String str) {
    DataGenMethod method = DataGenMethod.INVALID;
    String[] s = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = s[0];
    if (opcode.equalsIgnoreCase(DataGen.RAND_OPCODE)) {
        method = DataGenMethod.RAND;
        InstructionUtils.checkNumFields(s, 12);
    } else if (opcode.equalsIgnoreCase(DataGen.SEQ_OPCODE)) {
        method = DataGenMethod.SEQ;
        // 8 operands: rows, cols, rpb, cpb, from, to, incr, outvar
        InstructionUtils.checkNumFields(s, 8);
    } else if (opcode.equalsIgnoreCase(DataGen.SAMPLE_OPCODE)) {
        method = DataGenMethod.SAMPLE;
        // 7 operands: range, size, replace, seed, rpb, cpb, outvar
        InstructionUtils.checkNumFields(s, 7);
    }
    CPOperand out = new CPOperand(s[s.length - 1]);
    Operator op = null;
    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 pdf = s[9];
        String pdfParams = !s[10].contains(Lop.VARIABLE_NAME_PLACEHOLDER) ? s[10] : null;
        int k = Integer.parseInt(s[11]);
        return new DataGenCPInstruction(op, method, null, out, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, pdf, pdfParams, k, 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]);
        return new DataGenCPInstruction(op, method, null, 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 DataGenCPInstruction(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) 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