Added check for symmetricity of input matrix

This commit is contained in:
Daniel 2015-08-07 15:03:38 +02:00
parent b197959e2b
commit dc571838bb
2 changed files with 18 additions and 1 deletions

View File

@ -127,7 +127,11 @@ pub fn cholesky<N, V, VS, M>(m: &M) -> Result<M, &'static str>
Sub<M, Output = M> + ColSlice<VS> +
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 j in 0..(i+1) {

View File

@ -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]
fn test_cholesky_mat1() {
test_cholesky_impl!(Mat1<f64>);