Class ADictionary

    • Constructor Detail

      • ADictionary

        public ADictionary()
    • Method Detail

      • clone

        public abstract IDictionary clone()
        Description copied from interface: IDictionary
        Returns a deep clone of the dictionary.
        Specified by:
        clone in interface IDictionary
        Returns:
        A deep clone
      • centralMoment

        public final CM_COV_Object centralMoment​(ValueFunction fn,
                                                 int[] counts,
                                                 int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group. MUST be on a single column dictionary.
        Specified by:
        centralMoment in interface IDictionary
        Parameters:
        fn - The value function to apply
        counts - The weight of individual tuples
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • centralMomentWithDefault

        public final CM_COV_Object centralMomentWithDefault​(ValueFunction fn,
                                                            int[] counts,
                                                            double def,
                                                            int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group with a default offset on all missing tuples. MUST be on a single column dictionary.
        Specified by:
        centralMomentWithDefault in interface IDictionary
        Parameters:
        fn - The value function to apply
        counts - The weight of individual tuples
        def - The default values to offset the tuples with
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • centralMomentWithReference

        public final CM_COV_Object centralMomentWithReference​(ValueFunction fn,
                                                              int[] counts,
                                                              double reference,
                                                              int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group with a reference offset on each tuple. MUST be on a single column dictionary.
        Specified by:
        centralMomentWithReference in interface IDictionary
        Parameters:
        fn - The value function to apply
        counts - The weight of individual tuples
        reference - The reference values to offset the tuples with
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • equals

        public final boolean equals​(double[] v)
        Description copied from interface: IDictionary
        Indicate if this object is equal to the given array of doubles.
        Specified by:
        equals in interface IDictionary
        Parameters:
        v - The list of double values
        Returns:
        If they are equal to this.
      • correctNan

        public static void correctNan​(double[] res,
                                      IColIndex colIndexes)
        Correct Nan Values in an result. If there are any NaN values in the given Res then they are replaced with 0.
        Parameters:
        res - The array to correct
        colIndexes - The column indexes.
      • rightMMPreAggSparse

        public IDictionary rightMMPreAggSparse​(int numVals,
                                               SparseBlock b,
                                               IColIndex thisCols,
                                               IColIndex aggregateColumns,
                                               int nColRight)
        Description copied from interface: IDictionary
        Pre-aggregate the given sparse block for right multiplication. The returned dictionary is the new column groups dictionary.
        Specified by:
        rightMMPreAggSparse in interface IDictionary
        Parameters:
        numVals - The number of values in this dictionary and in the output dictionary.
        b - The sparse block to pre aggregate, note this contains the entire right side matrix, not a reduced or sliced version.
        thisCols - The column indexes of this dictionary, these correspond to the rows to extract from the right side matrix
        aggregateColumns - The reduced column indexes of the right side, these are the number of columns in the output dictionary, and the columns to multiply this dictionary with.
        nColRight - The number of columns in the b sparse matrix.
        Returns:
        The pre-aggregate dictionary that can be used as the output dictionary for the right matrix multiplication
      • putSparse

        public void putSparse​(SparseBlock sb,
                              int idx,
                              int rowOut,
                              int nCol,
                              IColIndex columns)
        Description copied from interface: IDictionary
        Put the row specified into the sparse block, via append calls.
        Specified by:
        putSparse in interface IDictionary
        Parameters:
        sb - The sparse block to put into
        idx - The dictionary index to put in.
        rowOut - The row in the sparse block to put it into
        nCol - The number of columns in the dictionary
        columns - The columns to output into.
      • putDense

        public void putDense​(DenseBlock dr,
                             int idx,
                             int rowOut,
                             int nCol,
                             IColIndex columns)
        Description copied from interface: IDictionary
        Put the row specified into the sparse block, via append calls.
        Specified by:
        putDense in interface IDictionary
        Parameters:
        dr - The dense block to put into
        idx - The dictionary index to put in.
        rowOut - The row in the sparse block to put it into
        nCol - The number of columns in the dictionary
        columns - The columns to output into.
      • getRow

        public double[] getRow​(int i,
                               int nCol)
        Description copied from interface: IDictionary
        Extract the values on a given row as a dense double array.
        Specified by:
        getRow in interface IDictionary
        Parameters:
        i - The row index to extract
        nCol - The number of columns in this column group
        Returns:
        The row extracted
      • product

        public void product​(double[] ret,
                            int[] counts,
                            int nCol)
        Description copied from interface: IDictionary
        Calculate the product of the dictionary weighted by counts.
        Specified by:
        product in interface IDictionary
        Parameters:
        ret - The result dense double array (containing one value)
        counts - The count of individual tuples
        nCol - Number of columns in the dictionary.
      • productWithDefault

        public void productWithDefault​(double[] ret,
                                       int[] counts,
                                       double[] def,
                                       int defCount)
        Description copied from interface: IDictionary
        Calculate the product of the dictionary weighted by counts with a default value added .
        Specified by:
        productWithDefault in interface IDictionary
        Parameters:
        ret - The result dense double array (containing one value)
        counts - The count of individual tuples
        def - The default tuple
        defCount - The count of the default tuple
      • productWithReference

        public void productWithReference​(double[] ret,
                                         int[] counts,
                                         double[] reference,
                                         int refCount)
        Description copied from interface: IDictionary
        Calculate the product of the dictionary weighted by counts and offset by reference
        Specified by:
        productWithReference in interface IDictionary
        Parameters:
        ret - The result dense double array (containing one value)
        counts - The counts of each entry in the dictionary
        reference - The reference value.
        refCount - The number of occurrences of the ref value.
      • centralMoment

        public CM_COV_Object centralMoment​(CM_COV_Object ret,
                                           ValueFunction fn,
                                           int[] counts,
                                           int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group. MUST be on a single column dictionary.
        Specified by:
        centralMoment in interface IDictionary
        Parameters:
        ret - The Central Moment object to be modified and returned
        fn - The value function to apply
        counts - The weight of individual tuples
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • getSparsity

        public double getSparsity()
        Description copied from interface: IDictionary
        Get the sparsity of the dictionary.
        Specified by:
        getSparsity in interface IDictionary
        Returns:
        a sparsity between 0 and 1
      • centralMomentWithDefault

        public CM_COV_Object centralMomentWithDefault​(CM_COV_Object ret,
                                                      ValueFunction fn,
                                                      int[] counts,
                                                      double def,
                                                      int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group with a default offset on all missing tuples. MUST be on a single column dictionary.
        Specified by:
        centralMomentWithDefault in interface IDictionary
        Parameters:
        ret - The Central Moment object to be modified and returned
        fn - The value function to apply
        counts - The weight of individual tuples
        def - The default values to offset the tuples with
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • centralMomentWithReference

        public CM_COV_Object centralMomentWithReference​(CM_COV_Object ret,
                                                        ValueFunction fn,
                                                        int[] counts,
                                                        double reference,
                                                        int nRows)
        Description copied from interface: IDictionary
        Central moment function to calculate the central moment of this column group with a reference offset on each tuple. MUST be on a single column dictionary.
        Specified by:
        centralMomentWithReference in interface IDictionary
        Parameters:
        ret - The Central Moment object to be modified and returned
        fn - The value function to apply
        counts - The weight of individual tuples
        reference - The reference values to offset the tuples with
        nRows - The number of rows in total of the column group
        Returns:
        The central moment Object
      • rexpandCols

        public IDictionary rexpandCols​(int max,
                                       boolean ignore,
                                       boolean cast,
                                       int nCol)
        Description copied from interface: IDictionary
        Rexpand the dictionary (one hot encode)
        Specified by:
        rexpandCols in interface IDictionary
        Parameters:
        max - the tuple width of the output
        ignore - If we should ignore zero and negative values
        cast - If we should cast all double values to whole integer values
        nCol - The number of columns in the dictionary already (should be 1)
        Returns:
        A new dictionary
      • rexpandColsWithReference

        public IDictionary rexpandColsWithReference​(int max,
                                                    boolean ignore,
                                                    boolean cast,
                                                    int reference)
        Description copied from interface: IDictionary
        Rexpand the dictionary (one hot encode)
        Specified by:
        rexpandColsWithReference in interface IDictionary
        Parameters:
        max - the tuple width of the output
        ignore - If we should ignore zero and negative values
        cast - If we should cast all double values to whole integer values
        reference - A reference value to add to all tuples before expanding
        Returns:
        A new dictionary
      • TSMMWithScaling

        public void TSMMWithScaling​(int[] counts,
                                    IColIndex rows,
                                    IColIndex cols,
                                    MatrixBlock ret)
        Description copied from interface: IDictionary
        Transpose self matrix multiplication with a scaling factor on each pair of values.
        Specified by:
        TSMMWithScaling in interface IDictionary
        Parameters:
        counts - The scaling factor
        rows - The row indexes
        cols - The col indexes
        ret - The output matrix block
      • MMDict

        public void MMDict​(IDictionary right,
                           IColIndex rowsLeft,
                           IColIndex colsRight,
                           MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries note the left is this, and it is supposed to be treated as if it is transposed while it is not physically transposed.
        Specified by:
        MMDict in interface IDictionary
        Parameters:
        right - Right hand side of multiplication
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • MMDictScaling

        public void MMDictScaling​(IDictionary right,
                                  IColIndex rowsLeft,
                                  IColIndex colsRight,
                                  MatrixBlock result,
                                  int[] scaling)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries, note the left is this, and it is supposed to be treated as if it is transposed while it is not physically transposed.
        Specified by:
        MMDictScaling in interface IDictionary
        Parameters:
        right - Right hand side of multiplication (not transposed)
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
        scaling - The scaling
      • MMDictSparse

        public void MMDictSparse​(SparseBlock left,
                                 IColIndex rowsLeft,
                                 IColIndex colsRight,
                                 MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries left side sparse and transposed right side is this.
        Specified by:
        MMDictSparse in interface IDictionary
        Parameters:
        left - Sparse left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • MMDictScalingSparse

        public void MMDictScalingSparse​(SparseBlock left,
                                        IColIndex rowsLeft,
                                        IColIndex colsRight,
                                        MatrixBlock result,
                                        int[] scaling)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries left side sparse and transposed right side is this.
        Specified by:
        MMDictScalingSparse in interface IDictionary
        Parameters:
        left - Sparse left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
        scaling - The scaling
      • TSMMToUpperTriangle

        public void TSMMToUpperTriangle​(IDictionary right,
                                        IColIndex rowsLeft,
                                        IColIndex colsRight,
                                        MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is left
        Specified by:
        TSMMToUpperTriangle in interface IDictionary
        Parameters:
        right - Right side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • TSMMToUpperTriangleDense

        public void TSMMToUpperTriangleDense​(double[] left,
                                             IColIndex rowsLeft,
                                             IColIndex colsRight,
                                             MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is right
        Specified by:
        TSMMToUpperTriangleDense in interface IDictionary
        Parameters:
        left - Dense left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • TSMMToUpperTriangleSparse

        public void TSMMToUpperTriangleSparse​(SparseBlock left,
                                              IColIndex rowsLeft,
                                              IColIndex colsRight,
                                              MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is right
        Specified by:
        TSMMToUpperTriangleSparse in interface IDictionary
        Parameters:
        left - Sparse left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • TSMMToUpperTriangleScaling

        public void TSMMToUpperTriangleScaling​(IDictionary right,
                                               IColIndex rowsLeft,
                                               IColIndex colsRight,
                                               int[] scale,
                                               MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is left
        Specified by:
        TSMMToUpperTriangleScaling in interface IDictionary
        Parameters:
        right - Right side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        scale - Scale factor
        result - The output matrix block
      • TSMMToUpperTriangleDenseScaling

        public void TSMMToUpperTriangleDenseScaling​(double[] left,
                                                    IColIndex rowsLeft,
                                                    IColIndex colsRight,
                                                    int[] scale,
                                                    MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is right
        Specified by:
        TSMMToUpperTriangleDenseScaling in interface IDictionary
        Parameters:
        left - Dense left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        scale - Scale factor
        result - The output matrix block
      • TSMMToUpperTriangleSparseScaling

        public void TSMMToUpperTriangleSparseScaling​(SparseBlock left,
                                                     IColIndex rowsLeft,
                                                     IColIndex colsRight,
                                                     int[] scale,
                                                     MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication but allocate output in upper triangle and twice if on diagonal, note this is right
        Specified by:
        TSMMToUpperTriangleSparseScaling in interface IDictionary
        Parameters:
        left - Sparse left side
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        scale - Scale factor
        result - The output matrix block
      • reorder

        public IDictionary reorder​(int[] reorder)
        Description copied from interface: IDictionary
        Reorder the elements in the dictionary based on the reorder specification given.
        Specified by:
        reorder in interface IDictionary
        Parameters:
        reorder - The order to move to.
        Returns:
        A new Dictionary that is reordered.s
      • cbind

        public IDictionary cbind​(IDictionary that,
                                 int nCol)
        Description copied from interface: IDictionary
        Cbind this dictionary with that dictionary
        Specified by:
        cbind in interface IDictionary
        Parameters:
        that - the right hand side dictionary to cbind
        nCol - the right hand side number of columns
        Returns:
        The combined dictionary
      • append

        public IDictionary append​(double[] row)
        Description copied from interface: IDictionary
        Return a new dictionary with the given row appended. If possible reuse as much of the old dictionary as possible.
        Specified by:
        append in interface IDictionary
        Parameters:
        row - The new row to append.
        Returns:
        A new dictionary with the appended row
      • replace

        public IDictionary replace​(double pattern,
                                   double replace,
                                   int nCol)
        Description copied from interface: IDictionary
        Make a copy of the values, and replace all values that match pattern with replacement value. If needed add a new column index.
        Specified by:
        replace in interface IDictionary
        Parameters:
        pattern - The value to look for
        replace - The value to replace the other value with
        nCol - The number of columns contained in the dictionary.
        Returns:
        A new Column Group, reusing the index structure but with new values.
      • replaceWithReference

        public IDictionary replaceWithReference​(double pattern,
                                                double replace,
                                                double[] reference)
        Description copied from interface: IDictionary
        Make a copy of the values, and replace all values that match pattern with replacement value. If needed add a new column index. With reference such that each value in the dict is considered offset by the values contained in the reference.
        Specified by:
        replaceWithReference in interface IDictionary
        Parameters:
        pattern - The value to look for
        replace - The value to replace the other value with
        reference - The reference tuple to add to all entries when replacing
        Returns:
        A new Column Group, reusing the index structure but with new values.
      • subtractTuple

        public IDictionary subtractTuple​(double[] tuple)
        Description copied from interface: IDictionary
        Allocate a new dictionary where the tuple given is subtracted from all tuples in the previous dictionary.
        Specified by:
        subtractTuple in interface IDictionary
        Parameters:
        tuple - a double list representing a tuple, it is given that the tuple with is the same as this dictionaries.
        Returns:
        a new instance of dictionary with the tuple subtracted.
      • getNumberNonZerosWithReference

        public long getNumberNonZerosWithReference​(int[] counts,
                                                   double[] reference,
                                                   int nRows)
        Description copied from interface: IDictionary
        Calculate the number of non zeros in the dictionary. Each value in the dictionary should be added to the reference value. The number of non zeros should be scaled with the given counts.
        Specified by:
        getNumberNonZerosWithReference in interface IDictionary
        Parameters:
        counts - The Counts of each dict entry.
        reference - The reference vector.
        nRows - The number of rows in the input.
        Returns:
        The NonZero Count.
      • containsValueWithReference

        public boolean containsValueWithReference​(double pattern,
                                                  double[] reference)
        Description copied from interface: IDictionary
        Detect if the dictionary contains a specific value with reference offset.
        Specified by:
        containsValueWithReference in interface IDictionary
        Parameters:
        pattern - The pattern/ value to search for
        reference - The reference double array.
        Returns:
        true if the value is contained else false.
      • sumSqWithReference

        public double sumSqWithReference​(int[] counts,
                                         double[] reference)
        Description copied from interface: IDictionary
        Get the square sum of the values contained in the dictionary with a reference offset on each value.
        Specified by:
        sumSqWithReference in interface IDictionary
        Parameters:
        counts - The counts of the individual tuples
        reference - The reference value
        Returns:
        The square sum scaled by the counts and reference.
      • colProductWithReference

        public void colProductWithReference​(double[] res,
                                            int[] counts,
                                            IColIndex colIndexes,
                                            double[] reference)
        Description copied from interface: IDictionary
        Calculate the column product of the dictionary weighted by counts.
        Specified by:
        colProductWithReference in interface IDictionary
        Parameters:
        res - The result vector to put the result into
        counts - The weighted count of individual tuples
        colIndexes - The column indexes.
        reference - The reference value.
      • colSumSqWithReference

        public void colSumSqWithReference​(double[] c,
                                          int[] counts,
                                          IColIndex colIndexes,
                                          double[] reference)
        Description copied from interface: IDictionary
        Get the column sum of the values contained in the dictionary with an offset reference value added to each cell.
        Specified by:
        colSumSqWithReference in interface IDictionary
        Parameters:
        c - The output array allocated to contain all column groups output.
        counts - The counts of the individual tuples.
        colIndexes - The columns indexes of the parent column group, this indicate where to put the column sum into the c output.
        reference - The reference values to add to each cell.
      • multiplyScalar

        public void multiplyScalar​(double v,
                                   double[] ret,
                                   int off,
                                   int dictIdx,
                                   IColIndex cols)
        Description copied from interface: IDictionary
        Multiply the v value with the dictionary entry at dictIdx and add it to the ret matrix at the columns specified in the int array.
        Specified by:
        multiplyScalar in interface IDictionary
        Parameters:
        v - Value to multiply
        ret - Output dense double array location
        off - Offset into the ret array that the "row" output starts at
        dictIdx - The dictionary entry to multiply.
        cols - The columns to multiply into of the output.
      • MMDictDense

        public void MMDictDense​(double[] left,
                                IColIndex rowsLeft,
                                IColIndex colsRight,
                                MatrixBlock result)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries left side dense and transposed. The right side is this.
        Specified by:
        MMDictDense in interface IDictionary
        Parameters:
        left - Dense left side (treat as if it is transposed but it is physically not)
        rowsLeft - Offset rows on the left
        colsRight - Offset cols on the right
        result - The output matrix block
      • productAllRowsToDoubleWithReference

        public double[] productAllRowsToDoubleWithReference​(double[] reference)
        Description copied from interface: IDictionary
        Method to product all rows to a column vector with a reference values added to all cells, and a reference product in the end
        Specified by:
        productAllRowsToDoubleWithReference in interface IDictionary
        Parameters:
        reference - The reference row
        Returns:
        A row product
      • sumAllRowsToDoubleSqWithDefault

        public double[] sumAllRowsToDoubleSqWithDefault​(double[] defaultTuple)
        Description copied from interface: IDictionary
        Method used as a pre-aggregate of each tuple in the dictionary, to single double values. But adds another cell to the return with an extra value that is the sum of the given defaultTuple.
        Specified by:
        sumAllRowsToDoubleSqWithDefault in interface IDictionary
        Parameters:
        defaultTuple - The default row to sum in the end index returned.
        Returns:
        a double array containing the row sums from this dictionary.
      • sumAllRowsToDoubleSqWithReference

        public double[] sumAllRowsToDoubleSqWithReference​(double[] reference)
        Description copied from interface: IDictionary
        Method used as a pre-aggregate of each tuple in the dictionary, to single double values.
        Specified by:
        sumAllRowsToDoubleSqWithReference in interface IDictionary
        Parameters:
        reference - The reference values to add to each cell.
        Returns:
        a double array containing the row sums from this dictionary.
      • binOpRightWithReference

        public IDictionary binOpRightWithReference​(BinaryOperator op,
                                                   double[] v,
                                                   IColIndex colIndexes,
                                                   double[] reference,
                                                   double[] newReference)
        Description copied from interface: IDictionary
        Apply the binary operator such that each value is offset by the reference before application. Then put the result into the new dictionary, but offset it by the new reference. outValues[j] = op(this.values[j] + reference[i], v[colIndexes[i]]) - newReference[i]
        Specified by:
        binOpRightWithReference in interface IDictionary
        Parameters:
        op - The operation to apply on the dictionary values.
        v - The values to use on the right side of the operator.
        colIndexes - The column indexes to use.
        reference - The reference value to add before operator.
        newReference - The reference value to subtract after operator.
        Returns:
        A new dictionary.
      • binOpRightAndAppend

        public IDictionary binOpRightAndAppend​(BinaryOperator op,
                                               double[] v,
                                               IColIndex colIndexes)
        Description copied from interface: IDictionary
        Apply binary row operation on the right side with one extra row evaluating with zeros.
        Specified by:
        binOpRightAndAppend in interface IDictionary
        Parameters:
        op - The operation to this dictionary
        v - The values to use on the right hand side.
        colIndexes - The column indexes to consider inside v.
        Returns:
        A new dictionary containing the updated values.
      • binOpRight

        public IDictionary binOpRight​(BinaryOperator op,
                                      double[] v)
        Description copied from interface: IDictionary
        Apply binary row operation on the right side as with no columns to extract from v.
        Specified by:
        binOpRight in interface IDictionary
        Parameters:
        op - The operation to this dictionary
        v - The values to apply on the dictionary (same number of cols as the dictionary)
        Returns:
        A new dictionary containing the updated values.
      • applyScalarOp

        public IDictionary applyScalarOp​(ScalarOperator op)
        Description copied from interface: IDictionary
        Allocate a new dictionary and applies the scalar operation on each cell of to then return the new dictionary.
        Specified by:
        applyScalarOp in interface IDictionary
        Parameters:
        op - The operator.
        Returns:
        The new dictionary to return.
      • applyScalarOpAndAppend

        public IDictionary applyScalarOpAndAppend​(ScalarOperator op,
                                                  double v0,
                                                  int nCol)
        Description copied from interface: IDictionary
        Allocate a new dictionary with one extra row and applies the scalar operation on each cell of to then return the new dictionary.
        Specified by:
        applyScalarOpAndAppend in interface IDictionary
        Parameters:
        op - The operator
        v0 - The new value to put into each cell in the new row
        nCol - The number of columns in the dictionary
        Returns:
        The new dictionary to return.
      • applyUnaryOp

        public IDictionary applyUnaryOp​(UnaryOperator op)
        Description copied from interface: IDictionary
        Allocate a new dictionary and apply the unary operator on each cell.
        Specified by:
        applyUnaryOp in interface IDictionary
        Parameters:
        op - The operator.
        Returns:
        The new dictionary to return.
      • applyUnaryOpAndAppend

        public IDictionary applyUnaryOpAndAppend​(UnaryOperator op,
                                                 double v0,
                                                 int nCol)
        Description copied from interface: IDictionary
        Allocate a new dictionary with one extra row and apply the unary operator on each cell.
        Specified by:
        applyUnaryOpAndAppend in interface IDictionary
        Parameters:
        op - The operator.
        v0 - The new value to put into each cell in the new row
        nCol - The number of columns in the dictionary
        Returns:
        The new dictionary to return.
      • applyScalarOpWithReference

        public IDictionary applyScalarOpWithReference​(ScalarOperator op,
                                                      double[] reference,
                                                      double[] newReference)
        Description copied from interface: IDictionary
        Allocate a new dictionary and apply the scalar operation on each cell to then return a new dictionary. outValues[j] = op(this.values[j] + reference[i]) - newReference[i]
        Specified by:
        applyScalarOpWithReference in interface IDictionary
        Parameters:
        op - The operator to apply to each cell.
        reference - The reference value to add before the operator.
        newReference - The reference value to subtract after the operator.
        Returns:
        A New Dictionary.
      • applyUnaryOpWithReference

        public IDictionary applyUnaryOpWithReference​(UnaryOperator op,
                                                     double[] reference,
                                                     double[] newReference)
        Description copied from interface: IDictionary
        Allocate a new dictionary and apply the scalar operation on each cell to then return a new dictionary. outValues[j] = op(this.values[j] + reference[i]) - newReference[i]
        Specified by:
        applyUnaryOpWithReference in interface IDictionary
        Parameters:
        op - The unary operator to apply to each cell.
        reference - The reference value to add before the operator.
        newReference - The reference value to subtract after the operator.
        Returns:
        A New Dictionary.
      • binOpLeft

        public IDictionary binOpLeft​(BinaryOperator op,
                                     double[] v,
                                     IColIndex colIndexes)
        Description copied from interface: IDictionary
        Apply binary row operation on the left side
        Specified by:
        binOpLeft in interface IDictionary
        Parameters:
        op - The operation to this dictionary
        v - The values to use on the left hand side.
        colIndexes - The column indexes to consider inside v.
        Returns:
        A new dictionary containing the updated values.
      • binOpLeftAndAppend

        public IDictionary binOpLeftAndAppend​(BinaryOperator op,
                                              double[] v,
                                              IColIndex colIndexes)
        Description copied from interface: IDictionary
        Apply binary row operation on the left side with one extra row evaluating with zeros.
        Specified by:
        binOpLeftAndAppend in interface IDictionary
        Parameters:
        op - The operation to this dictionary
        v - The values to use on the left hand side.
        colIndexes - The column indexes to consider inside v.
        Returns:
        A new dictionary containing the updated values.
      • binOpLeftWithReference

        public IDictionary binOpLeftWithReference​(BinaryOperator op,
                                                  double[] v,
                                                  IColIndex colIndexes,
                                                  double[] reference,
                                                  double[] newReference)
        Description copied from interface: IDictionary
        Apply the binary operator such that each value is offset by the reference before application. Then put the result into the new dictionary, but offset it by the new reference. outValues[j] = op(v[colIndexes[i]], this.values[j] + reference[i]) - newReference[i]
        Specified by:
        binOpLeftWithReference in interface IDictionary
        Parameters:
        op - The operation to apply on the dictionary values.
        v - The values to use on the left side of the operator.
        colIndexes - The column indexes to use.
        reference - The reference value to add before operator.
        newReference - The reference value to subtract after operator.
        Returns:
        A new dictionary.
      • aggregateColsWithReference

        public void aggregateColsWithReference​(double[] c,
                                               Builtin fn,
                                               IColIndex colIndexes,
                                               double[] reference,
                                               boolean def)
        Description copied from interface: IDictionary
        Aggregates the columns into the target double array provided.
        Specified by:
        aggregateColsWithReference in interface IDictionary
        Parameters:
        c - The target double array, this contains the full number of columns, therefore the colIndexes for this specific dictionary is needed.
        fn - The function to apply to individual columns
        colIndexes - The mapping to the target columns from the individual columns
        reference - The reference offset values to add to each cell.
        def - If the reference should be treated as a tuple as well
      • aggregateRowsWithDefault

        public double[] aggregateRowsWithDefault​(Builtin fn,
                                                 double[] defaultTuple)
        Description copied from interface: IDictionary
        Aggregate all entries in the rows of the dictionary with a extra cell in the end that contains the aggregate of the given defaultTuple.
        Specified by:
        aggregateRowsWithDefault in interface IDictionary
        Parameters:
        fn - The aggregate function
        defaultTuple - The default tuple to aggregate in last cell
        Returns:
        Aggregates for this dictionary tuples.
      • aggregateRowsWithReference

        public double[] aggregateRowsWithReference​(Builtin fn,
                                                   double[] reference)
        Description copied from interface: IDictionary
        Aggregate all entries in the rows with an offset value reference added.
        Specified by:
        aggregateRowsWithReference in interface IDictionary
        Parameters:
        fn - The aggregate function
        reference - The reference offset to each value in the dictionary
        Returns:
        Aggregates for this dictionary tuples.
      • aggregateWithReference

        public double aggregateWithReference​(double init,
                                             Builtin fn,
                                             double[] reference,
                                             boolean def)
        Description copied from interface: IDictionary
        Aggregate all the contained values, with a reference offset.
        Specified by:
        aggregateWithReference in interface IDictionary
        Parameters:
        init - The initial value, in cases such as Max value this could be -infinity.
        fn - The function to apply to the values
        reference - The reference offset to each value in the dictionary
        def - If the reference should be treated as an instance of only as reference
        Returns:
        The aggregated value as a double.
      • aggregate

        public double aggregate​(double init,
                                Builtin fn)
        Description copied from interface: IDictionary
        Aggregate all the contained values, useful in value only computations where the operation is iterating through all values contained in the dictionary.
        Specified by:
        aggregate in interface IDictionary
        Parameters:
        init - The initial Value, in cases such as Max value, this could be -infinity
        fn - The Function to apply to values
        Returns:
        The aggregated value as a double.
      • colSumSq

        public void colSumSq​(double[] c,
                             int[] counts,
                             IColIndex colIndexes)
        Description copied from interface: IDictionary
        Get the column sum of the values contained in the dictionary
        Specified by:
        colSumSq in interface IDictionary
        Parameters:
        c - The output array allocated to contain all column groups output.
        counts - The counts of the individual tuples.
        colIndexes - The columns indexes of the parent column group, this indicate where to put the column sum into the c output.
      • addToEntry

        public void addToEntry​(double[] v,
                               int fr,
                               int to,
                               int nCol)
        Description copied from interface: IDictionary
        Adds the dictionary entry from this dictionary to the d dictionary
        Specified by:
        addToEntry in interface IDictionary
        Parameters:
        v - The target dictionary (dense double array)
        fr - The from index is the tuple index to copy from.
        to - The to index is the row index to copy into.
        nCol - The number of columns in both cases
      • colProduct

        public void colProduct​(double[] res,
                               int[] counts,
                               IColIndex colIndexes)
        Description copied from interface: IDictionary
        Calculate the column product of the dictionary weighted by counts.
        Specified by:
        colProduct in interface IDictionary
        Parameters:
        res - The result vector to put the result into
        counts - The weighted count of individual tuples
        colIndexes - The column indexes.
      • MMDictScalingDense

        public void MMDictScalingDense​(double[] left,
                                       IColIndex rowsLeft,
                                       IColIndex colsRight,
                                       MatrixBlock result,
                                       int[] scaling)
        Description copied from interface: IDictionary
        Matrix multiplication of dictionaries left side dense and transposed. The Right side is this, the scaling factor is used to multiply each element with.
        Specified by:
        MMDictScalingDense in interface IDictionary
        Parameters:
        left - Dense left side (Dense dictionary)
        rowsLeft - Offset rows on the left (That dictionaries column indexes)
        colsRight - Offset cols on the right (This dictionaries column indexes)
        result - The output matrix block, guaranteed to be allocated as dense.
        scaling - The scaling factor to multiply each entry with.
      • countNNZZeroColumns

        public int[] countNNZZeroColumns​(int[] counts)
        Description copied from interface: IDictionary
        Count the number of non zero values in each column of the dictionary, multiplied with the counts
        Specified by:
        countNNZZeroColumns in interface IDictionary
        Parameters:
        counts - The counts to multiply with.
        Returns:
        The nonzero count of each column in the dictionary.
      • sliceOutColumnRange

        public IDictionary sliceOutColumnRange​(int idxStart,
                                               int idxEnd,
                                               int previousNumberOfColumns)
        Description copied from interface: IDictionary
        Modify the dictionary by removing columns not within the index range.
        Specified by:
        sliceOutColumnRange in interface IDictionary
        Parameters:
        idxStart - The column index to start at.
        idxEnd - The column index to end at (not inclusive)
        previousNumberOfColumns - The number of columns contained in the dictionary.
        Returns:
        A dictionary containing the sliced out columns values only.
      • scaleTuples

        public IDictionary scaleTuples​(int[] scaling,
                                       int nCol)
        Description copied from interface: IDictionary
        Scale all tuples contained in the dictionary by the scaling factor given in the int list.
        Specified by:
        scaleTuples in interface IDictionary
        Parameters:
        scaling - The amount to multiply the given tuples with
        nCol - The number of columns contained in this column group.
        Returns:
        A New dictionary (since we don't want to modify the underlying dictionary)
      • binOpRight

        public IDictionary binOpRight​(BinaryOperator op,
                                      double[] v,
                                      IColIndex colIndexes)
        Description copied from interface: IDictionary
        Apply binary row operation on the right side.
        Specified by:
        binOpRight in interface IDictionary
        Parameters:
        op - The operation to this dictionary
        v - The values to use on the right hand side.
        colIndexes - The column indexes to consider inside v.
        Returns:
        A new dictionary containing the updated values.
      • preaggValuesFromDense

        public IDictionary preaggValuesFromDense​(int numVals,
                                                 IColIndex colIndexes,
                                                 IColIndex aggregateColumns,
                                                 double[] b,
                                                 int cut)
        Description copied from interface: IDictionary
        Pre Aggregate values for Right Matrix Multiplication.
        Specified by:
        preaggValuesFromDense in interface IDictionary
        Parameters:
        numVals - The number of values contained in this dictionary
        colIndexes - The column indexes that is associated with the parent column group
        aggregateColumns - The column to aggregate, this is preprocessed, to find remove consideration for empty columns
        b - The values in the right hand side matrix
        cut - The number of columns in b.
        Returns:
        A new dictionary with the pre aggregated values.
      • addToEntryVectorized

        public void addToEntryVectorized​(double[] v,
                                         int f1,
                                         int f2,
                                         int f3,
                                         int f4,
                                         int f5,
                                         int f6,
                                         int f7,
                                         int f8,
                                         int t1,
                                         int t2,
                                         int t3,
                                         int t4,
                                         int t5,
                                         int t6,
                                         int t7,
                                         int t8,
                                         int nCol)
        Description copied from interface: IDictionary
        Vectorized add to entry, this call helps with a bit of locality for the cache.
        Specified by:
        addToEntryVectorized in interface IDictionary
        Parameters:
        v - The target dictionary (dense double array)
        f1 - From index 1
        f2 - From index 2
        f3 - From index 3
        f4 - From index 4
        f5 - From index 5
        f6 - From index 6
        f7 - From index 7
        f8 - From index 8
        t1 - To index 1
        t2 - To index 2
        t3 - To index 3
        t4 - To index 4
        t5 - To index 5
        t6 - To index 6
        t7 - To index 7
        t8 - To index 8
        nCol - Number of columns in the dictionary
      • getValues

        public double[] getValues()
        Description copied from interface: IDictionary
        Get all the values contained in the dictionary as a linearized double array.
        Specified by:
        getValues in interface IDictionary
        Returns:
        linearized double array
      • getValue

        public double getValue​(int i)
        Description copied from interface: IDictionary
        Get Specific value contained in the dictionary at index.
        Specified by:
        getValue in interface IDictionary
        Parameters:
        i - The index to extract the value from
        Returns:
        The value contained at the index
      • getValue

        public double getValue​(int r,
                               int col,
                               int nCol)
        Description copied from interface: IDictionary
        Get Specific value contain in dictionary at index.
        Specified by:
        getValue in interface IDictionary
        Parameters:
        r - Row target
        col - Col target
        nCol - nCol in dictionary
        Returns:
        value
      • aggregateRows

        public double[] aggregateRows​(Builtin fn,
                                      int nCol)
        Description copied from interface: IDictionary
        Aggregate all entries in the rows.
        Specified by:
        aggregateRows in interface IDictionary
        Parameters:
        fn - The aggregate function
        nCol - The number of columns contained in the dictionary.
        Returns:
        Aggregates for this dictionary tuples.
      • aggregateCols

        public void aggregateCols​(double[] c,
                                  Builtin fn,
                                  IColIndex colIndexes)
        Description copied from interface: IDictionary
        Aggregates the columns into the target double array provided.
        Specified by:
        aggregateCols in interface IDictionary
        Parameters:
        c - The target double array, this contains the full number of columns, therefore the colIndexes for this specific dictionary is needed.
        fn - The function to apply to individual columns
        colIndexes - The mapping to the target columns from the individual columns
      • sumAllRowsToDouble

        public double[] sumAllRowsToDouble​(int nrColumns)
        Description copied from interface: IDictionary
        Method used as a pre-aggregate of each tuple in the dictionary, to single double values. Note if the number of columns is one the actual dictionaries values are simply returned.
        Specified by:
        sumAllRowsToDouble in interface IDictionary
        Parameters:
        nrColumns - The number of columns in the ColGroup to know how to get the values from the dictionary.
        Returns:
        a double array containing the row sums from this dictionary.
      • sumAllRowsToDoubleWithDefault

        public double[] sumAllRowsToDoubleWithDefault​(double[] defaultTuple)
        Description copied from interface: IDictionary
        Do exactly the same as the sumAllRowsToDouble but also sum the array given to a extra index in the end of the array.
        Specified by:
        sumAllRowsToDoubleWithDefault in interface IDictionary
        Parameters:
        defaultTuple - The default row to sum in the end index returned.
        Returns:
        a double array containing the row sums from this dictionary.
      • sumAllRowsToDoubleWithReference

        public double[] sumAllRowsToDoubleWithReference​(double[] reference)
        Description copied from interface: IDictionary
        Method used as a pre-aggregate of each tuple in the dictionary, to single double values with a reference.
        Specified by:
        sumAllRowsToDoubleWithReference in interface IDictionary
        Parameters:
        reference - The reference values to add to each cell.
        Returns:
        a double array containing the row sums from this dictionary.
      • sumAllRowsToDoubleSq

        public double[] sumAllRowsToDoubleSq​(int nrColumns)
        Description copied from interface: IDictionary
        Method used as a pre-aggregate of each tuple in the dictionary, to single double values. Note if the number of columns is one the actual dictionaries values are simply returned.
        Specified by:
        sumAllRowsToDoubleSq in interface IDictionary
        Parameters:
        nrColumns - The number of columns in the ColGroup to know how to get the values from the dictionary.
        Returns:
        a double array containing the row sums from this dictionary.
      • productAllRowsToDouble

        public double[] productAllRowsToDouble​(int nrColumns)
        Description copied from interface: IDictionary
        Method to product all rows to a column vector.
        Specified by:
        productAllRowsToDouble in interface IDictionary
        Parameters:
        nrColumns - The number of columns in the ColGroup to know how to get the values from the dictionary.
        Returns:
        A row product
      • productAllRowsToDoubleWithDefault

        public double[] productAllRowsToDoubleWithDefault​(double[] defaultTuple)
        Description copied from interface: IDictionary
        Method to product all rows to a column vector with a default value added in the end.
        Specified by:
        productAllRowsToDoubleWithDefault in interface IDictionary
        Parameters:
        defaultTuple - The default row that aggregate to last cell
        Returns:
        A row product
      • colSum

        public void colSum​(double[] c,
                           int[] counts,
                           IColIndex colIndexes)
        Description copied from interface: IDictionary
        Get the column sum of the values contained in the dictionary
        Specified by:
        colSum in interface IDictionary
        Parameters:
        c - The output array allocated to contain all column groups output.
        counts - The counts of the individual tuples.
        colIndexes - The columns indexes of the parent column group, this indicate where to put the column sum into the c output.
      • sum

        public double sum​(int[] counts,
                          int nCol)
        Description copied from interface: IDictionary
        Get the sum of the values contained in the dictionary
        Specified by:
        sum in interface IDictionary
        Parameters:
        counts - The counts of the individual tuples
        nCol - The number of columns contained
        Returns:
        The sum scaled by the counts provided.
      • sumSq

        public double sumSq​(int[] counts,
                            int nCol)
        Description copied from interface: IDictionary
        Get the square sum of the values contained in the dictionary
        Specified by:
        sumSq in interface IDictionary
        Parameters:
        counts - The counts of the individual tuples
        nCol - The number of columns contained
        Returns:
        The square sum scaled by the counts provided.
      • containsValue

        public boolean containsValue​(double pattern)
        Description copied from interface: IDictionary
        Detect if the dictionary contains a specific value.
        Specified by:
        containsValue in interface IDictionary
        Parameters:
        pattern - The value to search for
        Returns:
        true if the value is contained else false.
      • addToEntry

        public void addToEntry​(double[] v,
                               int fr,
                               int to,
                               int nCol,
                               int rep)
        Description copied from interface: IDictionary
        Adds the dictionary entry from this dictionary to the v dictionary rep times.
        Specified by:
        addToEntry in interface IDictionary
        Parameters:
        v - The target dictionary (dense double array)
        fr - The from index is the tuple index to copy from.
        to - The to index is the row index to copy into.
        nCol - The number of columns in both cases
        rep - The number of repetitions to apply (simply multiply do not loop)
      • getMBDict

        public MatrixBlockDictionary getMBDict​(int nCol)
        Description copied from interface: IDictionary
        Get this dictionary as a MatrixBlock dictionary. This allows us to use optimized kernels coded elsewhere in the system, such as matrix multiplication. Return null if the matrix is empty.
        Specified by:
        getMBDict in interface IDictionary
        Parameters:
        nCol - The number of columns contained in this column group.
        Returns:
        A Dictionary containing a MatrixBlock.