serialize_sparse_matrix

Function serialize_sparse_matrix 

Source
pub fn serialize_sparse_matrix<P, A>(
    path: P,
    matrix: &SparseMatrixCOO<A>,
    format: SerializationFormat,
) -> Result<()>
where P: AsRef<Path>, A: Serialize,
Expand description

Serialize a sparse matrix to a file

§Arguments

  • path - Path to the output file
  • matrix - The sparse matrix to serialize
  • format - Serialization format

§Returns

  • Result<()> - Success or error

§Examples

use scirs2_io::serialize::{serialize_sparse_matrix, SparseMatrixCOO, SerializationFormat};

// Create a sparse matrix
let mut sparse = SparseMatrixCOO::<f64>::new(100, 100);
sparse.push(0, 0, 1.0);
sparse.push(10, 10, 2.0);
sparse.push(50, 50, 3.0);

// Add metadata
sparse.metadata.insert("description".to_string(), "Sparse test matrix".to_string());

// Serialize to file
serialize_sparse_matrix("sparse.json", &sparse, SerializationFormat::JSON).unwrap();