From 656180f40ea7670cb3242859fa1c6ad77ddd694e Mon Sep 17 00:00:00 2001 From: Hantao Hui Date: Mon, 13 Dec 2021 09:26:54 +0100 Subject: [PATCH] fix for empty dense matrix --- nalgebra-sparse/src/io/matrix_market.rs | 11 ---------- .../tests/unit_tests/matrix_market.rs | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/nalgebra-sparse/src/io/matrix_market.rs b/nalgebra-sparse/src/io/matrix_market.rs index 2620eea6..446f045d 100644 --- a/nalgebra-sparse/src/io/matrix_market.rs +++ b/nalgebra-sparse/src/io/matrix_market.rs @@ -1072,17 +1072,6 @@ fn parse_dense_shape( let mut inner = shape_inner.into_inner(); let r = inner.next().unwrap().as_str().parse::().unwrap(); let c = inner.next().unwrap().as_str().parse::().unwrap(); - // shape information can't use 0 as dimension - if r * c == 0 { - return Err(MatrixMarketError::from_kind_and_message( - MatrixMarketErrorKind::ZeroError, - String::from( - " - Matrix can't have 0 as shape dimensions. - ", - ), - )); - } // check for square matrix, when it's not a general matrix if *storagescheme != StorageScheme::General && r != c { diff --git a/nalgebra-sparse/tests/unit_tests/matrix_market.rs b/nalgebra-sparse/tests/unit_tests/matrix_market.rs index 58db6e02..48ff1a78 100644 --- a/nalgebra-sparse/tests/unit_tests/matrix_market.rs +++ b/nalgebra-sparse/tests/unit_tests/matrix_market.rs @@ -7,7 +7,7 @@ use nalgebra_sparse::CooMatrix; #[test] #[rustfmt::skip] fn test_matrixmarket_sparse_real_general_empty() { - // Test several valid zero-shapes of a matrix + // Test several valid zero-shapes of a sparse matrix let shapes = vec![ (0, 0), (1, 0), (0, 1) ]; let strings: Vec = shapes .iter() @@ -22,6 +22,24 @@ fn test_matrixmarket_sparse_real_general_empty() { } } +#[test] +#[rustfmt::skip] +fn test_matrixmarket_dense_real_general_empty() { + // Test several valid zero-shapes of a dense matrix + let shapes = vec![ (0, 0), (1, 0), (0, 1) ]; + let strings: Vec = shapes + .iter() + .map(|(m, n)| format!("%%MatrixMarket matrix array real general\n {} {}", m, n)) + .collect(); + + for (shape,string) in shapes.iter().zip(strings.iter()) { + let sparse_mat = load_coo_from_matrix_market_str::(string).unwrap(); + assert_eq!(sparse_mat.nrows(), shape.0); + assert_eq!(sparse_mat.ncols(), shape.1); + assert_eq!(sparse_mat.nnz(), 0); + } +} + #[test] #[rustfmt::skip] fn test_matrixmarket_sparse_real_general() {