mirror of
https://github.com/drewcassidy/vector-victor.git
synced 2024-09-01 14:58:35 +00:00
Fix Solve and add unit tests on an identity matrix
This commit is contained in:
51
tests/ops.rs
51
tests/ops.rs
@ -1,10 +1,9 @@
|
||||
use generic_parameterize::parameterize;
|
||||
use std::convert::identity;
|
||||
use num_traits::real::Real;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::{Product, Sum};
|
||||
use std::ops;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use vector_victor::Matrix;
|
||||
use vector_victor::{Matrix, Vector};
|
||||
|
||||
#[parameterize(S = (i32, f32, u32), M = [1,4], N = [1,4])]
|
||||
#[test]
|
||||
@ -20,10 +19,46 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[parameterize(S = (f32, f64), M = [1,2,3,4])]
|
||||
#[test]
|
||||
fn test_lu() {
|
||||
fn test_lu_identity<S: Default + Real + Debug + Product + Sum, const M: usize>() {
|
||||
// let a: Matrix<f32, 3, 3> = Matrix::<f32, 3, 3>::identity();
|
||||
let a = Matrix::new([[1.0, 2.0], [3.0, 4.0]]);
|
||||
let (lu, _idx, _d) = a.lu().expect("What");
|
||||
println!("{:?}", lu);
|
||||
let i = Matrix::<S, M, M>::identity();
|
||||
let ones = Vector::<S, M>::fill(S::one());
|
||||
let (lu, idx, d) = i.lu().expect("Singular matrix encountered");
|
||||
assert_eq!(
|
||||
lu,
|
||||
i,
|
||||
"Incorrect LU decomposition matrix for {m}x{m} identity matrix",
|
||||
m = M
|
||||
);
|
||||
assert!(
|
||||
(0..M).eq(idx.elements().cloned()),
|
||||
"Incorrect permutation matrix result for {m}x{m} identity matrix",
|
||||
m = M
|
||||
);
|
||||
assert_eq!(
|
||||
d,
|
||||
S::one(),
|
||||
"Incorrect permutation parity for {m}x{m} identity matrix",
|
||||
m = M
|
||||
);
|
||||
assert_eq!(
|
||||
i.det(),
|
||||
S::one(),
|
||||
"Incorrect determinant for {m}x{m} identity matrix",
|
||||
m = M
|
||||
);
|
||||
assert_eq!(
|
||||
i.inverse(),
|
||||
Some(i),
|
||||
"Incorrect inverse for {m}x{m} identity matrix",
|
||||
m = M
|
||||
);
|
||||
assert_eq!(
|
||||
i.solve(&ones),
|
||||
Some(ones),
|
||||
"Incorrect solve result for {m}x{m} identity matrix",
|
||||
m = M
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user