//! Implements core traits for use with `matrixcompare`. use crate::csr::CsrMatrix; use crate::csc::CscMatrix; use matrixcompare_core; use matrixcompare_core::{Access, SparseAccess}; use crate::coo::CooMatrix; macro_rules! impl_matrix_for_csr_csc { ($MatrixType:ident) => { impl SparseAccess for $MatrixType { fn nnz(&self) -> usize { $MatrixType::nnz(self) } fn fetch_triplets(&self) -> Vec<(usize, usize, T)> { self.triplet_iter().map(|(i, j, v)| (i, j, v.clone())).collect() } } impl matrixcompare_core::Matrix for $MatrixType { fn rows(&self) -> usize { self.nrows() } fn cols(&self) -> usize { self.ncols() } fn access(&self) -> Access { Access::Sparse(self) } } } } impl_matrix_for_csr_csc!(CsrMatrix); impl_matrix_for_csr_csc!(CscMatrix); impl SparseAccess for CooMatrix { fn nnz(&self) -> usize { CooMatrix::nnz(self) } fn fetch_triplets(&self) -> Vec<(usize, usize, T)> { self.triplet_iter().map(|(i, j, v)| (i, j, v.clone())).collect() } } impl matrixcompare_core::Matrix for CooMatrix { fn rows(&self) -> usize { self.nrows() } fn cols(&self) -> usize { self.ncols() } fn access(&self) -> Access { Access::Sparse(self) } }