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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations