Search in sources :

Example 6 with DataIdentifier

use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.

the class HopRewriteUtils method createDataGenOpByVal.

public static Hop createDataGenOpByVal(ArrayList<LiteralOp> values, long rows, long cols) {
    StringBuilder sb = new StringBuilder();
    for (LiteralOp lit : values) {
        if (sb.length() > 0)
            sb.append(StringInitCPInstruction.DELIM);
        sb.append(lit.getStringValue());
    }
    LiteralOp str = new LiteralOp(sb.toString());
    HashMap<String, Hop> params = new HashMap<>();
    params.put(DataExpression.RAND_ROWS, new LiteralOp(rows));
    params.put(DataExpression.RAND_COLS, new LiteralOp(cols));
    params.put(DataExpression.RAND_MIN, str);
    params.put(DataExpression.RAND_MAX, str);
    params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED));
    Hop datagen = new DataGenOp(DataGenMethod.SINIT, new DataIdentifier("tmp"), params);
    int blksz = ConfigurationManager.getBlocksize();
    datagen.setOutputBlocksizes(blksz, blksz);
    copyLineNumbers(values.get(0), datagen);
    return datagen;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 7 with DataIdentifier

use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.

the class HopRewriteUtils method createDataGenOp.

public static Hop createDataGenOp(Hop rowInput, boolean tRowInput, Hop colInput, boolean tColInput, double value) {
    long nrow = tRowInput ? rowInput.getDim2() : rowInput.getDim1();
    long ncol = tColInput ? colInput.getDim1() : rowInput.getDim2();
    Hop rows = (nrow >= 0) ? new LiteralOp(nrow) : new UnaryOp("tmprows", DataType.SCALAR, ValueType.INT, tRowInput ? OpOp1.NCOL : OpOp1.NROW, rowInput);
    Hop cols = (ncol >= 0) ? new LiteralOp(ncol) : new UnaryOp("tmpcols", DataType.SCALAR, ValueType.INT, tColInput ? OpOp1.NROW : OpOp1.NCOL, colInput);
    Hop val = new LiteralOp(value);
    HashMap<String, Hop> params = new HashMap<>();
    params.put(DataExpression.RAND_ROWS, rows);
    params.put(DataExpression.RAND_COLS, cols);
    params.put(DataExpression.RAND_MIN, val);
    params.put(DataExpression.RAND_MAX, val);
    params.put(DataExpression.RAND_PDF, new LiteralOp(DataExpression.RAND_PDF_UNIFORM));
    params.put(DataExpression.RAND_LAMBDA, new LiteralOp(-1.0));
    params.put(DataExpression.RAND_SPARSITY, new LiteralOp(1.0));
    params.put(DataExpression.RAND_SEED, new LiteralOp(DataGenOp.UNSPECIFIED_SEED));
    // note internal refresh size information
    Hop datagen = new DataGenOp(DataGenMethod.RAND, new DataIdentifier("tmp"), params);
    datagen.setOutputBlocksizes(rowInput.getRowsInBlock(), colInput.getColsInBlock());
    copyLineNumbers(rowInput, datagen);
    if (value == 0)
        datagen.setNnz(0);
    return datagen;
}
Also used : AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 8 with DataIdentifier

use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.

the class HopRewriteUtils method copyDataGenOp.

/**
 * Assumes that min and max are literal ops, needs to be checked from outside.
 *
 * @param inputGen input data gen op
 * @param scale the scale
 * @param shift the shift
 * @return data gen op
 */
public static DataGenOp copyDataGenOp(DataGenOp inputGen, double scale, double shift) {
    HashMap<String, Integer> params = inputGen.getParamIndexMap();
    Hop rows = inputGen.getInput().get(params.get(DataExpression.RAND_ROWS));
    Hop cols = inputGen.getInput().get(params.get(DataExpression.RAND_COLS));
    Hop min = inputGen.getInput().get(params.get(DataExpression.RAND_MIN));
    Hop max = inputGen.getInput().get(params.get(DataExpression.RAND_MAX));
    Hop pdf = inputGen.getInput().get(params.get(DataExpression.RAND_PDF));
    Hop mean = inputGen.getInput().get(params.get(DataExpression.RAND_LAMBDA));
    Hop sparsity = inputGen.getInput().get(params.get(DataExpression.RAND_SPARSITY));
    Hop seed = inputGen.getInput().get(params.get(DataExpression.RAND_SEED));
    // check for literal ops
    if (!(min instanceof LiteralOp) || !(max instanceof LiteralOp))
        return null;
    // scale and shift
    double smin = getDoubleValue((LiteralOp) min);
    double smax = getDoubleValue((LiteralOp) max);
    smin = smin * scale + shift;
    smax = smax * scale + shift;
    Hop sminHop = new LiteralOp(smin);
    Hop smaxHop = new LiteralOp(smax);
    HashMap<String, Hop> params2 = new HashMap<>();
    params2.put(DataExpression.RAND_ROWS, rows);
    params2.put(DataExpression.RAND_COLS, cols);
    params2.put(DataExpression.RAND_MIN, sminHop);
    params2.put(DataExpression.RAND_MAX, smaxHop);
    params2.put(DataExpression.RAND_PDF, pdf);
    params2.put(DataExpression.RAND_LAMBDA, mean);
    params2.put(DataExpression.RAND_SPARSITY, sparsity);
    params2.put(DataExpression.RAND_SEED, seed);
    // note internal refresh size information
    DataGenOp datagen = new DataGenOp(DataGenMethod.RAND, new DataIdentifier("tmp"), params2);
    datagen.setOutputBlocksizes(inputGen.getRowsInBlock(), inputGen.getColsInBlock());
    copyLineNumbers(inputGen, datagen);
    if (smin == 0 && smax == 0)
        datagen.setNnz(0);
    return datagen;
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 9 with DataIdentifier

use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.

the class HopRewriteUtils method createSeqDataGenOp.

public static DataGenOp createSeqDataGenOp(Hop input, boolean asc) {
    Hop to = input.rowsKnown() ? new LiteralOp(input.getDim1()) : new UnaryOp("tmprows", DataType.SCALAR, ValueType.INT, OpOp1.NROW, input);
    HashMap<String, Hop> params = new HashMap<>();
    if (asc) {
        params.put(Statement.SEQ_FROM, new LiteralOp(1));
        params.put(Statement.SEQ_TO, to);
        params.put(Statement.SEQ_INCR, new LiteralOp(1));
    } else {
        params.put(Statement.SEQ_FROM, to);
        params.put(Statement.SEQ_TO, new LiteralOp(1));
        params.put(Statement.SEQ_INCR, new LiteralOp(-1));
    }
    // note internal refresh size information
    DataGenOp datagen = new DataGenOp(DataGenMethod.SEQ, new DataIdentifier("tmp"), params);
    datagen.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
    copyLineNumbers(input, datagen);
    return datagen;
}
Also used : AggUnaryOp(org.apache.sysml.hops.AggUnaryOp) UnaryOp(org.apache.sysml.hops.UnaryOp) DataIdentifier(org.apache.sysml.parser.DataIdentifier) HashMap(java.util.HashMap) DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 10 with DataIdentifier

use of org.apache.sysml.parser.DataIdentifier in project incubator-systemml by apache.

the class CommonSyntacticValidator method exitAssignmentStatementHelper.

protected void exitAssignmentStatementHelper(ParserRuleContext ctx, String lhs, ExpressionInfo dataInfo, Token lhsStart, ExpressionInfo rhs, StatementInfo info) {
    if (lhs.startsWith("$")) {
        notifyErrorListeners("assignment of commandline parameters is not allowed. (Quickfix: try using someLocalVariable=ifdef(" + lhs + ", default value))", ctx.start);
        return;
    }
    DataIdentifier target = null;
    if (dataInfo.expr instanceof DataIdentifier) {
        target = (DataIdentifier) dataInfo.expr;
        Expression source = rhs.expr;
        try {
            info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
        } catch (LanguageException e) {
            // TODO: extract more meaningful info from this exception.
            notifyErrorListeners("invalid assignment", lhsStart);
            return;
        }
    } else {
        notifyErrorListeners("incorrect lvalue in assignment statement", lhsStart);
        return;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) DataIdentifier(org.apache.sysml.parser.DataIdentifier) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement) MultiAssignmentStatement(org.apache.sysml.parser.MultiAssignmentStatement)

Aggregations

DataIdentifier (org.apache.sysml.parser.DataIdentifier)56 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)13 ParameterExpression (org.apache.sysml.parser.ParameterExpression)13 Hop (org.apache.sysml.hops.Hop)12 Expression (org.apache.sysml.parser.Expression)12 LiteralOp (org.apache.sysml.hops.LiteralOp)10 BinaryExpression (org.apache.sysml.parser.BinaryExpression)8 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)8 Data (org.apache.sysml.runtime.instructions.cp.Data)7 DataGenOp (org.apache.sysml.hops.DataGenOp)6 DataOp (org.apache.sysml.hops.DataOp)6 StatementBlock (org.apache.sysml.parser.StatementBlock)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 HopsException (org.apache.sysml.hops.HopsException)4 DataType (org.apache.sysml.parser.Expression.DataType)4 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)4 IterablePredicate (org.apache.sysml.parser.IterablePredicate)4 LanguageException (org.apache.sysml.parser.LanguageException)4 ParForStatement (org.apache.sysml.parser.ParForStatement)4