fix for empty dense matrix
This commit is contained in:
parent
92b324c007
commit
656180f40e
|
@ -1072,17 +1072,6 @@ fn parse_dense_shape(
|
||||||
let mut inner = shape_inner.into_inner();
|
let mut inner = shape_inner.into_inner();
|
||||||
let r = inner.next().unwrap().as_str().parse::<usize>().unwrap();
|
let r = inner.next().unwrap().as_str().parse::<usize>().unwrap();
|
||||||
let c = inner.next().unwrap().as_str().parse::<usize>().unwrap();
|
let c = inner.next().unwrap().as_str().parse::<usize>().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
|
// check for square matrix, when it's not a general matrix
|
||||||
if *storagescheme != StorageScheme::General && r != c {
|
if *storagescheme != StorageScheme::General && r != c {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use nalgebra_sparse::CooMatrix;
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn test_matrixmarket_sparse_real_general_empty() {
|
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 shapes = vec![ (0, 0), (1, 0), (0, 1) ];
|
||||||
let strings: Vec<String> = shapes
|
let strings: Vec<String> = shapes
|
||||||
.iter()
|
.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<String> = 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::<f32>(string).unwrap();
|
||||||
|
assert_eq!(sparse_mat.nrows(), shape.0);
|
||||||
|
assert_eq!(sparse_mat.ncols(), shape.1);
|
||||||
|
assert_eq!(sparse_mat.nnz(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn test_matrixmarket_sparse_real_general() {
|
fn test_matrixmarket_sparse_real_general() {
|
||||||
|
|
Loading…
Reference in New Issue