org.apache.sysds.hops.rewrite

## Class RewriteElementwiseMultChainOptimization

- java.lang.Object
- - org.apache.sysds.hops.rewrite.HopRewriteRule
  - - org.apache.sysds.hops.rewrite.RewriteElementwiseMultChainOptimization

-     public class RewriteElementwiseMultChainOptimization
      extends HopRewriteRule

  Prerequisite: RewriteCommonSubexpressionElimination must run before this rule. Rewrite a chain of element-wise multiply hops that contain identical elements. For example `(B * A) * B` is rewritten to `A * (B^2)` (or `(B^2) * A`), where `^` is element-wise power. The order of the multiplicands depends on their data types, dimensions (matrix or vector), and sparsity. Does not rewrite in the presence of foreign parents in the middle of the e-wise multiply chain, since foreign parents may rely on the individual results. Does not perform rewrites on an element-wise multiply if its dimensions are unknown. The new order of element-wise multiply chains is as follows:

           (((unknown * object * frame) * ([least-nnz-matrix * matrix] * most-nnz-matrix))
            * ([least-nnz-row-vector * row-vector] * most-nnz-row-vector))
           * ([[scalars * least-nnz-col-vector] * col-vector] * most-nnz-col-vector)

  Identical elements are replaced with powers.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RewriteElementwiseMultChainOptimization()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Hop` | `rewriteHopDAG(Hop root, ProgramRewriteStatus state)` Handle a predicate hop DAG with exactly one root.
    `ArrayList<Hop>` | `rewriteHopDAGs(ArrayList<Hop> roots, ProgramRewriteStatus state)` Handle a generic (last-level) hop DAG with multiple roots.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RewriteElementwiseMultChainOptimization

          public RewriteElementwiseMultChainOptimization()

  - ### Method Detail

    - #### rewriteHopDAGs

          public ArrayList<Hop> rewriteHopDAGs(ArrayList<Hop> roots,
                                               ProgramRewriteStatus state)

      Description copied from class: `HopRewriteRule`
      Handle a generic (last-level) hop DAG with multiple roots.
      Specified by:
        `rewriteHopDAGs` in class `HopRewriteRule`
      Parameters:
        `roots` - high-level operator roots
        `state` - program rewrite status
      Returns:
        list of high-level operators

    - #### rewriteHopDAG

          public Hop rewriteHopDAG(Hop root,
                                   ProgramRewriteStatus state)

      Description copied from class: `HopRewriteRule`
      Handle a predicate hop DAG with exactly one root.
      Specified by:
        `rewriteHopDAG` in class `HopRewriteRule`
      Parameters:
        `root` - high-level operator root
        `state` - program rewrite status
      Returns:
        high-level operator

Copyright © 2020 The Apache Software Foundation. All rights reserved.