Class ColumnView
-
- All Implemented Interfaces:
public class ColumnView
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 < 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
QORE Lab, Imperial College London
-
-
Field Summary
Fields Modifier and Type Field Description public final int
columnIndex
public final int
numRows
-
Method Summary
Modifier and Type Method Description int
getColumnIndex()
Returns the column index that this view represents. int
getNumRows()
Returns the total number of rows in the column (including zeros). double
get(int row)
Returns the value at the specified row in this column. int
getNonZeroCount()
Returns the number of non-zero elements in this column. int
getNonZeroRow(int i)
Returns the row index of the i-th non-zero element in this column. double
getNonZeroValue(int i)
Returns the value of the i-th non-zero element in this column. boolean
hasNonZeros()
Checks if this column has any non-zero elements. -
-
Method Detail
-
getColumnIndex
int getColumnIndex()
Returns the column index that this view represents.
- Returns:
the column index
-
getNumRows
int getNumRows()
Returns the total number of rows in the column (including zeros).
- Returns:
the number of rows
-
get
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
-
getNonZeroCount
int getNonZeroCount()
Returns the number of non-zero elements in this column.
- Returns:
the count of non-zero elements
-
getNonZeroRow
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
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
-
hasNonZeros
boolean hasNonZeros()
Checks if this column has any non-zero elements.
- Returns:
true if the column contains at least one non-zero element
-
-
-
-