pub struct GraphColoring {
pub num_colors: usize,
pub colors: Vec<u32>,
pub color_offsets: Vec<usize>,
pub color_order: Vec<u32>,
}Expand description
Result of a distance-2 graph coloring of a sparse matrix.
Contains the color assignment for each row, plus auxiliary data structures for efficiently iterating over rows of the same color.
Fields§
§num_colors: usizeNumber of distinct colors used.
colors: Vec<u32>Color assigned to each row: colors[i] is the color of row i.
color_offsets: Vec<usize>Start index of each color group in color_order.
color_offsets[c]..color_offsets[c+1] gives the range of row indices
with color c in color_order.
color_order: Vec<u32>Row indices sorted by color.
Implementations§
Source§impl GraphColoring
impl GraphColoring
Sourcepub fn from_csr<T: GpuFloat>(
_handle: &SparseHandle,
matrix: &CsrMatrix<T>,
) -> SparseResult<Self>
pub fn from_csr<T: GpuFloat>( _handle: &SparseHandle, matrix: &CsrMatrix<T>, ) -> SparseResult<Self>
Compute a distance-2 coloring of the adjacency graph of a CSR matrix.
The matrix must be square. The coloring considers the structural (non-zero) pattern, not the numerical values.
§Arguments
_handle— sparse handle (reserved for future GPU-accelerated variants).matrix— a square CSR matrix.
§Errors
Returns SparseError::DimensionMismatch if the matrix is not square.
Sourcepub fn from_csr_host(
row_ptr: &[i32],
col_idx: &[i32],
n: usize,
) -> SparseResult<Self>
pub fn from_csr_host( row_ptr: &[i32], col_idx: &[i32], n: usize, ) -> SparseResult<Self>
Compute distance-2 coloring from host-side CSR structure.
This is the core algorithm, operating on host data.
Sourcepub fn rows_for_color(&self, color: usize) -> &[u32]
pub fn rows_for_color(&self, color: usize) -> &[u32]
Returns the row indices for a given color.
§Panics
This method does not panic; returns an empty slice if color >= num_colors.
Sourcepub fn parallel_ilu0<T: GpuFloat>(
&self,
_handle: &SparseHandle,
matrix: &CsrMatrix<T>,
) -> SparseResult<(CsrMatrix<T>, CsrMatrix<T>)>
pub fn parallel_ilu0<T: GpuFloat>( &self, _handle: &SparseHandle, matrix: &CsrMatrix<T>, ) -> SparseResult<(CsrMatrix<T>, CsrMatrix<T>)>
Apply coloring to parallelize ILU(0) factorization.
Performs ILU(0) on a CSR matrix, processing rows color-by-color. Within each color, rows are independent and can be processed in parallel.
Returns (L, U) where L is unit lower triangular and U is upper
triangular (including diagonal).
§Arguments
_handle— sparse handle.matrix— the CSR matrix to factor (square, will be consumed for values).
§Errors
Returns SparseError::SingularMatrix if a zero pivot is encountered.