Search in sources :

Example 26 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class RandInstruction method parseInstruction.

public static RandInstruction parseInstruction(String str) throws DMLRuntimeException {
    InstructionUtils.checkNumFields(str, 13);
    String[] parts = InstructionUtils.getInstructionParts(str);
    Operator op = null;
    byte input = Byte.parseByte(parts[1]);
    byte output = Byte.parseByte(parts[2]);
    long rows = Double.valueOf(parts[3]).longValue();
    long cols = Double.valueOf(parts[4]).longValue();
    int rpb = Integer.parseInt(parts[5]);
    int cpb = Integer.parseInt(parts[6]);
    double minValue = Double.parseDouble(parts[7]);
    double maxValue = Double.parseDouble(parts[8]);
    double sparsity = Double.parseDouble(parts[9]);
    long seed = Long.parseLong(parts[10]);
    String baseDir = parts[11];
    String pdf = parts[12];
    String pdfParams = parts[13];
    return new RandInstruction(op, input, output, rows, cols, rpb, cpb, minValue, maxValue, sparsity, seed, pdf, pdfParams, baseDir, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator)

Example 27 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class MatrixReshapeMRInstruction method parseInstruction.

public static MatrixReshapeMRInstruction parseInstruction(String str) throws DMLRuntimeException {
    InstructionUtils.checkNumFields(str, 5);
    String[] parts = InstructionUtils.getInstructionParts(str);
    String opcode = parts[0];
    byte in = Byte.parseByte(parts[1]);
    //save cast
    long rows = UtilFunctions.toLong(Double.parseDouble(parts[2]));
    //save cast
    long cols = UtilFunctions.toLong(Double.parseDouble(parts[3]));
    boolean byrow = Boolean.parseBoolean(parts[4]);
    byte out = Byte.parseByte(parts[5]);
    if (!opcode.equalsIgnoreCase("rshape"))
        throw new DMLRuntimeException("Unknown opcode while parsing an MatrixReshapeMRInstruction: " + str);
    else
        return new MatrixReshapeMRInstruction(new Operator(true), in, rows, cols, byrow, out, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 28 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class DataGenCPInstruction method parseInstruction.

public static DataGenCPInstruction parseInstruction(String str) throws DMLRuntimeException {
    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);
    }
    // ouput is specified by the last operand
    CPOperand out = new CPOperand(s[s.length - 1]);
    Operator op = null;
    if (method == DataGenMethod.RAND) {
        long rows = -1, cols = -1;
        if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            rows = Double.valueOf(s[1]).longValue();
        }
        if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            cols = Double.valueOf(s[2]).longValue();
        }
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        double minValue = -1, maxValue = -1;
        if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            minValue = Double.valueOf(s[5]).doubleValue();
        }
        if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            maxValue = Double.valueOf(s[6]).doubleValue();
        }
        double sparsity = -1;
        if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            sparsity = Double.valueOf(s[7]);
        }
        long seed = DataGenOp.UNSPECIFIED_SEED;
        if (!s[8].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            seed = Long.parseLong(s[8]);
        }
        String pdf = s[9];
        String pdfParams = null;
        if (!s[10].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            pdfParams = s[10];
        }
        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) {
        // Example Instruction: CP:seq:11:1:1000:1000:1:0:-0.1:scratch_space/_p7932_192.168.1.120//_t0/:mVar1
        long rows = Double.valueOf(s[1]).longValue();
        long cols = Double.valueOf(s[2]).longValue();
        int rpb = Integer.parseInt(s[3]);
        int cpb = Integer.parseInt(s[4]);
        double from, to, incr;
        from = to = incr = Double.NaN;
        if (!s[5].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            from = Double.valueOf(s[5]);
        }
        if (!s[6].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            to = Double.valueOf(s[6]);
        }
        if (!s[7].contains(Lop.VARIABLE_NAME_PLACEHOLDER)) {
            incr = Double.valueOf(s[7]);
        }
        return new DataGenCPInstruction(op, method, null, out, rows, cols, rpb, cpb, from, to, incr, opcode, str);
    } else if (method == DataGenMethod.SAMPLE) {
        // Example Instruction: CP:sample:10:100:false:1000:1000:_mVar2·MATRIX·DOUBLE
        double max = 0;
        long rows = 0, cols;
        boolean replace = false;
        if (!s[1].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            max = Double.valueOf(s[1]);
        if (!s[2].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            rows = Double.valueOf(s[2]).longValue();
        cols = 1;
        if (!s[3].contains(Lop.VARIABLE_NAME_PLACEHOLDER))
            replace = 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 29 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class ArithmeticBinaryCPInstruction method parseInstruction.

public static ArithmeticBinaryCPInstruction 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);
    Operator operator = (in1.getDataType() != in2.getDataType()) ? InstructionUtils.parseScalarBinaryOperator(opcode, (in1.getDataType() == DataType.SCALAR)) : InstructionUtils.parseBinaryOperator(opcode);
    if (in1.getDataType() == DataType.SCALAR && in2.getDataType() == DataType.SCALAR)
        return new ScalarScalarArithmeticCPInstruction(operator, in1, in2, out, opcode, str);
    else if (in1.getDataType() == DataType.MATRIX && in2.getDataType() == DataType.MATRIX)
        return new MatrixMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str);
    else
        return new ScalarMatrixArithmeticCPInstruction(operator, in1, in2, out, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator)

Example 30 with Operator

use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.

the class ReblockSPInstruction method parseInstruction.

public static ReblockSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equals("rblk")) {
        throw new DMLRuntimeException("Incorrect opcode for ReblockSPInstruction:" + opcode);
    }
    CPOperand in = new CPOperand(parts[1]);
    CPOperand out = new CPOperand(parts[2]);
    int brlen = Integer.parseInt(parts[3]);
    int bclen = Integer.parseInt(parts[4]);
    boolean outputEmptyBlocks = Boolean.parseBoolean(parts[5]);
    // no operator for ReblockSPInstruction
    Operator op = null;
    return new ReblockSPInstruction(op, in, out, brlen, bclen, outputEmptyBlocks, opcode, str);
}
Also used : Operator(org.apache.sysml.runtime.matrix.operators.Operator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

Operator (org.apache.sysml.runtime.matrix.operators.Operator)32 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)20 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)10 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)5 DataType (org.apache.sysml.parser.Expression.DataType)4 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)4 MMTSJType (org.apache.sysml.lops.MMTSJ.MMTSJType)3 IOException (java.io.IOException)2 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)2 VectorType (org.apache.sysml.lops.BinaryM.VectorType)2 CM (org.apache.sysml.runtime.functionobjects.CM)2 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)2 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)2 GroupedAggregateInstruction (org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction)2 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)2 SimpleOperator (org.apache.sysml.runtime.matrix.operators.SimpleOperator)2 HashMap (java.util.HashMap)1 CacheType (org.apache.sysml.lops.PMMJ.CacheType)1 PDataPartitionFormat (org.apache.sysml.runtime.controlprogram.ParForProgramBlock.PDataPartitionFormat)1 AggregateUnaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateUnaryOperator)1