2020-09-23 15:34:19 +08:00
|
|
|
use nalgebra_sparse::coo::CooMatrix;
|
2020-07-14 00:44:40 +08:00
|
|
|
use nalgebra_sparse::ops::spmv_coo;
|
2020-11-23 22:58:02 +08:00
|
|
|
use nalgebra::{DVector, DMatrix};
|
2020-07-14 00:44:40 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn spmv_coo_agrees_with_dense_gemv() {
|
|
|
|
let x = DVector::from_column_slice(&[2, 3, 4, 5]);
|
|
|
|
|
|
|
|
let i = vec![0, 0, 1, 1, 2, 2];
|
|
|
|
let j = vec![0, 3, 0, 1, 1, 3];
|
|
|
|
let v = vec![3, 2, 1, 2, 3, 1];
|
|
|
|
let a = CooMatrix::try_from_triplets(3, 4, i, j, v).unwrap();
|
|
|
|
|
|
|
|
let betas = [0, 1, 2];
|
|
|
|
let alphas = [0, 1, 2];
|
|
|
|
|
|
|
|
for &beta in &betas {
|
|
|
|
for &alpha in &alphas {
|
|
|
|
let mut y = DVector::from_column_slice(&[2, 5, 3]);
|
|
|
|
let mut y_dense = y.clone();
|
|
|
|
spmv_coo(beta, &mut y, alpha, &a, &x);
|
|
|
|
|
2020-11-23 22:58:02 +08:00
|
|
|
y_dense.gemv(alpha, &DMatrix::from(&a), &x, beta);
|
2020-07-14 00:44:40 +08:00
|
|
|
|
|
|
|
assert_eq!(y, y_dense);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|