Skip to main content

array2_to_csr_with_tolerance

Function array2_to_csr_with_tolerance 

Source
pub fn array2_to_csr_with_tolerance<T: Scalar + Clone + Field>(
    arr: &Array2<T>,
    tolerance: Option<<T as Scalar>::Real>,
) -> CsrMatrix<T>
Expand description

Converts a dense Array2 to CSR (Compressed Sparse Row) format, with an explicit, opt-in tolerance for approximate sparsification.

§Arguments

  • arr - Dense 2D array
  • tolerance - None selects exact-zero sparsification (see array2_to_csr). Some(tol) explicitly opts into dropping any entry with abs(value) <= tol; this must be a deliberate, user-supplied choice, never a silent default, because it changes the numerical content of the matrix.

NaN entries are always retained (stored explicitly) regardless of tolerance, since a NaN is technically non-zero and silently discarding it would be data corruption.

§Returns

CSR matrix containing the retained entries