use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class HopDagValidator method rValidateHop.
private static void rValidateHop(final Hop hop, final ValidatorState state) {
final long id = hop.getHopID();
// check visit status
final boolean seen = !state.seen.add(id);
if (seen != hop.isVisited()) {
String parentIDs = hop.getParent().stream().map(h -> Long.toString(h.getHopID())).collect(Collectors.joining(", "));
check(false, hop, parentIDs, seen);
}
// we saw the Hop previously, no need to re-validate
if (seen)
return;
// check parent linking
for (Hop parent : hop.getParent()) check(parent.getInput().contains(hop), hop, "not properly linked to its parent pid=%d %s", parent.getHopID(), parent.getClass().getName());
final ArrayList<Hop> input = hop.getInput();
final Expression.DataType dt = hop.getDataType();
final Expression.ValueType vt = hop.getValueType();
// check child linking
for (Hop child : input) check(child.getParent().contains(hop), hop, "not properly linked to its child cid=%d %s", child.getHopID(), child.getClass().getName());
// check empty children (other variable-length Hops must have at least one child)
if (input.isEmpty())
check(hop instanceof DataOp || hop instanceof FunctionOp || hop instanceof LiteralOp, hop, "is not a dataop/functionop/literal but has no children");
// check Hop has a legal arity (number of children)
hop.checkArity();
// check Matrix data type Hops must have Double Value type
if (dt == Expression.DataType.MATRIX)
check(vt == Expression.ValueType.DOUBLE || vt == Expression.ValueType.INT, hop, "has Matrix type but Value Type %s is not DOUBLE", vt);
// recursively process children
for (Hop child : input) rValidateHop(child, state);
hop.setVisited();
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class HopRewriteUtils method createIndexingOp.
public static IndexingOp createIndexingOp(Hop input, long rix, long cix) {
LiteralOp row = new LiteralOp(rix);
LiteralOp col = new LiteralOp(cix);
return createIndexingOp(input, row, row, col, col);
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class HopRewriteUtils method createDataGenOp.
public static Hop createDataGenOp(Hop input, double value) {
Hop rows = input.rowsKnown() ? new LiteralOp(input.getDim1()) : new UnaryOp("tmprows", DataType.SCALAR, ValueType.INT, OpOp1.NROW, input);
Hop cols = input.colsKnown() ? new LiteralOp(input.getDim2()) : new UnaryOp("tmpcols", DataType.SCALAR, ValueType.INT, OpOp1.NCOL, input);
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(input.getRowsInBlock(), input.getColsInBlock());
copyLineNumbers(input, datagen);
if (value == 0)
datagen.setNnz(0);
return datagen;
}
use of org.apache.sysml.hops.LiteralOp in project incubator-systemml by apache.
the class HopRewriteUtils method createDataGenOpByVal.
public static Hop createDataGenOpByVal(Hop rowInput, Hop colInput, double value) {
Hop val = new LiteralOp(value);
HashMap<String, Hop> params = new HashMap<>();
params.put(DataExpression.RAND_ROWS, rowInput);
params.put(DataExpression.RAND_COLS, colInput);
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.hops.LiteralOp in project incubator-systemml by apache.
the class HopRewriteUtils method isBasicN1Sequence.
public static boolean isBasicN1Sequence(Hop hop) {
boolean ret = false;
if (hop instanceof DataGenOp) {
DataGenOp dgop = (DataGenOp) hop;
if (dgop.getOp() == DataGenMethod.SEQ) {
Hop to = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_TO));
Hop incr = dgop.getInput().get(dgop.getParamIndex(Statement.SEQ_INCR));
ret = (to instanceof LiteralOp && getDoubleValueSafe((LiteralOp) to) == 1) && (incr instanceof LiteralOp && getDoubleValueSafe((LiteralOp) incr) == -1);
}
}
return ret;
}
Aggregations