#![allow(clippy::manual_div_ceil)]
#![allow(clippy::needless_return)]
#![allow(clippy::manual_ok_err)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::while_let_loop)]
#![allow(clippy::vec_init_then_push)]
#![allow(clippy::should_implement_trait)]
#![allow(clippy::only_used_in_recursion)]
#![allow(clippy::manual_slice_fill)]
#![allow(dead_code)]
pub mod error;
pub use error::{SparseError, SparseResult};
pub mod sparray;
pub use sparray::{is_sparse, SparseArray, SparseSum};
pub mod sym_sparray;
pub use sym_sparray::SymSparseArray;
pub mod csr_array;
pub use csr_array::CsrArray;
pub mod csc_array;
pub use csc_array::CscArray;
pub mod coo_array;
pub use coo_array::CooArray;
pub mod dok_array;
pub use dok_array::DokArray;
pub mod lil_array;
pub use lil_array::LilArray;
pub mod dia_array;
pub use dia_array::DiaArray;
pub mod bsr_array;
pub use bsr_array::BsrArray;
pub mod banded_array;
pub use banded_array::BandedArray;
pub mod sym_csr;
pub use sym_csr::{SymCsrArray, SymCsrMatrix};
pub mod sym_coo;
pub use sym_coo::{SymCooArray, SymCooMatrix};
pub mod csr;
pub use csr::CsrMatrix;
pub mod csc;
pub use csc::CscMatrix;
pub mod coo;
pub use coo::CooMatrix;
pub mod dok;
pub use dok::DokMatrix;
pub mod lil;
pub use lil::LilMatrix;
pub mod dia;
pub use dia::DiaMatrix;
pub mod bsr;
pub use bsr::BsrMatrix;
pub mod banded;
pub use banded::BandedMatrix;
pub mod utils;
pub mod linalg;
pub use linalg::{
add,
bicg,
bicgstab,
cg,
cholesky_decomposition,
convolution_operator,
diag_matrix,
eigs,
eigsh,
enhanced_add,
enhanced_diagonal,
enhanced_scale,
enhanced_subtract,
expm,
expm_multiply,
eye,
finite_difference_operator,
gcrot,
gmres,
incomplete_cholesky,
incomplete_lu,
inv,
iram,
iram_shift_invert,
lanczos,
lu_decomposition,
matmul,
matrix_power,
multiply,
norm,
onenormest,
power_iteration,
qr_decomposition,
solve_arrow_matrix,
solve_banded_system,
solve_block_2x2,
solve_kronecker_system,
solve_saddle_point,
sparse_direct_solve,
sparse_lstsq,
spsolve,
svd_truncated,
svds,
tfqmr,
ArnoldiConfig,
ArpackOptions,
AsLinearOperator,
BiCGOptions,
BiCGSTABOptions,
BiCGSTABResult,
BoundaryCondition,
CGOptions,
CGSOptions,
CGSResult,
CholeskyResult,
ConvolutionMode,
ConvolutionOperator,
DiagonalOperator,
EigenResult,
EigenvalueMethod,
EnhancedDiagonalOperator,
EnhancedDifferenceOperator,
EnhancedOperatorOptions,
EnhancedScaledOperator,
EnhancedSumOperator,
FiniteDifferenceOperator,
GCROTOptions,
GCROTResult,
GMRESOptions,
ICOptions,
ILU0Preconditioner,
ILUOptions,
IdentityOperator,
IterationResult,
JacobiPreconditioner,
LUResult,
LanczosOptions,
LinearOperator,
PowerIterationOptions,
QRResult,
SSORPreconditioner,
SVDOptions,
SVDResult,
ScaledIdentityOperator,
TFQMROptions,
TFQMRResult,
};
pub mod convert;
pub mod construct;
pub mod construct_sym;
pub mod combine;
pub use combine::{block_diag, bmat, hstack, kron, kronsum, tril, triu, vstack};
pub mod index_dtype;
pub use index_dtype::{can_cast_safely, get_index_dtype, safely_cast_index_arrays};
pub mod sym_ops;
pub mod tensor_sparse;
pub mod bsr_enhanced;
pub use bsr_enhanced::{block_lu, block_lu_solve, BlockLUResult, EnhancedBsr};
pub mod dia_enhanced;
pub use dia_enhanced::{banded_solve, dia_tridiagonal_solve, tridiagonal_solve, EnhancedDia};
pub mod csf_tensor;
pub use csf_tensor::CsfTensor;
pub mod formats;
pub use formats::csf::CsfTensor as CsfTensorStandalone;
pub use formats::csr5::Csr5Matrix;
pub use formats::poly_precond::{
ChebyshevPreconditioner, NeumannPreconditioner as NeumannPreconditionerPoly, PolyPrecondConfig,
};
pub use formats::sell::SellMatrix;
pub mod sparse_functions;
pub use sparse_functions::{
sparse_block_diag, sparse_diag_matrix, sparse_diags, sparse_eye, sparse_eye_rect,
sparse_hstack, sparse_kron, sparse_kronsum, sparse_random, sparse_vstack,
};
pub use sym_ops::{
sym_coo_matvec, sym_csr_matvec, sym_csr_quadratic_form, sym_csr_rank1_update, sym_csr_trace,
};
pub use tensor_sparse::{khatri_rao_product, CPDecomposition, SparseTensor, TuckerDecomposition};
pub mod gpu;
pub mod gpu_kernel_execution;
pub mod gpu_ops;
pub mod gpu_preconditioner;
pub mod gpu_spmv_implementation;
pub use gpu_kernel_execution::{
calculate_adaptive_workgroup_size, execute_spmv_kernel, execute_symmetric_spmv_kernel,
execute_triangular_solve_kernel, GpuKernelConfig, GpuMemoryManager as GpuKernelMemoryManager,
GpuPerformanceProfiler, MemoryStrategy,
};
pub use gpu_ops::{
gpu_sparse_matvec, gpu_sym_sparse_matvec, AdvancedGpuOps, GpuKernelScheduler, GpuMemoryManager,
GpuOptions, GpuProfiler, OptimizedGpuOps,
};
pub use gpu_spmv_implementation::GpuSpMV;
pub mod memory_efficient;
pub use memory_efficient::{
streaming_sparse_matvec, CacheAwareOps, MemoryPool, MemoryTracker, OutOfCoreProcessor,
};
pub mod simd_ops;
pub use simd_ops::{
simd_csr_matvec, simd_sparse_elementwise, simd_sparse_linear_combination, simd_sparse_matmul,
simd_sparse_norm, simd_sparse_scale, simd_sparse_transpose, ElementwiseOp, SimdOptions,
};
pub mod parallel_vector_ops;
pub use parallel_vector_ops::{
advanced_sparse_matvec_csr, parallel_axpy, parallel_dot, parallel_linear_combination,
parallel_norm2, parallel_sparse_matvec_csr, parallel_vector_add, parallel_vector_copy,
parallel_vector_scale, parallel_vector_sub, ParallelVectorOptions,
};
pub mod iterative_solvers;
pub use iterative_solvers::{
bicgstab as enhanced_bicgstab,
cg as enhanced_cg,
chebyshev,
estimate_spectral_radius,
gmres as enhanced_gmres,
sparse_diagonal,
sparse_norm,
sparse_trace,
ILU0Preconditioner as EnhancedILU0Preconditioner,
IterativeSolverConfig,
JacobiPreconditioner as EnhancedJacobiPreconditioner,
NormType,
Preconditioner,
SSORPreconditioner as EnhancedSSORPreconditioner,
SolverResult,
};
pub mod lobpcg;
pub use lobpcg::{
lobpcg as lobpcg_eigensolver, lobpcg_generalised, EigenTarget, LobpcgConfig, LobpcgResult,
};
pub mod krylov;
pub use krylov::{
iram as krylov_iram, thick_restart_lanczos, IramConfig, KrylovEigenResult,
ThickRestartLanczosConfig, WhichEigenvalues,
};
pub mod sparse_utils;
pub use sparse_utils::{
condest_1norm, permute_matrix, reverse_cuthill_mckee, sparse_add, sparse_extract_diagonal,
sparse_identity, sparse_kronecker, sparse_matrix_norm, sparse_matrix_trace, sparse_scale,
sparse_sub, sparse_transpose, spgemm, RcmResult, SparseNorm,
};
pub mod incomplete_factorizations;
pub use incomplete_factorizations::{Ic0, Ilu0 as Ilu0Enhanced, IluK, Ilut, IlutConfig, Milu};
pub mod direct_solver;
pub use direct_solver::{
amd_ordering, elimination_tree, inverse_perm, nested_dissection_ordering,
sparse_cholesky_solve, sparse_lu_solve, symbolic_cholesky, SparseCholResult,
SparseCholeskySolver, SparseLuResult, SparseLuSolver, SparseSolver, SymbolicAnalysis,
};
pub mod sparse_qr;
pub use sparse_qr::{
apply_q, apply_qt, extract_q_dense, numerical_rank, sparse_least_squares,
sparse_qr as sparse_qr_factorize, SparseLeastSquaresResult, SparseQrConfig, SparseQrResult,
};
pub mod reorder;
pub use reorder::{
amd, amd_simple, apply_permutation as reorder_apply_permutation, apply_permutation_csr_array,
bandwidth as reorder_bandwidth, cuthill_mckee, cuthill_mckee_full, distance2_color,
dsatur_color, greedy_color, nested_dissection, nested_dissection_full,
nested_dissection_with_config, profile as reorder_profile,
reverse_cuthill_mckee as reorder_rcm, reverse_cuthill_mckee_full, verify_coloring,
verify_distance2_coloring, AdjacencyGraph, AmdResult, ColoringResult, CuthillMcKeeResult,
GreedyOrdering, NestedDissectionConfig, NestedDissectionResult,
};
pub mod sparse_eigen;
pub use sparse_eigen::{
cayley_transform_matvec, check_eigenpairs, compute_residuals, shift_invert_eig, sparse_eig,
sparse_eigs, sparse_eigsh, EigenMethod, EigenvalueTarget, SparseEigenConfig, SparseEigenResult,
SpectralTransform,
};
pub mod quantum_inspired_sparse;
pub use quantum_inspired_sparse::{
QuantumProcessorStats, QuantumSparseConfig, QuantumSparseProcessor, QuantumStrategy,
};
pub mod neural_adaptive_sparse;
pub use neural_adaptive_sparse::{
NeuralAdaptiveConfig, NeuralAdaptiveSparseProcessor, NeuralProcessorStats, OptimizationStrategy,
};
pub mod quantum_neural_hybrid;
pub use quantum_neural_hybrid::{
HybridStrategy, QuantumNeuralConfig, QuantumNeuralHybridProcessor, QuantumNeuralHybridStats,
};
pub mod adaptive_memory_compression;
pub use adaptive_memory_compression::{
AdaptiveCompressionConfig, AdaptiveMemoryCompressor, CompressedMatrix, CompressionAlgorithm,
MemoryStats,
};
pub mod realtime_performance_monitor;
pub use realtime_performance_monitor::{
Alert, AlertSeverity, PerformanceMonitorConfig, PerformanceSample, ProcessorType,
RealTimePerformanceMonitor,
};
pub mod cholesky_update;
pub mod distributed;
pub mod learned_smoother;
pub mod low_rank_update;
pub mod ml_preconditioner;
pub mod parallel_amg;
pub mod csgraph;
pub use csgraph::{
all_pairs_shortest_path,
bellman_ford_single_source,
betweenness_centrality,
bfs_distances,
breadth_first_search,
closeness_centrality,
community_detection,
compute_laplacianmatrix,
connected_components,
degree_matrix,
depth_first_search,
dijkstra_single_source,
dinic,
edmonds_karp,
eigenvector_centrality,
floyd_warshall,
ford_fulkerson,
has_path,
is_connected,
is_laplacian,
is_spanning_tree,
kruskal_mst,
label_propagation,
laplacian,
largest_component,
louvain_communities,
min_cut,
minimum_spanning_tree,
modularity,
num_edges,
num_vertices,
pagerank,
prim_mst,
reachable_vertices,
reconstruct_path,
shortest_path,
single_source_shortest_path,
spanning_tree_weight,
strongly_connected_components,
to_adjacency_list,
topological_sort,
traversegraph,
undirected_connected_components,
validate_graph,
weakly_connected_components,
LaplacianType,
MSTAlgorithm,
MaxFlowResult,
ShortestPathMethod,
TraversalOrder,
};
pub struct SparseEfficiencyWarning;
pub struct SparseWarning;
#[allow(dead_code)]
pub fn is_sparse_array<T>(obj: &dyn SparseArray<T>) -> bool
where
T: scirs2_core::SparseElement + std::ops::Div<Output = T> + PartialOrd + 'static,
{
sparray::is_sparse(obj)
}
#[allow(dead_code)]
pub fn is_sym_sparse_array<T>(obj: &dyn SymSparseArray<T>) -> bool
where
T: scirs2_core::SparseElement
+ std::ops::Div<Output = T>
+ scirs2_core::Float
+ PartialOrd
+ 'static,
{
obj.is_symmetric()
}
#[allow(dead_code)]
pub fn is_sparse_matrix(obj: &dyn std::any::Any) -> bool {
obj.is::<CsrMatrix<f64>>()
|| obj.is::<CscMatrix<f64>>()
|| obj.is::<CooMatrix<f64>>()
|| obj.is::<DokMatrix<f64>>()
|| obj.is::<LilMatrix<f64>>()
|| obj.is::<DiaMatrix<f64>>()
|| obj.is::<BsrMatrix<f64>>()
|| obj.is::<SymCsrMatrix<f64>>()
|| obj.is::<SymCooMatrix<f64>>()
|| obj.is::<CsrMatrix<f32>>()
|| obj.is::<CscMatrix<f32>>()
|| obj.is::<CooMatrix<f32>>()
|| obj.is::<DokMatrix<f32>>()
|| obj.is::<LilMatrix<f32>>()
|| obj.is::<DiaMatrix<f32>>()
|| obj.is::<BsrMatrix<f32>>()
|| obj.is::<SymCsrMatrix<f32>>()
|| obj.is::<SymCooMatrix<f32>>()
}
#[cfg(test)]
mod tests {
use super::*;
use approx::assert_relative_eq;
#[test]
fn test_csr_array() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let array =
CsrArray::from_triplets(&rows, &cols, &data, shape, false).expect("Operation failed");
assert_eq!(array.shape(), (3, 3));
assert_eq!(array.nnz(), 5);
assert!(is_sparse_array(&array));
}
#[test]
fn test_coo_array() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let array =
CooArray::from_triplets(&rows, &cols, &data, shape, false).expect("Operation failed");
assert_eq!(array.shape(), (3, 3));
assert_eq!(array.nnz(), 5);
assert!(is_sparse_array(&array));
}
#[test]
fn test_dok_array() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let array = DokArray::from_triplets(&rows, &cols, &data, shape).expect("Operation failed");
assert_eq!(array.shape(), (3, 3));
assert_eq!(array.nnz(), 5);
assert!(is_sparse_array(&array));
let mut array = DokArray::<f64>::new((2, 2));
array.set(0, 0, 1.0).expect("Operation failed");
array.set(1, 1, 2.0).expect("Operation failed");
assert_eq!(array.get(0, 0), 1.0);
assert_eq!(array.get(0, 1), 0.0);
assert_eq!(array.get(1, 1), 2.0);
array.set(0, 0, 0.0).expect("Operation failed");
assert_eq!(array.nnz(), 1);
}
#[test]
fn test_lil_array() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 2, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let array = LilArray::from_triplets(&rows, &cols, &data, shape).expect("Operation failed");
assert_eq!(array.shape(), (3, 3));
assert_eq!(array.nnz(), 5);
assert!(is_sparse_array(&array));
let mut array = LilArray::<f64>::new((2, 2));
array.set(0, 0, 1.0).expect("Operation failed");
array.set(1, 1, 2.0).expect("Operation failed");
assert_eq!(array.get(0, 0), 1.0);
assert_eq!(array.get(0, 1), 0.0);
assert_eq!(array.get(1, 1), 2.0);
assert!(array.has_sorted_indices());
array.set(0, 0, 0.0).expect("Operation failed");
assert_eq!(array.nnz(), 1);
}
#[test]
fn test_dia_array() {
use scirs2_core::ndarray::Array1;
let data = vec![
Array1::from_vec(vec![1.0, 2.0, 3.0]), Array1::from_vec(vec![4.0, 5.0, 0.0]), ];
let offsets = vec![0, 1]; let shape = (3, 3);
let array = DiaArray::new(data, offsets, shape).expect("Operation failed");
assert_eq!(array.shape(), (3, 3));
assert_eq!(array.nnz(), 5); assert!(is_sparse_array(&array));
assert_eq!(array.get(0, 0), 1.0);
assert_eq!(array.get(1, 1), 2.0);
assert_eq!(array.get(2, 2), 3.0);
assert_eq!(array.get(0, 1), 4.0);
assert_eq!(array.get(1, 2), 5.0);
assert_eq!(array.get(0, 2), 0.0);
let rows = vec![0, 0, 1, 1, 2];
let cols = vec![0, 1, 1, 2, 2];
let data_vec = vec![1.0, 4.0, 2.0, 5.0, 3.0];
let array2 =
DiaArray::from_triplets(&rows, &cols, &data_vec, shape).expect("Operation failed");
assert_eq!(array2.get(0, 0), 1.0);
assert_eq!(array2.get(1, 1), 2.0);
assert_eq!(array2.get(2, 2), 3.0);
assert_eq!(array2.get(0, 1), 4.0);
assert_eq!(array2.get(1, 2), 5.0);
let csr = array.to_csr().expect("Operation failed");
assert_eq!(csr.nnz(), 5);
assert_eq!(csr.get(0, 0), 1.0);
assert_eq!(csr.get(0, 1), 4.0);
}
#[test]
fn test_format_conversions() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 1, 0, 2];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let coo =
CooArray::from_triplets(&rows, &cols, &data, shape, false).expect("Operation failed");
let csr = coo.to_csr().expect("Operation failed");
let coo_dense = coo.to_array();
let csr_dense = csr.to_array();
for i in 0..shape.0 {
for j in 0..shape.1 {
assert_relative_eq!(coo_dense[[i, j]], csr_dense[[i, j]]);
}
}
}
#[test]
fn test_dot_product() {
let rows = vec![0, 0, 1, 2, 2];
let cols = vec![0, 2, 1, 0, 2];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let shape = (3, 3);
let coo =
CooArray::from_triplets(&rows, &cols, &data, shape, false).expect("Operation failed");
let csr =
CsrArray::from_triplets(&rows, &cols, &data, shape, false).expect("Operation failed");
let coo_result = coo.dot(&coo).expect("Operation failed");
let csr_result = csr.dot(&csr).expect("Operation failed");
let coo_dense = coo_result.to_array();
let csr_dense = csr_result.to_array();
for i in 0..shape.0 {
for j in 0..shape.1 {
assert_relative_eq!(coo_dense[[i, j]], csr_dense[[i, j]], epsilon = 1e-10);
}
}
}
#[test]
fn test_sym_csr_array() {
let data = vec![2.0, 1.0, 2.0, 3.0, 0.0, 3.0, 1.0];
let indices = vec![0, 0, 1, 2, 0, 1, 2];
let indptr = vec![0, 1, 3, 7];
let sym_matrix =
SymCsrMatrix::new(data, indptr, indices, (3, 3)).expect("Operation failed");
let sym_array = SymCsrArray::new(sym_matrix);
assert_eq!(sym_array.shape(), (3, 3));
assert!(is_sym_sparse_array(&sym_array));
assert_eq!(SparseArray::get(&sym_array, 0, 0), 2.0);
assert_eq!(SparseArray::get(&sym_array, 0, 1), 1.0);
assert_eq!(SparseArray::get(&sym_array, 1, 0), 1.0); assert_eq!(SparseArray::get(&sym_array, 1, 2), 3.0);
assert_eq!(SparseArray::get(&sym_array, 2, 1), 3.0);
let csr = SymSparseArray::to_csr(&sym_array).expect("Operation failed");
assert_eq!(csr.nnz(), 10); }
#[test]
fn test_sym_coo_array() {
let data = vec![2.0, 1.0, 2.0, 3.0, 1.0];
let rows = vec![0, 1, 1, 2, 2];
let cols = vec![0, 0, 1, 1, 2];
let sym_matrix = SymCooMatrix::new(data, rows, cols, (3, 3)).expect("Operation failed");
let sym_array = SymCooArray::new(sym_matrix);
assert_eq!(sym_array.shape(), (3, 3));
assert!(is_sym_sparse_array(&sym_array));
assert_eq!(SparseArray::get(&sym_array, 0, 0), 2.0);
assert_eq!(SparseArray::get(&sym_array, 0, 1), 1.0);
assert_eq!(SparseArray::get(&sym_array, 1, 0), 1.0); assert_eq!(SparseArray::get(&sym_array, 1, 2), 3.0);
assert_eq!(SparseArray::get(&sym_array, 2, 1), 3.0);
let rows2 = vec![0, 0, 1, 1, 2, 1, 0];
let cols2 = vec![0, 1, 1, 2, 2, 0, 2];
let data2 = vec![2.0, 1.5, 2.0, 3.5, 1.0, 0.5, 0.0];
let sym_array2 = SymCooArray::from_triplets(&rows2, &cols2, &data2, (3, 3), true)
.expect("Operation failed");
assert_eq!(SparseArray::get(&sym_array2, 0, 1), 1.0); assert_eq!(SparseArray::get(&sym_array2, 1, 0), 1.0); assert_eq!(SparseArray::get(&sym_array2, 0, 2), 0.0); }
#[test]
fn test_construct_sym_utils() {
let eye = construct_sym::eye_sym_array::<f64>(3, "csr").expect("Operation failed");
assert_eq!(eye.shape(), (3, 3));
assert_eq!(SparseArray::get(&*eye, 0, 0), 1.0);
assert_eq!(SparseArray::get(&*eye, 1, 1), 1.0);
assert_eq!(SparseArray::get(&*eye, 2, 2), 1.0);
assert_eq!(SparseArray::get(&*eye, 0, 1), 0.0);
let diag = vec![2.0, 2.0, 2.0];
let offdiag = vec![1.0, 1.0];
let tri =
construct_sym::tridiagonal_sym_array(&diag, &offdiag, "coo").expect("Operation failed");
assert_eq!(tri.shape(), (3, 3));
assert_eq!(SparseArray::get(&*tri, 0, 0), 2.0); assert_eq!(SparseArray::get(&*tri, 1, 1), 2.0);
assert_eq!(SparseArray::get(&*tri, 2, 2), 2.0);
assert_eq!(SparseArray::get(&*tri, 0, 1), 1.0); assert_eq!(SparseArray::get(&*tri, 1, 0), 1.0); assert_eq!(SparseArray::get(&*tri, 1, 2), 1.0);
assert_eq!(SparseArray::get(&*tri, 0, 2), 0.0);
let diagonals = vec![
vec![2.0, 2.0, 2.0, 2.0, 2.0], vec![1.0, 1.0, 1.0, 1.0], vec![0.5, 0.5, 0.5], ];
let band = construct_sym::banded_sym_array(&diagonals, 5, "csr").expect("Operation failed");
assert_eq!(band.shape(), (5, 5));
assert_eq!(SparseArray::get(&*band, 0, 0), 2.0);
assert_eq!(SparseArray::get(&*band, 0, 1), 1.0);
assert_eq!(SparseArray::get(&*band, 0, 2), 0.5);
assert_eq!(SparseArray::get(&*band, 2, 0), 0.5); }
#[test]
fn test_sym_conversions() {
let data = vec![2.0, 1.0, 2.0, 3.0, 1.0];
let rows = vec![0, 1, 1, 2, 2];
let cols = vec![0, 0, 1, 1, 2];
let sym_coo = SymCooArray::from_triplets(&rows, &cols, &data, (3, 3), true)
.expect("Operation failed");
let sym_csr = sym_coo.to_sym_csr().expect("Operation failed");
for i in 0..3 {
for j in 0..3 {
assert_eq!(
SparseArray::get(&sym_coo, i, j),
SparseArray::get(&sym_csr, i, j)
);
}
}
let csr = SymSparseArray::to_csr(&sym_coo).expect("Operation failed");
let coo = SymSparseArray::to_coo(&sym_csr).expect("Operation failed");
assert_eq!(csr.nnz(), 7); assert_eq!(coo.nnz(), 7);
for i in 0..3 {
for j in 0..3 {
assert_eq!(SparseArray::get(&csr, i, j), SparseArray::get(&coo, i, j));
assert_eq!(
SparseArray::get(&csr, i, j),
SparseArray::get(&sym_csr, i, j)
);
}
}
}
}