Search in sources :

Example 71 with LiteralOp

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();
}
Also used : HopsException.check(org.apache.sysml.hops.HopsException.check) HopsException(org.apache.sysml.hops.HopsException) Set(java.util.Set) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) Collectors(java.util.stream.Collectors) Hop(org.apache.sysml.hops.Hop) ArrayList(java.util.ArrayList) FunctionOp(org.apache.sysml.hops.FunctionOp) LiteralOp(org.apache.sysml.hops.LiteralOp) HashSet(java.util.HashSet) DataOp(org.apache.sysml.hops.DataOp) Expression(org.apache.sysml.parser.Expression) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Explain(org.apache.sysml.utils.Explain) Expression(org.apache.sysml.parser.Expression) Hop(org.apache.sysml.hops.Hop) FunctionOp(org.apache.sysml.hops.FunctionOp) LiteralOp(org.apache.sysml.hops.LiteralOp) DataOp(org.apache.sysml.hops.DataOp)

Example 72 with LiteralOp

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);
}
Also used : LiteralOp(org.apache.sysml.hops.LiteralOp)

Example 73 with LiteralOp

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;
}
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 74 with LiteralOp

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;
}
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 75 with LiteralOp

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;
}
Also used : DataGenOp(org.apache.sysml.hops.DataGenOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Aggregations

LiteralOp (org.apache.sysml.hops.LiteralOp)102 Hop (org.apache.sysml.hops.Hop)88 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)30 BinaryOp (org.apache.sysml.hops.BinaryOp)27 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)25 UnaryOp (org.apache.sysml.hops.UnaryOp)24 DataOp (org.apache.sysml.hops.DataOp)23 IndexingOp (org.apache.sysml.hops.IndexingOp)17 ArrayList (java.util.ArrayList)13 DataGenOp (org.apache.sysml.hops.DataGenOp)13 LeftIndexingOp (org.apache.sysml.hops.LeftIndexingOp)12 HashMap (java.util.HashMap)11 DataIdentifier (org.apache.sysml.parser.DataIdentifier)10 ReorgOp (org.apache.sysml.hops.ReorgOp)9 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)9 HopsException (org.apache.sysml.hops.HopsException)8 ParameterizedBuiltinOp (org.apache.sysml.hops.ParameterizedBuiltinOp)8 StatementBlock (org.apache.sysml.parser.StatementBlock)8 TernaryOp (org.apache.sysml.hops.TernaryOp)7 CNodeData (org.apache.sysml.hops.codegen.cplan.CNodeData)6