Class IdentityDictionarySlice

    • Constructor Detail

      • IdentityDictionarySlice

        public IdentityDictionarySlice​(int nRowCol,
                                       boolean withEmpty,
                                       int l,
                                       int u)
        Create a Identity matrix dictionary slice. It behaves as if allocated a Sparse Matrix block but exploits that the structure is known to have certain properties.
        Parameters:
        nRowCol - the number of rows and columns in this identity matrix.
        withEmpty - If the matrix should contain an empty row in the end.
        l - the index lower to start at
        u - the index upper to end at (not inclusive)
    • Method Detail

      • 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
        Overrides:
        getValues in class IdentityDictionary
        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
        Overrides:
        getValue in class IdentityDictionary
        Parameters:
        i - The index to extract the value from
        Returns:
        The value contained at the index
      • getValue

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

        public static long getInMemorySize​(int numberColumns)
      • 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
        Overrides:
        aggregateRows in class IdentityDictionary
        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
        Overrides:
        aggregateCols in class IdentityDictionary
        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
        Overrides:
        sumAllRowsToDouble in class IdentityDictionary
        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
        Overrides:
        sumAllRowsToDoubleWithDefault in class IdentityDictionary
        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
        Overrides:
        sumAllRowsToDoubleWithReference in class IdentityDictionary
        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
        Overrides:
        sumAllRowsToDoubleSq in class IdentityDictionary
        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 nCol)
        Description copied from interface: IDictionary
        Method to product all rows to a column vector.
        Specified by:
        productAllRowsToDouble in interface IDictionary
        Overrides:
        productAllRowsToDouble in class IdentityDictionary
        Parameters:
        nCol - The number of columns in the ColGroup to know how to get the values from the dictionary.
        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
        Overrides:
        colSum in class IdentityDictionary
        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.
      • 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
        Overrides:
        colSumSq in class IdentityDictionary
        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.
      • 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
        Overrides:
        colProduct in class IdentityDictionary
        Parameters:
        res - The result vector to put the result into
        counts - The weighted count of individual tuples
        colIndexes - The column indexes.
      • 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
        Overrides:
        sum in class IdentityDictionary
        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
        Overrides:
        sumSq in class IdentityDictionary
        Parameters:
        counts - The counts of the individual tuples
        ncol - The number of columns contained
        Returns:
        The square sum scaled by the counts provided.
      • 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
        Overrides:
        sliceOutColumnRange in class IdentityDictionary
        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.
      • 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
        Overrides:
        containsValue in class IdentityDictionary
        Parameters:
        pattern - The value to search for
        Returns:
        true if the value is contained else false.
      • getNumberNonZeros

        public long getNumberNonZeros​(int[] counts,
                                      int nCol)
        Description copied from interface: IDictionary
        Calculate the number of non zeros in the dictionary. The number of non zeros should be scaled with the counts given. This gives the exact number of non zero values in the parent column group.
        Specified by:
        getNumberNonZeros in interface IDictionary
        Overrides:
        getNumberNonZeros in class IdentityDictionary
        Parameters:
        counts - The counts of each dictionary entry
        nCol - The number of columns in this dictionary
        Returns:
        The nonZero count
      • 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
        Overrides:
        getMBDict in class IdentityDictionary
        Parameters:
        nCol - The number of columns contained in this column group.
        Returns:
        A Dictionary containing a MatrixBlock.
      • getString

        public String getString​(int colIndexes)
        Description copied from interface: IDictionary
        Get a string representation of the dictionary, that considers the layout of the data.
        Specified by:
        getString in interface IDictionary
        Overrides:
        getString in class IdentityDictionary
        Parameters:
        colIndexes - The number of columns in the dictionary.
        Returns:
        A string that is nicer to print.
      • 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
        Overrides:
        scaleTuples in class IdentityDictionary
        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)
      • 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
        Overrides:
        replace in class IdentityDictionary
        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
        Overrides:
        replaceWithReference in class IdentityDictionary
        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.
      • 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
        Overrides:
        preaggValuesFromDense in class IdentityDictionary
        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
        Overrides:
        addToEntryVectorized in class IdentityDictionary
        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
      • 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
        Overrides:
        addToEntry in class IdentityDictionary
        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)