| 1 |
#![cfg_attr(rustfmt, rustfmt_skip)] |
| 2 |
|
| 3 |
|
| 4 |
use na::io; |
| 5 |
use na::DMatrix; |
| 6 |
|
| 7 |
#[test] |
| 8 |
fn cs_matrix_market() { |
| 9 |
let file_str = r#" |
| 10 |
%%MatrixMarket matrix coordinate real general |
| 11 |
%================================================================================= |
| 12 |
% |
| 13 |
% This ASCII file represents a sparse MxN matrix with L |
| 14 |
% nonzeros in the following Matrix Market format: |
| 15 |
% |
| 16 |
% +----------------------------------------------+ |
| 17 |
% |%%MatrixMarket matrix coordinate real general | <--- header line |
| 18 |
% |% | <--+ |
| 19 |
% |% comments | |-- 0 or more comment lines |
| 20 |
% |% | <--+ |
| 21 |
% | M T L | <--- rows, columns, entries |
| 22 |
% | I1 J1 A(I1, J1) | <--+ |
| 23 |
% | I2 J2 A(I2, J2) | | |
| 24 |
% | I3 J3 A(I3, J3) | |-- L lines |
| 25 |
% | . . . | | |
| 26 |
% | IL JL A(IL, JL) | <--+ |
| 27 |
% +----------------------------------------------+ |
| 28 |
% |
| 29 |
% Indices are 1-based, i.e. A(1,1) is the first element. |
| 30 |
% |
| 31 |
%================================================================================= |
| 32 |
5 5 8 |
| 33 |
1 1 1.000e+00 |
| 34 |
2 2 1.050e+01 |
| 35 |
3 3 1.500e-02 |
| 36 |
1 4 6.000e+00 |
| 37 |
4 2 2.505e+02 |
| 38 |
4 4 -2.800e+02 |
| 39 |
4 5 3.332e+01 |
| 40 |
5 5 1.200e+01 |
| 41 |
"#; |
| 42 |
|
| 43 |
let cs_mat = io::cs_matrix_from_matrix_market_str(file_str).unwrap(); |
| 44 |
let mat: DMatrix<_> = cs_mat.into(); |
| 45 |
let expected = DMatrix::from_row_slice(5, 5, &[ |
| 46 |
1.0, 0.0, 0.0, 6.0, 0.0, |
| 47 |
0.0, 10.5, 0.0, 0.0, 0.0, |
| 48 |
0.0, 0.0, 0.015, 0.0, 0.0, |
| 49 |
0.0, 250.5, 0.0, -280.0, 33.32, |
| 50 |
0.0, 0.0, 0.0, 0.0, 12.0, |
| 51 |
]); |
| 52 |
|
| 53 |
assert_eq!(mat, expected); |
| 54 |
} |