Search in sources :

Example 1 with ReOrgOp

use of org.apache.sysml.hops.Hop.ReOrgOp in project systemml by apache.

the class RewriteAlgebraicSimplificationStatic method removeUnnecessaryReorgOperation.

/**
 * Pattners: t(t(X)) -> X, rev(rev(X)) -> X
 *
 * @param parent parent high-level operator
 * @param hi high-level operator
 * @param pos position
 * @return high-level operator
 */
private static Hop removeUnnecessaryReorgOperation(Hop parent, Hop hi, int pos) {
    ReOrgOp[] lookup = new ReOrgOp[] { ReOrgOp.TRANSPOSE, ReOrgOp.REV };
    if (// first reorg
    hi instanceof ReorgOp && HopRewriteUtils.isValidOp(((ReorgOp) hi).getOp(), lookup)) {
        ReOrgOp firstOp = ((ReorgOp) hi).getOp();
        Hop hi2 = hi.getInput().get(0);
        if (// second reorg w/ same type
        hi2 instanceof ReorgOp && ((ReorgOp) hi2).getOp() == firstOp) {
            Hop hi3 = hi2.getInput().get(0);
            // remove unnecessary chain of t(t())
            HopRewriteUtils.replaceChildReference(parent, hi, hi3, pos);
            HopRewriteUtils.cleanupUnreferenced(hi, hi2);
            hi = hi3;
            LOG.debug("Applied removeUnecessaryReorgOperation.");
        }
    }
    return hi;
}
Also used : ReOrgOp(org.apache.sysml.hops.Hop.ReOrgOp) ReorgOp(org.apache.sysml.hops.ReorgOp) Hop(org.apache.sysml.hops.Hop)

Example 2 with ReOrgOp

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

the class RewriteAlgebraicSimplificationStatic method removeUnnecessaryReorgOperation.

/**
 * Pattners: t(t(X)) -> X, rev(rev(X)) -> X
 *
 * @param parent parent high-level operator
 * @param hi high-level operator
 * @param pos position
 * @return high-level operator
 */
private static Hop removeUnnecessaryReorgOperation(Hop parent, Hop hi, int pos) {
    ReOrgOp[] lookup = new ReOrgOp[] { ReOrgOp.TRANSPOSE, ReOrgOp.REV };
    if (// first reorg
    hi instanceof ReorgOp && HopRewriteUtils.isValidOp(((ReorgOp) hi).getOp(), lookup)) {
        ReOrgOp firstOp = ((ReorgOp) hi).getOp();
        Hop hi2 = hi.getInput().get(0);
        if (// second reorg w/ same type
        hi2 instanceof ReorgOp && ((ReorgOp) hi2).getOp() == firstOp) {
            Hop hi3 = hi2.getInput().get(0);
            // remove unnecessary chain of t(t())
            HopRewriteUtils.replaceChildReference(parent, hi, hi3, pos);
            HopRewriteUtils.cleanupUnreferenced(hi, hi2);
            hi = hi3;
            LOG.debug("Applied removeUnecessaryReorgOperation.");
        }
    }
    return hi;
}
Also used : ReOrgOp(org.apache.sysml.hops.Hop.ReOrgOp) ReorgOp(org.apache.sysml.hops.ReorgOp) Hop(org.apache.sysml.hops.Hop)

Aggregations

Hop (org.apache.sysml.hops.Hop)2 ReOrgOp (org.apache.sysml.hops.Hop.ReOrgOp)2 ReorgOp (org.apache.sysml.hops.ReorgOp)2