use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class LiteralReplacement method replaceLiteralFullUnaryAggregate.
private static LiteralOp replaceLiteralFullUnaryAggregate(Hop c, LocalVariableMap vars) {
LiteralOp ret = null;
// full unary aggregate w/ matrix less than 10^6 cells
if (c instanceof AggUnaryOp && isReplaceableUnaryAggregate((AggUnaryOp) c) && c.getInput().get(0) instanceof DataOp && vars.keySet().contains(c.getInput().get(0).getName())) {
Hop data = c.getInput().get(0);
MatrixObject mo = (MatrixObject) vars.get(data.getName());
// dimensions might not have been updated during recompile
if (mo.getNumRows() * mo.getNumColumns() < REPLACE_LITERALS_MAX_MATRIX_SIZE) {
MatrixBlock mBlock = mo.acquireRead();
double value = replaceUnaryAggregate((AggUnaryOp) c, mBlock);
mo.release();
// literal substitution (always double)
ret = new LiteralOp(value);
}
}
return ret;
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class LiteralReplacement method replaceLiteralDataTypeCastMatrixRead.
private static LiteralOp replaceLiteralDataTypeCastMatrixRead(Hop c, LocalVariableMap vars) {
LiteralOp ret = null;
// as.scalar/matrix read - literal replacement
if (c instanceof UnaryOp && ((UnaryOp) c).getOp() == OpOp1.CAST_AS_SCALAR && c.getInput().get(0) instanceof DataOp && c.getInput().get(0).getDataType() == DataType.MATRIX) {
Data dat = vars.get(c.getInput().get(0).getName());
if (// required for selective constant propagation
dat != null) {
// cast as scalar (see VariableCPInstruction)
MatrixObject mo = (MatrixObject) dat;
MatrixBlock mBlock = mo.acquireRead();
if (mBlock.getNumRows() != 1 || mBlock.getNumColumns() != 1)
throw new DMLRuntimeException("Dimension mismatch - unable to cast matrix of dimension (" + mBlock.getNumRows() + " x " + mBlock.getNumColumns() + ") to scalar.");
double value = mBlock.getValue(0, 0);
mo.release();
// literal substitution (always double)
ret = new LiteralOp(value);
}
}
return ret;
}
use of org.apache.sysml.hops.LiteralOp 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.hops.LiteralOp in project incubator-systemml by apache.
the class HopRewriteUtils method isBasic1NSequence.
public static boolean isBasic1NSequence(Hop hop) {
if (hop instanceof DataGenOp && ((DataGenOp) hop).getOp() == DataGenMethod.SEQ) {
DataGenOp dgop = (DataGenOp) hop;
Hop from = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_FROM));
Hop incr = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_INCR));
return (from instanceof LiteralOp && getDoubleValueSafe((LiteralOp) from) == 1) && (incr instanceof LiteralOp && getDoubleValueSafe((LiteralOp) incr) == 1);
}
return false;
}
use of org.apache.sysml.hops.LiteralOp 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;
}
Aggregations