From 46a757fc420a977c66fc0a914e1a23a918117eec Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 26 Feb 2022 18:24:24 -0700 Subject: [PATCH] Added missing example file --- nalgebra-sparse/example/spmm.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 nalgebra-sparse/example/spmm.rs diff --git a/nalgebra-sparse/example/spmm.rs b/nalgebra-sparse/example/spmm.rs new file mode 100644 index 00000000..17ae21d0 --- /dev/null +++ b/nalgebra-sparse/example/spmm.rs @@ -0,0 +1,25 @@ +extern crate nalgebra_sparse; +use nalgebra_sparse::CsrMatrix; +use std::time::{Duration, Instant}; + +#[cfg(feature = "io")] +use nalgebra_sparse::io::load_coo_from_matrix_market_file; +fn main() { + #[cfg(feature = "io")] + { + let sparse_input_matrix = + load_coo_from_matrix_market_file::("./data/crankseg_1.mtx").unwrap(); + let sparse_input_matrix = CsrMatrix::from(&sparse_input_matrix); + let spmm_result = &sparse_input_matrix * &sparse_input_matrix; + let now = Instant::now(); + let spmm_result = &sparse_input_matrix * &sparse_input_matrix; + let spmm_time = now.elapsed().as_millis(); + println!("SGEMM time was {}", spmm_time); + let sum: f64 = spmm_result.triplet_iter().map(|(_, _, v)| v).sum(); + println!("sum of product is {}", sum); + } + #[cfg(not(feature = "io"))] + { + panic!("Run with IO feature only"); + } +}