pub struct EllMatrix<T: Scalar> { /* private fields */ }Expand description
ELLPACK sparse matrix format.
Efficient for:
- GPU computation
- Vectorized operations
- Matrices with uniform row lengths
§Storage
Each row stores exactly width entries. The width is typically the maximum
number of non-zeros in any row. Rows with fewer non-zeros are padded with
zeros and a special “invalid” column index (usually ncols or usize::MAX).
§Example
use oxiblas_sparse::EllMatrix;
// Create a sparse matrix:
// [1 2 0 0]
// [0 3 4 0]
// [5 0 0 6]
let width = 2; // max 2 non-zeros per row
let data = vec![
vec![1.0, 2.0], // row 0
vec![3.0, 4.0], // row 1
vec![5.0, 6.0], // row 2
];
let indices = vec![
vec![0, 1], // row 0
vec![1, 2], // row 1
vec![0, 3], // row 2
];
let ell = EllMatrix::new(3, 4, width, data, indices).unwrap();
assert_eq!(ell.width(), 2);Implementations§
Source§impl<T: Scalar + Clone> EllMatrix<T>
impl<T: Scalar + Clone> EllMatrix<T>
Sourcepub fn new(
nrows: usize,
ncols: usize,
width: usize,
data: Vec<Vec<T>>,
indices: Vec<Vec<usize>>,
) -> Result<Self, EllError>
pub fn new( nrows: usize, ncols: usize, width: usize, data: Vec<Vec<T>>, indices: Vec<Vec<usize>>, ) -> Result<Self, EllError>
Sourcepub unsafe fn new_unchecked(
nrows: usize,
ncols: usize,
width: usize,
data: Vec<Vec<T>>,
indices: Vec<Vec<usize>>,
) -> Self
pub unsafe fn new_unchecked( nrows: usize, ncols: usize, width: usize, data: Vec<Vec<T>>, indices: Vec<Vec<usize>>, ) -> Self
Creates an ELL matrix without validation (unsafe but faster).
§Safety
The caller must ensure:
data.len() == nrowsand each row has lengthwidthindices.len() == nrowsand each row has lengthwidth- All valid column indices are < ncols
Sourcepub fn zeros(nrows: usize, ncols: usize) -> Self
pub fn zeros(nrows: usize, ncols: usize) -> Self
Creates an empty ELL matrix with given dimensions.
Sourcepub fn nnz(&self) -> usizewhere
T: Field,
pub fn nnz(&self) -> usizewhere
T: Field,
Returns the number of non-zero elements.
Note: This counts actual non-zeros, not stored values.
Sourcepub fn efficiency(&self) -> f64where
T: Field,
pub fn efficiency(&self) -> f64where
T: Field,
Returns the storage efficiency (nnz / nstored).
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&T>
pub fn get(&self, row: usize, col: usize) -> Option<&T>
Gets the value at (row, col), returning None if not present.
Sourcepub fn get_or_zero(&self, row: usize, col: usize) -> Twhere
T: Field,
pub fn get_or_zero(&self, row: usize, col: usize) -> Twhere
T: Field,
Gets the value at (row, col), returning zero if not present.
Sourcepub fn row_iter(&self, row: usize) -> impl Iterator<Item = (usize, &T)>
pub fn row_iter(&self, row: usize) -> impl Iterator<Item = (usize, &T)>
Returns an iterator over non-zeros in a row as (col, value).
Sourcepub fn iter(&self) -> impl Iterator<Item = (usize, usize, &T)> + '_
pub fn iter(&self) -> impl Iterator<Item = (usize, usize, &T)> + '_
Returns an iterator over all non-zeros as (row, col, value).
Sourcepub fn mul_vec(&self, x: &[T]) -> Vec<T>where
T: Field,
pub fn mul_vec(&self, x: &[T]) -> Vec<T>where
T: Field,
Matrix-vector product returning a new vector: y = A * x.
Sourcepub fn from_dense(dense: &MatRef<'_, T>, max_width: Option<usize>) -> Selfwhere
T: Field,
pub fn from_dense(dense: &MatRef<'_, T>, max_width: Option<usize>) -> Selfwhere
T: Field,
Creates an ELL matrix from a dense matrix.
§Arguments
dense- Source dense matrixmax_width- Maximum width (if None, uses actual max non-zeros per row)