Search in sources :

Example 21 with DataGenOp

use of org.apache.sysml.hops.DataGenOp in project incubator-systemml by apache.

the class RewriteAlgebraicSimplificationStatic method simplifyConstantSort.

private static Hop simplifyConstantSort(Hop parent, Hop hi, int pos) {
    // order(matrix(7), indexreturn=TRUE) -> seq(1,nrow(X),1)
    if (// order
    hi instanceof ReorgOp && ((ReorgOp) hi).getOp() == ReOrgOp.SORT) {
        Hop hi2 = hi.getInput().get(0);
        if (hi2 instanceof DataGenOp && ((DataGenOp) hi2).getOp() == DataGenMethod.RAND && ((DataGenOp) hi2).hasConstantValue() && // known indexreturn
        hi.getInput().get(3) instanceof LiteralOp) {
            if (HopRewriteUtils.getBooleanValue((LiteralOp) hi.getInput().get(3))) {
                // order(matrix(7), indexreturn=TRUE) -> seq(1,nrow(X),1)
                Hop seq = HopRewriteUtils.createSeqDataGenOp(hi2);
                seq.refreshSizeInformation();
                HopRewriteUtils.replaceChildReference(parent, hi, seq, pos);
                HopRewriteUtils.cleanupUnreferenced(hi);
                hi = seq;
                LOG.debug("Applied simplifyConstantSort1.");
            } else {
                // order(matrix(7), indexreturn=FALSE) -> matrix(7)
                HopRewriteUtils.replaceChildReference(parent, hi, hi2, pos);
                HopRewriteUtils.cleanupUnreferenced(hi);
                hi = hi2;
                LOG.debug("Applied simplifyConstantSort2.");
            }
        }
    }
    return hi;
}
Also used : DataGenOp(org.apache.sysml.hops.DataGenOp) ReorgOp(org.apache.sysml.hops.ReorgOp) Hop(org.apache.sysml.hops.Hop) LiteralOp(org.apache.sysml.hops.LiteralOp)

Aggregations

DataGenOp (org.apache.sysml.hops.DataGenOp)21 Hop (org.apache.sysml.hops.Hop)21 LiteralOp (org.apache.sysml.hops.LiteralOp)13 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)6 DataIdentifier (org.apache.sysml.parser.DataIdentifier)6 ReorgOp (org.apache.sysml.hops.ReorgOp)5 AggBinaryOp (org.apache.sysml.hops.AggBinaryOp)4 AggUnaryOp (org.apache.sysml.hops.AggUnaryOp)4 BinaryOp (org.apache.sysml.hops.BinaryOp)4 UnaryOp (org.apache.sysml.hops.UnaryOp)4 DataOp (org.apache.sysml.hops.DataOp)2 List (java.util.List)1 ConvolutionOp (org.apache.sysml.hops.ConvolutionOp)1 DataGenMethod (org.apache.sysml.hops.Hop.DataGenMethod)1 MultiThreadedHop (org.apache.sysml.hops.Hop.MultiThreadedHop)1 OpOp2 (org.apache.sysml.hops.Hop.OpOp2)1 OpOpN (org.apache.sysml.hops.Hop.OpOpN)1 HopsException (org.apache.sysml.hops.HopsException)1 IndexingOp (org.apache.sysml.hops.IndexingOp)1