Search in sources :

Example 41 with DataGenOp

use of org.apache.sysml.hops.DataGenOp in project 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)

Aggregations

DataGenOp (org.apache.sysml.hops.DataGenOp)41 Hop (org.apache.sysml.hops.Hop)41 LiteralOp (org.apache.sysml.hops.LiteralOp)26 HashMap (java.util.HashMap)18 DataIdentifier (org.apache.sysml.parser.DataIdentifier)12 ArrayList (java.util.ArrayList)11 ReorgOp (org.apache.sysml.hops.ReorgOp)10 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)8 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)8 BinaryOp (org.apache.sysml.hops.BinaryOp)8 UnaryOp (org.apache.sysml.hops.UnaryOp)8 DataOp (org.apache.sysml.hops.DataOp)4 List (java.util.List)2 ConvolutionOp (org.apache.sysml.hops.ConvolutionOp)2 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)2 OpOp2 (org.apache.sysml.hops.Hop.OpOp2)2 OpOpN (org.apache.sysml.hops.Hop.OpOpN)2 HopsException (org.apache.sysml.hops.HopsException)2 IndexingOp (org.apache.sysml.hops.IndexingOp)2 NaryOp (org.apache.sysml.hops.NaryOp)2