filter out only matrix files

This commit is contained in:
Saurabh 2022-03-12 15:03:13 -07:00
parent 424207914b
commit a2422ee02b
1 changed files with 14 additions and 10 deletions

View File

@ -10,19 +10,23 @@ use nalgebra_sparse::io::load_coo_from_matrix_market_file;
fn main() { fn main() {
#[cfg(feature = "io")] #[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 { for f in file_iter {
println!("Benchmark file {:?}", f); println!("Benchmark file {:?}", f);
let f = f.unwrap().path(); let f = f.unwrap().path();
let sparse_input_matrix = load_coo_from_matrix_market_file::<f64, _>(&f).unwrap();
let sparse_input_matrix = CsrMatrix::from(&sparse_input_matrix); if f.extension().map_or(false, |ext| ext == "mtx") {
let spmm_result = &sparse_input_matrix * &sparse_input_matrix; println!("Benchmark file {:?}", f);
let now = Instant::now(); let sparse_input_matrix = load_coo_from_matrix_market_file::<f64, _>(&f).unwrap();
let spmm_result = &sparse_input_matrix * &sparse_input_matrix; let sparse_input_matrix = CsrMatrix::from(&sparse_input_matrix);
let spmm_time = now.elapsed().as_millis(); let spmm_result = &sparse_input_matrix * &sparse_input_matrix;
println!("SGEMM time was {}", spmm_time); let now = Instant::now();
let sum: f64 = spmm_result.triplet_iter().map(|(_, _, v)| v).sum(); let spmm_result = &sparse_input_matrix * &sparse_input_matrix;
println!("sum of product is {}", sum); 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"))] #[cfg(not(feature = "io"))]