Package org.apache.sysds.runtime.data

## Class SparseRow

- java.lang.Object
- - org.apache.sysds.runtime.data.SparseRow

- All Implemented Interfaces:
    `Serializable`
  Direct Known Subclasses:
    `SparseRowScalar`, `SparseRowVector`

      public abstract class SparseRow
      extends Object
      implements Serializable

  Base class for sparse row implementations such as sparse row vectors and sparse scalars (single value per row).
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SparseRow()` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `abstract boolean` | `add​(int col, double v)` | Add a value to a specified column with awareness of potential insertions.
    `abstract void` | `append​(int col, double v)` | Appends a value to the end of the sparse row.
    `abstract void` | `compact()` | In-place compaction of non-zero-entries; removes zero entries and shifts non-zero entries to the left if necessary.
    `abstract void` | `compact​(double eps)` | In-place compaction of values over eps away from zero; and shifts non-zero entries to the left if necessary.
    `abstract double` | `get​(int col)` | Gets the value of a specified column.
    `abstract int[]` | `indexes()` | Get the index array of non-zero entries, co-aligned with the array of values.
    `abstract boolean` | `isEmpty()` | Indicates if the sparse row is empty, i.e., if is has size zero.
    `abstract 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.
    `abstract boolean` | `set​(int col, double v)` | Sets the value of a specified column with awareness of potential overwrites or deletes (set to value zero).
    `abstract int` | `size()` | Get the number of non-zero values of the sparse row.
    `abstract 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.
    `String` | `toString()` |
    `abstract double[]` | `values()` | Get the value array of non-zero entries, co-aligned with the array of indexes.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SparseRow

          public SparseRow()

  - ### Method Detail

    - #### size

          public abstract int size()

      Get the number of non-zero values of the sparse row.
      Returns:
        number of non-zeros

    - #### isEmpty

          public abstract boolean isEmpty()

      Indicates if the sparse row is empty, i.e., if is has size zero.
      Returns:
        true if empty

    - #### values

          public abstract double[] values()

      Get the value array of non-zero entries, co-aligned with the array of indexes.
      Returns:
        array of values

    - #### indexes

          public abstract int[] indexes()

      Get the index array of non-zero entries, co-aligned with the array of values.
      Returns:
        array of indexes

    - #### reset

          public abstract 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.
      Parameters:
        `estnns` - estimated number of non-zeros
        `maxnns` - maximum number of non-zeros, e.g., number of columns

    - #### set

          public abstract boolean set​(int col,
                                      double v)

      Sets the value of a specified column with awareness of potential overwrites or deletes (set to value zero).
      Parameters:
        `col` - column index, zero-based
        `v` - value
      Returns:
        true if the size of the sparse row changed

    - #### add

          public abstract boolean add​(int col,
                                      double v)

      Add a value to a specified column with awareness of potential insertions.
      Parameters:
        `col` - column index, zero-based
        `v` - value
      Returns:
        true if the size of the sparse row changed

    - #### append

          public abstract void append​(int col,
                                      double v)

      Appends a value to the end of the sparse row.
      Parameters:
        `col` - column index, zero-based
        `v` - value

    - #### get

          public abstract double get​(int col)

      Gets the value of a specified column. If the column index does not exist in the sparse row, this call returns zero.
      Parameters:
        `col` - column index, zero-based
      Returns:
        value

    - #### sort

          public abstract 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. 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.

    - #### compact

          public abstract void compact()

      In-place compaction of non-zero-entries; removes zero entries and shifts non-zero entries to the left if necessary.

    - #### compact

          public abstract void compact​(double eps)

      In-place compaction of values over eps away from zero; and shifts non-zero entries to the left if necessary.
      Parameters:
        `eps` - epsilon value

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`