pub struct HybMatrix<T: GpuFloat> { /* private fields */ }Expand description
A sparse matrix in HYB (Hybrid ELL+COO) format, stored on host.
The ELL portion uses column-major layout: element (row, k) is at index
k * rows + row. Unused ELL slots have column index HYB_ELL_SENTINEL
and a zero value.
The COO portion stores overflow entries as unsorted (row, col, value)
triplets.
Implementations§
Source§impl<T: GpuFloat> HybMatrix<T>
impl<T: GpuFloat> HybMatrix<T>
Sourcepub fn new(
rows: usize,
cols: usize,
ell_width: usize,
ell_col_indices: Vec<i32>,
ell_values: Vec<T>,
coo_row_indices: Vec<i32>,
coo_col_indices: Vec<i32>,
coo_values: Vec<T>,
) -> SparseResult<Self>
pub fn new( rows: usize, cols: usize, ell_width: usize, ell_col_indices: Vec<i32>, ell_values: Vec<T>, coo_row_indices: Vec<i32>, coo_col_indices: Vec<i32>, coo_values: Vec<T>, ) -> SparseResult<Self>
Creates a new HYB matrix from raw host-side arrays.
§Arguments
rows– Number of rows.cols– Number of columns.ell_width– Maximum entries per row in the ELL portion.ell_col_indices– ELL column indices, lengthrows * ell_width, column-major. Unused entries must beHYB_ELL_SENTINEL.ell_values– ELL values, lengthrows * ell_width, column-major.coo_row_indices– COO overflow row indices.coo_col_indices– COO overflow column indices.coo_values– COO overflow values.
§Errors
Returns SparseError::InvalidFormat if array lengths are inconsistent.
Sourcepub fn from_csr(
csr: &CsrMatrix<T>,
partition: HybPartition,
) -> SparseResult<Self>
pub fn from_csr( csr: &CsrMatrix<T>, partition: HybPartition, ) -> SparseResult<Self>
Constructs a HYB matrix from a CSR matrix using the given partition strategy.
Downloads the CSR data from GPU, computes per-row nnz, determines
the ELL width according to partition, then fills ELL up to that
width and overflows the remainder into COO.
§Errors
Returns SparseError::Cuda on GPU transfer failure.
Sourcepub fn from_coo(
coo: &CooMatrix<T>,
partition: HybPartition,
) -> SparseResult<Self>
pub fn from_coo( coo: &CooMatrix<T>, partition: HybPartition, ) -> SparseResult<Self>
Constructs a HYB matrix from a COO matrix (via CSR intermediate) using the given partition strategy.
Converts COO to CSR first, then builds HYB from the CSR data.
§Errors
Returns SparseError::Cuda on GPU transfer failure.
Sourcepub fn to_csr(&self) -> SparseResult<CsrMatrix<T>>
pub fn to_csr(&self) -> SparseResult<CsrMatrix<T>>
Converts this HYB matrix back to CSR format, uploading to GPU.
Merges the ELL and COO portions into a single CSR representation.
§Errors
Returns SparseError::Cuda on GPU allocation failure.
Returns SparseError::ZeroNnz if the matrix has no non-zeros.
Sourcepub fn ell_col_indices(&self) -> &[i32]
pub fn ell_col_indices(&self) -> &[i32]
Returns a reference to the ELL column indices (column-major).
Sourcepub fn ell_values(&self) -> &[T]
pub fn ell_values(&self) -> &[T]
Returns a reference to the ELL values (column-major).
Sourcepub fn coo_row_indices(&self) -> &[i32]
pub fn coo_row_indices(&self) -> &[i32]
Returns a reference to the COO overflow row indices.
Sourcepub fn coo_col_indices(&self) -> &[i32]
pub fn coo_col_indices(&self) -> &[i32]
Returns a reference to the COO overflow column indices.
Sourcepub fn coo_values(&self) -> &[T]
pub fn coo_values(&self) -> &[T]
Returns a reference to the COO overflow values.
Sourcepub fn statistics(&self) -> HybStatistics
pub fn statistics(&self) -> HybStatistics
Computes statistics describing the quality of the HYB partition.
The returned HybStatistics includes the fraction of nnz in each
portion, the ELL padding ratio, and memory consumption compared to
an equivalent CSR matrix.