Class HopRewriteUtils


  • public class HopRewriteUtils
    extends Object
    • Constructor Detail

      • HopRewriteUtils

        public HopRewriteUtils()
    • Method Detail

      • isValueTypeCast

        public static boolean isValueTypeCast​(Types.OpOp1 op)
      • getBooleanValue

        public static boolean getBooleanValue​(LiteralOp op)
      • getBooleanValueSafe

        public static boolean getBooleanValueSafe​(LiteralOp op)
      • getDoubleValue

        public static double getDoubleValue​(LiteralOp op)
      • getDoubleValueSafe

        public static double getDoubleValueSafe​(LiteralOp op)
      • getIntValue

        public static long getIntValue​(LiteralOp op)
        Return the int value of a LiteralOp (as a long). Note: For comparisons, this is *only* to be used in situations in which the value is absolutely guaranteed to be an integer. Otherwise, a safer alternative is `getDoubleValue`.
        Parameters:
        op - literal operator
        Returns:
        long value of literal op
      • getIntValueSafe

        public static long getIntValueSafe​(Hop op)
      • getIntValueSafe

        public static long getIntValueSafe​(LiteralOp op)
      • isLiteralOfValue

        public static boolean isLiteralOfValue​(Hop hop,
                                               Double... val)
      • isLiteralOfValue

        public static boolean isLiteralOfValue​(Hop hop,
                                               double val)
      • isLiteralOfValue

        public static boolean isLiteralOfValue​(Hop hop,
                                               String val)
      • isLiteralOfValue

        public static boolean isLiteralOfValue​(Hop hop,
                                               boolean val)
      • getChildReferencePos

        public static int getChildReferencePos​(Hop parent,
                                               Hop child)
      • removeChildReference

        public static void removeChildReference​(Hop parent,
                                                Hop child)
      • removeChildReferenceByPos

        public static void removeChildReferenceByPos​(Hop parent,
                                                     Hop child,
                                                     int posChild)
      • removeAllChildReferences

        public static void removeAllChildReferences​(Hop parent)
      • addChildReference

        public static void addChildReference​(Hop parent,
                                             Hop child)
      • addChildReference

        public static void addChildReference​(Hop parent,
                                             Hop child,
                                             int pos)
      • rewireAllParentChildReferences

        public static Hop rewireAllParentChildReferences​(Hop hold,
                                                         Hop hnew)
        Replace an old Hop with a replacement Hop. If the old Hop has no parents, then return the replacement. Otherwise rewire each of the Hop's parents into the replacement and return the replacement.
        Parameters:
        hold - To be replaced
        hnew - The replacement
        Returns:
        hnew
      • replaceChildReference

        public static void replaceChildReference​(Hop parent,
                                                 Hop inOld,
                                                 Hop inNew)
      • replaceChildReference

        public static void replaceChildReference​(Hop parent,
                                                 Hop inOld,
                                                 Hop inNew,
                                                 int pos)
      • replaceChildReference

        public static void replaceChildReference​(Hop parent,
                                                 Hop inOld,
                                                 Hop inNew,
                                                 int pos,
                                                 boolean refresh)
      • cleanupUnreferenced

        public static void cleanupUnreferenced​(Hop... inputs)
      • getOtherInput

        public static Hop getOtherInput​(Hop hop,
                                        Hop input)
      • getLargestInput

        public static Hop getLargestInput​(Hop hop)
      • createDataGenOp

        public static Hop createDataGenOp​(Hop input,
                                          double value)
      • copyDataGenOp

        public static DataGenOp copyDataGenOp​(DataGenOp inputGen,
                                              double scale,
                                              double shift)
        Assumes that min and max are literal ops, needs to be checked from outside.
        Parameters:
        inputGen - input data gen op
        scale - the scale
        shift - the shift
        Returns:
        data gen op
      • createDataGenOp

        public static Hop createDataGenOp​(Hop rowInput,
                                          Hop colInput,
                                          double value)
      • createDataGenOp

        public static Hop createDataGenOp​(Hop rowInput,
                                          boolean tRowInput,
                                          Hop colInput,
                                          boolean tColInput,
                                          double value)
      • createDataGenOpByVal

        public static Hop createDataGenOpByVal​(ArrayList<LiteralOp> values,
                                               long rows,
                                               long cols)
      • isDataGenOp

        public static boolean isDataGenOp​(Hop hop,
                                          Types.OpOpDG... ops)
      • isDataGenOpWithLiteralInputs

        public static boolean isDataGenOpWithLiteralInputs​(Hop hop,
                                                           Types.OpOpDG... ops)
      • isDataGenOpWithConstantValue

        public static boolean isDataGenOpWithConstantValue​(Hop hop)
      • isDataGenOpWithConstantValue

        public static boolean isDataGenOpWithConstantValue​(Hop hop,
                                                           double value)
      • isDataGenOpWithNonDeterminism

        public static boolean isDataGenOpWithNonDeterminism​(Hop hop)
      • getDataGenOpConstantValue

        public static Hop getDataGenOpConstantValue​(Hop hop)
      • createTransientRead

        public static DataOp createTransientRead​(String name,
                                                 Hop h)
      • createTransientWrite

        public static DataOp createTransientWrite​(String name,
                                                  Hop in)
      • createTranspose

        public static ReorgOp createTranspose​(Hop input)
      • createBinaryMinus

        public static BinaryOp createBinaryMinus​(Hop input)
      • createTsmm

        public static AggBinaryOp createTsmm​(Hop input,
                                             boolean left)
      • createMatrixMultiply

        public static AggBinaryOp createMatrixMultiply​(Hop left,
                                                       Hop right)
      • createScalarIndexing

        public static Hop createScalarIndexing​(Hop input,
                                               long rix,
                                               long cix)
      • createIndexingOp

        public static IndexingOp createIndexingOp​(Hop input,
                                                  Hop batchsize)
      • createIndexingOp

        public static IndexingOp createIndexingOp​(Hop input,
                                                  long rix,
                                                  long cix)
      • createIndexingOp

        public static IndexingOp createIndexingOp​(Hop input,
                                                  long rl,
                                                  long ru,
                                                  long cl,
                                                  long cu)
      • createValueHop

        public static Hop createValueHop​(Hop hop,
                                         boolean row)
      • createSeqDataGenOp

        public static DataGenOp createSeqDataGenOp​(Hop input)
      • createSeqDataGenOp

        public static DataGenOp createSeqDataGenOp​(Hop input,
                                                   boolean asc)
      • createSeqDataGenOp

        public static DataGenOp createSeqDataGenOp​(Hop proxy,
                                                   Hop from,
                                                   Hop to,
                                                   Hop incr)
      • createComputeNnz

        public static Hop createComputeNnz​(Hop input)
      • setOutputParameters

        public static void setOutputParameters​(Hop hop,
                                               long rlen,
                                               long clen,
                                               int blen,
                                               long nnz)
      • setOutputParametersForScalar

        public static void setOutputParametersForScalar​(Hop hop)
      • refreshOutputParameters

        public static void refreshOutputParameters​(Hop hnew,
                                                   Hop hold)
      • copyLineNumbers

        public static void copyLineNumbers​(Hop src,
                                           Hop dest)
      • copyLineNumbers

        public static void copyLineNumbers​(MatrixBlock mb,
                                           Hop tread)
      • copyLineNumbers

        public static void copyLineNumbers​(MatrixObject mo,
                                           Hop tread)
      • updateHopCharacteristics

        public static void updateHopCharacteristics​(Hop hop,
                                                    int blen,
                                                    Hop src)
      • updateHopCharacteristics

        public static void updateHopCharacteristics​(Hop hop,
                                                    int blen,
                                                    MemoTable memo,
                                                    Hop src)
      • isDimsKnown

        public static boolean isDimsKnown​(Hop hop)
      • isEmpty

        public static boolean isEmpty​(Hop hop)
      • isEqualMatrixSize

        public static boolean isEqualMatrixSize​(BinaryOp hop)
      • isEqualSize

        public static boolean isEqualSize​(Hop hop1,
                                          Hop hop2)
      • isEqualSize

        public static boolean isEqualSize​(Hop hop1,
                                          Hop... hops)
      • isSingleBlock

        public static boolean isSingleBlock​(Hop hop)
      • isSingleBlock

        public static boolean isSingleBlock​(Hop hop,
                                            boolean cols)
        Checks our BLOCKSIZE CONSTRAINT, w/ awareness of forced single node execution mode.
        Parameters:
        hop - high-level operator
        cols - true if cols
        Returns:
        true if single block
      • isOuterProductLikeMM

        public static boolean isOuterProductLikeMM​(Hop hop)
      • isOuterBinary

        public static boolean isOuterBinary​(Hop hop)
      • isValidOuterBinaryOp

        public static boolean isValidOuterBinaryOp​(Types.OpOp2 op)
      • isSparse

        public static boolean isSparse​(Hop hop)
      • isDense

        public static boolean isDense​(Hop hop)
      • isSparse

        public static boolean isSparse​(Hop hop,
                                       double threshold)
      • isEqualValue

        public static boolean isEqualValue​(Hop hop1,
                                           Hop hop2)
      • isNotMatrixVectorBinaryOperation

        public static boolean isNotMatrixVectorBinaryOperation​(Hop hop)
      • isTransposeOperation

        public static boolean isTransposeOperation​(Hop hop)
      • isTransposeOperation

        public static boolean isTransposeOperation​(Hop hop,
                                                   int maxParents)
      • containsTransposeOperation

        public static boolean containsTransposeOperation​(ArrayList<Hop> hops)
      • isTransposeOfItself

        public static boolean isTransposeOfItself​(Hop hop1,
                                                  Hop hop2)
      • isTsmm

        public static boolean isTsmm​(Hop input)
      • isTsmmInput

        public static boolean isTsmmInput​(Hop input)
      • isBinary

        public static boolean isBinary​(Hop hop,
                                       Types.OpOp2 type)
      • isBinary

        public static boolean isBinary​(Hop hop,
                                       Types.OpOp2... types)
      • isBinary

        public static boolean isBinary​(Hop hop,
                                       Types.OpOp2 type,
                                       int maxParents)
      • isBinaryPPred

        public static boolean isBinaryPPred​(Hop hop)
      • isBinarySparseSafe

        public static boolean isBinarySparseSafe​(Hop hop)
      • isBinaryMatrixScalarOperation

        public static boolean isBinaryMatrixScalarOperation​(Hop hop)
      • isBinaryMatrixMatrixOperation

        public static boolean isBinaryMatrixMatrixOperation​(Hop hop)
      • isBinaryMatrixMatrixOperationWithSharedInput

        public static boolean isBinaryMatrixMatrixOperationWithSharedInput​(Hop hop)
      • isBinaryMatrixScalar

        public static boolean isBinaryMatrixScalar​(Hop hop,
                                                   Types.OpOp2 type,
                                                   double val)
      • isTernary

        public static boolean isTernary​(Hop hop,
                                        Types.OpOp3 type)
      • isTernary

        public static boolean isTernary​(Hop hop,
                                        Types.OpOp3... types)
      • containsInput

        public static boolean containsInput​(Hop current,
                                            Hop probe)
      • isBinaryMatrixColVectorOperation

        public static boolean isBinaryMatrixColVectorOperation​(Hop hop)
      • isBinaryMatrixRowVectorOperation

        public static boolean isBinaryMatrixRowVectorOperation​(Hop hop)
      • isUnary

        public static boolean isUnary​(Hop hop,
                                      Types.OpOp1 type)
      • isUnary

        public static boolean isUnary​(Hop hop,
                                      Types.OpOp1 type,
                                      int maxParents)
      • isUnary

        public static boolean isUnary​(Hop hop,
                                      Types.OpOp1... types)
      • isTerminalHop

        public static boolean isTerminalHop​(Hop hop)
        Check if given hop is of a terminal type. Terminal hops are either of type print or write.
        Parameters:
        hop - for which the type is checked
        Returns:
        true if hop is terminal
      • isMatrixMultiply

        public static boolean isMatrixMultiply​(Hop hop)
      • isAggUnaryOp

        public static boolean isAggUnaryOp​(Hop hop,
                                           Types.AggOp... op)
      • isSum

        public static boolean isSum​(Hop hop)
      • isSumSq

        public static boolean isSumSq​(Hop hop)
      • isRemoveEmpty

        public static boolean isRemoveEmpty​(Hop hop,
                                            boolean rows)
      • isRemoveEmpty

        public static boolean isRemoveEmpty​(Hop hop)
      • isNary

        public static boolean isNary​(Hop hop,
                                     Types.OpOpN type)
      • isNary

        public static boolean isNary​(Hop hop,
                                     Types.OpOpN... types)
      • isNonZeroIndicator

        public static boolean isNonZeroIndicator​(Hop pred,
                                                 Hop hop)
      • checkInputDataTypes

        public static boolean checkInputDataTypes​(Hop hop,
                                                  Types.DataType... dt)
      • checkAvgRowsGteCols

        public static boolean checkAvgRowsGteCols​(List<Hop> list)
      • checkConsistentRows

        public static boolean checkConsistentRows​(List<Hop> list1,
                                                  List<Hop> list2)
      • isColumnRightIndexing

        public static boolean isColumnRightIndexing​(Hop hop)
      • isFullColumnIndexing

        public static boolean isFullColumnIndexing​(LeftIndexingOp hop)
      • isFullColumnIndexing

        public static boolean isFullColumnIndexing​(IndexingOp hop)
      • isFullRowIndexing

        public static boolean isFullRowIndexing​(LeftIndexingOp hop)
      • isFullRowIndexing

        public static boolean isFullRowIndexing​(IndexingOp hop)
      • isColumnRangeIndexing

        public static boolean isColumnRangeIndexing​(IndexingOp hop)
      • isConsecutiveIndex

        public static boolean isConsecutiveIndex​(Hop index,
                                                 Hop index2)
      • isUnnecessaryRightIndexing

        public static boolean isUnnecessaryRightIndexing​(Hop hop)
      • isScalarMatrixBinaryMult

        public static boolean isScalarMatrixBinaryMult​(Hop hop)
      • isBasic1NSequence

        public static boolean isBasic1NSequence​(Hop hop)
      • isBasic1NSequence

        public static boolean isBasic1NSequence​(Hop seq,
                                                Hop input,
                                                boolean row)
      • isBasicN1Sequence

        public static boolean isBasicN1Sequence​(Hop hop)
      • getBasic1NSequenceMax

        public static Hop getBasic1NSequenceMax​(Hop hop)
      • isSizeExpressionOf

        public static boolean isSizeExpressionOf​(Hop size,
                                                 Hop input,
                                                 boolean row)
      • hasOnlyWriteParents

        public static boolean hasOnlyWriteParents​(Hop hop,
                                                  boolean inclTransient,
                                                  boolean inclPersistent)
      • hasOnlyUnaryBinaryParents

        public static boolean hasOnlyUnaryBinaryParents​(Hop hop,
                                                        boolean disallowLhs)
      • alwaysRequiresReblock

        public static boolean alwaysRequiresReblock​(Hop hop)
      • containsOp

        public static boolean containsOp​(ArrayList<Hop> candidates,
                                         Class<? extends Hop> clazz)
      • rHasSimpleReadChain

        public static boolean rHasSimpleReadChain​(Hop root,
                                                  String var)
      • rContainsRead

        public static boolean rContainsRead​(Hop root,
                                            String var,
                                            boolean includeMetaOp)
      • createPartialTsmmCbind

        public static Hop createPartialTsmmCbind​(Hop X,
                                                 Hop deltaX,
                                                 Hop tsmmIn1)
      • compareSize

        public static int compareSize​(Hop hop1,
                                      Hop hop2)
        Compares the size of outputs from hop1 and hop2, in terms of number of matrix cells.
        Parameters:
        hop1 - high-level operator 1
        hop2 - high-level operator 2
        Returns:
        0 if sizes are equal, <0 for hop1<hop2, >0 for hop1>hop2.
      • isLastLevelStatementBlock

        public static boolean isLastLevelStatementBlock​(StatementBlock sb)
      • isLoopStatementBlock

        public static boolean isLoopStatementBlock​(StatementBlock sb)
      • getMaxNrowInput

        public static long getMaxNrowInput​(Hop hop)
      • getMaxNcolInput

        public static long getMaxNcolInput​(Hop hop)
      • getMaxInputDim

        public static long getMaxInputDim​(Hop hop,
                                          boolean dim1)
      • getSumValidInputDims

        public static long getSumValidInputDims​(Hop hop,
                                                boolean dim1)
      • hasValidInputDims

        public static boolean hasValidInputDims​(Hop hop,
                                                boolean dim1)
      • getSumValidInputNnz

        public static long getSumValidInputNnz​(Hop hop)
      • hasValidInputNnz

        public static boolean hasValidInputNnz​(Hop hop)
      • getMaxInputDim

        public static long getMaxInputDim​(DataCharacteristics[] dc,
                                          boolean dim1)
      • getSumValidInputDims

        public static long getSumValidInputDims​(DataCharacteristics[] mc,
                                                boolean dim1)
      • hasValidInputDims

        public static boolean hasValidInputDims​(DataCharacteristics[] mc,
                                                boolean dim1)
      • getSumValidInputNnz

        public static long getSumValidInputNnz​(DataCharacteristics[] mc,
                                               boolean worstcase)
      • hasValidInputNnz

        public static boolean hasValidInputNnz​(DataCharacteristics[] mc,
                                               boolean worstcase)
      • hasListInputs

        public static boolean hasListInputs​(Hop hop)
      • containsSecondOrderBuiltin

        public static boolean containsSecondOrderBuiltin​(ArrayList<Hop> roots)
      • knownParamservFunctions

        public static boolean knownParamservFunctions​(Hop hop)
      • knownParamservFunctions

        public static boolean knownParamservFunctions​(Hop hop,
                                                      DMLProgram prog)
      • setUnoptimizedFunctionCalls

        public static void setUnoptimizedFunctionCalls​(StatementBlock sb)