Class SparseRowVector

  • All Implemented Interfaces:
    Serializable

    public final class SparseRowVector
    extends SparseRow
    A sparse row vector that is able to grow dynamically as values are appended to it.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int initialCapacity
      Initial capacity of any created sparse row
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int col, double v)
      Add a value to a specified column with awareness of potential insertions.
      SparseRowVector append​(int col, double v)
      Appends a value to the end of the sparse row.
      int capacity()  
      void compact()
      In-place compaction of non-zero-entries; removes zero entries and shifts non-zero entries to the left if necessary.
      void compact​(double eps)
      In-place compaction of values over eps away from zero; and shifts non-zero entries to the left if necessary.
      SparseRow copy​(boolean deep)
      Make a copy of this row.
      void copy​(SparseRow that)  
      void deleteIndexRange​(int lowerCol, int upperCol)  
      double get​(int col)
      Gets the value of a specified column.
      int getIndex​(int col)  
      int[] indexes()
      Get the index array of non-zero entries, co-aligned with the array of values.
      boolean isEmpty()
      Indicates if the sparse row is empty, i.e., if is has size zero.
      void reset​(int estnns, int maxnns)
      Resets the sparse row to empty, after this call size and isEmpty are guaranteed to return 0 and true, respectively.
      int searchIndexesFirstGT​(int col)  
      int searchIndexesFirstGTE​(int col)
      Get first index greater than equal column index.
      int searchIndexesFirstLTE​(int col)  
      boolean set​(int col, double v)
      Sets the value of a specified column with awareness of potential overwrites or deletes (set to value zero).
      void setAtPos​(int pos, int col, double v)  
      void setEstimatedNzs​(int estnnz)  
      void setIndexes​(int[] i)  
      void setIndexRange​(int cl, int cu, double[] v, int[] vix, int vpos, int vlen)  
      void setIndexRange​(int cl, int cu, double[] v, int vix, int vlen)  
      void setSize​(int newsize)  
      void setValues​(double[] d)  
      int size()
      Get the number of non-zero values of the sparse row.
      void sort()
      In-place sort of column-index value pairs in order to allow binary search after constant-time append was used for reading unordered sparse rows.
      double[] values()
      Get the value array of non-zero entries, co-aligned with the array of indexes.
    • Field Detail

      • initialCapacity

        public static final int initialCapacity

        Initial capacity of any created sparse row

        WARNING: be aware that this affects the core memory estimates (incl. implicit assumptions)!
        See Also:
        Constant Field Values
    • Constructor Detail

      • SparseRowVector

        public SparseRowVector()
      • SparseRowVector

        public SparseRowVector​(int capacity)
      • SparseRowVector

        public SparseRowVector​(int nnz,
                               double[] v,
                               int vlen)
      • SparseRowVector

        public SparseRowVector​(double[] v,
                               int[] i)
      • SparseRowVector

        public SparseRowVector​(double[] v,
                               int[] i,
                               int nnz)
      • SparseRowVector

        public SparseRowVector​(double[] v)
        Sparse row vector constructor that take a dense array, and allocate sparsely by ignoring zero values
        Parameters:
        v - The dense row
      • SparseRowVector

        public SparseRowVector​(int estnnz,
                               int maxnnz)
      • SparseRowVector

        public SparseRowVector​(SparseRow that)
    • Method Detail

      • size

        public int size()
        Description copied from class: SparseRow
        Get the number of non-zero values of the sparse row.
        Specified by:
        size in class SparseRow
        Returns:
        number of non-zeros
      • setSize

        public void setSize​(int newsize)
      • isEmpty

        public final boolean isEmpty()
        Description copied from class: SparseRow
        Indicates if the sparse row is empty, i.e., if is has size zero.
        Specified by:
        isEmpty in class SparseRow
        Returns:
        true if empty
      • values

        public double[] values()
        Description copied from class: SparseRow
        Get the value array of non-zero entries, co-aligned with the array of indexes.
        Specified by:
        values in class SparseRow
        Returns:
        array of values
      • indexes

        public int[] indexes()
        Description copied from class: SparseRow
        Get the index array of non-zero entries, co-aligned with the array of values.
        Specified by:
        indexes in class SparseRow
        Returns:
        array of indexes
      • setValues

        public void setValues​(double[] d)
      • setIndexes

        public void setIndexes​(int[] i)
      • capacity

        public int capacity()
      • copy

        public void copy​(SparseRow that)
      • reset

        public void reset​(int estnns,
                          int maxnns)
        Description copied from class: SparseRow
        Resets the sparse row to empty, after this call size and isEmpty are guaranteed to return 0 and true, respectively.
        Specified by:
        reset in class SparseRow
        Parameters:
        estnns - estimated number of non-zeros
        maxnns - maximum number of non-zeros, e.g., number of columns
      • setEstimatedNzs

        public void setEstimatedNzs​(int estnnz)
      • set

        public boolean set​(int col,
                           double v)
        Description copied from class: SparseRow
        Sets the value of a specified column with awareness of potential overwrites or deletes (set to value zero).
        Specified by:
        set in class SparseRow
        Parameters:
        col - column index, zero-based
        v - value
        Returns:
        true if the size of the sparse row changed
      • setAtPos

        public void setAtPos​(int pos,
                             int col,
                             double v)
      • add

        public boolean add​(int col,
                           double v)
        Description copied from class: SparseRow
        Add a value to a specified column with awareness of potential insertions.
        Specified by:
        add in class SparseRow
        Parameters:
        col - column index, zero-based
        v - value
        Returns:
        true if the size of the sparse row changed
      • append

        public SparseRowVector append​(int col,
                                      double v)
        Description copied from class: SparseRow
        Appends a value to the end of the sparse row.
        Specified by:
        append in class SparseRow
        Parameters:
        col - column index, zero-based
        v - value
        Returns:
        the row with an appended element
      • get

        public double get​(int col)
        Description copied from class: SparseRow
        Gets the value of a specified column. If the column index does not exist in the sparse row, this call returns zero.
        Specified by:
        get in class SparseRow
        Parameters:
        col - column index, zero-based
        Returns:
        value
      • getIndex

        public int getIndex​(int col)
      • searchIndexesFirstLTE

        public int searchIndexesFirstLTE​(int col)
      • searchIndexesFirstGTE

        public int searchIndexesFirstGTE​(int col)
        Description copied from class: SparseRow
        Get first index greater than equal column index.
        Specified by:
        searchIndexesFirstGTE in class SparseRow
        Parameters:
        col - column to be greater than
        Returns:
        index
      • deleteIndexRange

        public void deleteIndexRange​(int lowerCol,
                                     int upperCol)
      • setIndexRange

        public void setIndexRange​(int cl,
                                  int cu,
                                  double[] v,
                                  int vix,
                                  int vlen)
      • setIndexRange

        public void setIndexRange​(int cl,
                                  int cu,
                                  double[] v,
                                  int[] vix,
                                  int vpos,
                                  int vlen)
      • sort

        public void sort()
        Description copied from class: SparseRow
        In-place sort of column-index value pairs in order to allow binary search after constant-time append was used for reading unordered sparse rows. We first check if already sorted and subsequently sort if necessary in order to get O(n) best case. Note: In-place sort is necessary in order to guarantee the memory estimate for operations that implicitly read that data set.
        Specified by:
        sort in class SparseRow
      • compact

        public void compact()
        Description copied from class: SparseRow
        In-place compaction of non-zero-entries; removes zero entries and shifts non-zero entries to the left if necessary.
        Specified by:
        compact in class SparseRow
      • compact

        public void compact​(double eps)
        Description copied from class: SparseRow
        In-place compaction of values over eps away from zero; and shifts non-zero entries to the left if necessary.
        Specified by:
        compact in class SparseRow
        Parameters:
        eps - epsilon value
      • copy

        public SparseRow copy​(boolean deep)
        Description copied from class: SparseRow
        Make a copy of this row.
        Specified by:
        copy in class SparseRow
        Parameters:
        deep - if the copy should be deep
        Returns:
        A copy