Class ColumnView

java.lang.Object
jline.util.matrix.ColumnView

public class ColumnView extends Object
A lightweight view into a column of a sparse matrix that doesn't copy data. This provides efficient access to matrix column elements without the overhead of creating a new Matrix object and copying all the data.

This is particularly useful for large sparse matrices where you need to access column elements frequently, such as in iterative algorithms.

Example usage:

 Matrix bigMatrix = ...; // 1M x 1000 sparse matrix
 ColumnView col = bigMatrix.getColumnView(5);

 // Efficient access - only processes non-zero elements
 for (int i = 0; i invalid input: '<' col.getNonZeroCount(); i++) {
     int row = col.getNonZeroRow(i);
     double value = col.getNonZeroValue(i);
     // process (row, value) pair
 }

 // Or get any element (returns 0.0 for non-stored elements)
 double val = col.get(100);
 
Since:
1.0
Author:
QORE Lab, Imperial College London
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    get(int row)
    Returns the value at the specified row in this column.
    int
    Returns the column index that this view represents.
    int
    Returns the number of non-zero elements in this column.
    int
    Returns the row index of the i-th non-zero element in this column.
    double
    Returns the value of the i-th non-zero element in this column.
    int
    Returns the total number of rows in the column (including zeros).
    boolean
    Checks if this column has any non-zero elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public double get(int row)
      Returns the value at the specified row in this column. This method searches through the non-zero elements, so it's O(nnz_in_column). For frequent access to multiple elements, consider using the non-zero iterators.
      Parameters:
      row - the row index
      Returns:
      the value at (row, column), or 0.0 if not stored
    • getColumnIndex

      public int getColumnIndex()
      Returns the column index that this view represents.
      Returns:
      the column index
    • getNonZeroCount

      public int getNonZeroCount()
      Returns the number of non-zero elements in this column.
      Returns:
      the count of non-zero elements
    • getNonZeroRow

      public int getNonZeroRow(int i)
      Returns the row index of the i-th non-zero element in this column.
      Parameters:
      i - the index into the non-zero elements (0 to getNonZeroCount()-1)
      Returns:
      the row index
    • getNonZeroValue

      public double getNonZeroValue(int i)
      Returns the value of the i-th non-zero element in this column.
      Parameters:
      i - the index into the non-zero elements (0 to getNonZeroCount()-1)
      Returns:
      the value
    • getNumRows

      public int getNumRows()
      Returns the total number of rows in the column (including zeros).
      Returns:
      the number of rows
    • hasNonZeros

      public boolean hasNonZeros()
      Checks if this column has any non-zero elements.
      Returns:
      true if the column contains at least one non-zero element