Added check for symmetricity of input matrix
This commit is contained in:
parent
b197959e2b
commit
dc571838bb
|
@ -127,7 +127,11 @@ pub fn cholesky<N, V, VS, M>(m: &M) -> Result<M, &'static str>
|
||||||
Sub<M, Output = M> + ColSlice<VS> +
|
Sub<M, Output = M> + ColSlice<VS> +
|
||||||
ApproxEq<N> + Copy {
|
ApproxEq<N> + Copy {
|
||||||
|
|
||||||
let mut out = m.clone();
|
let mut out = m.clone().transpose();
|
||||||
|
|
||||||
|
if !ApproxEq::approx_eq(&out, &m) {
|
||||||
|
return Err("Cholesky: Input matrix is not symmetric");
|
||||||
|
}
|
||||||
|
|
||||||
for i in 0..out.nrows() {
|
for i in 0..out.nrows() {
|
||||||
for j in 0..(i+1) {
|
for j in 0..(i+1) {
|
||||||
|
|
13
tests/mat.rs
13
tests/mat.rs
|
@ -658,6 +658,19 @@ fn test_cholesky_not_spd() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cholesky_not_symmetric() {
|
||||||
|
|
||||||
|
let a : Mat2<f64> = Mat2::<f64>::new(1.0, 1.0, -1.0, 1.0);
|
||||||
|
|
||||||
|
let result = na::cholesky(&a);
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(_) => assert!(false),
|
||||||
|
Err(_) => assert!(true),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cholesky_mat1() {
|
fn test_cholesky_mat1() {
|
||||||
test_cholesky_impl!(Mat1<f64>);
|
test_cholesky_impl!(Mat1<f64>);
|
||||||
|
|
Loading…
Reference in New Issue