Skip to main content

GraphColoring

Struct GraphColoring 

Source
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: usize

Number 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn validate(&self, row_ptr: &[i32], col_idx: &[i32], n: usize) -> bool

Validates the coloring: checks that no two vertices within distance 2 share the same color.

Returns true if the coloring is valid.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more