Skip to main content

validate_csr_matrix

Function validate_csr_matrix 

Source
pub fn validate_csr_matrix(
    matrix: &CsrMatrix<f32>,
) -> Result<(), ValidationError>
Expand description

Validate the structural integrity of a CSR matrix.

Performs the following checks in order:

  1. rows and cols are within MAX_NODES.
  2. nnz (number of non-zeros) is within MAX_EDGES.
  3. row_ptr length equals rows + 1.
  4. row_ptr is monotonically non-decreasing.
  5. row_ptr[0] == 0 and row_ptr[rows] == nnz.
  6. col_indices length equals values length.
  7. All column indices are less than cols.
  8. No NaN or Inf values in values.
  9. Column indices are sorted within each row (emits a tracing::warn if not, but does not error).

§Errors

Returns ValidationError describing the first violation found.

§Examples

use ruvector_solver::types::CsrMatrix;
use ruvector_solver::validation::validate_csr_matrix;

let m = CsrMatrix::<f32>::from_coo(2, 2, vec![(0, 0, 1.0), (1, 1, 2.0)]);
assert!(validate_csr_matrix(&m).is_ok());