org.apache.sysds.hops.rewrite

## Class RewriteRemoveUnnecessaryCasts

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

    public class RewriteRemoveUnnecessaryCasts
    extends HopRewriteRule

Rule: RemoveUnnecessaryCasts. For all value type casts check if they are really necessary. If both cast input and output type are the same, the cast itself is redundant. There are two use case where this can arise: (1) automatically inserted casts on function inlining (in case of unknown value types), and (2) explicit script-level value type casts, that might be redundant according to the read input data. The benefit of this rewrite is negligible for scalars. However, when we support matrices with different value types, those casts might refer to matrices and with that incur large costs.

### Constructor Summary

Constructors
Constructor and Description
`RewriteRemoveUnnecessaryCasts()`

### Method Summary

All Methods Instance Methods Concrete Methods
`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

#### RewriteRemoveUnnecessaryCasts

    public RewriteRemoveUnnecessaryCasts()

### 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