From a2422ee02bd963334b27f116655429e17a49c7d4 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 12 Mar 2022 15:03:13 -0700 Subject: [PATCH] filter out only matrix files --- nalgebra-sparse/example/spmm.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/nalgebra-sparse/example/spmm.rs b/nalgebra-sparse/example/spmm.rs index aa4eb473..2be64735 100644 --- a/nalgebra-sparse/example/spmm.rs +++ b/nalgebra-sparse/example/spmm.rs @@ -10,19 +10,23 @@ use nalgebra_sparse::io::load_coo_from_matrix_market_file; fn main() { #[cfg(feature = "io")] { - let mut file_iter = fs::read_dir("./data").unwrap(); + let mut file_iter = fs::read_dir("data").unwrap(); for f in file_iter { println!("Benchmark file {:?}", f); let f = f.unwrap().path(); - let sparse_input_matrix = load_coo_from_matrix_market_file::(&f).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); + + if f.extension().map_or(false, |ext| ext == "mtx") { + println!("Benchmark file {:?}", f); + let sparse_input_matrix = load_coo_from_matrix_market_file::(&f).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"))]