Merge pull request #861 from jturner314/fix-cholesky-det-complex
Fix Cholesky::determinant for complex elements
This commit is contained in:
commit
2ebba30117
@ -140,13 +140,13 @@ where
|
||||
}
|
||||
|
||||
/// Computes the determinant of the decomposed matrix.
|
||||
pub fn determinant(&self) -> N {
|
||||
pub fn determinant(&self) -> N::SimdRealField {
|
||||
let dim = self.chol.nrows();
|
||||
let mut prod_diag = N::one();
|
||||
for i in 0..dim {
|
||||
prod_diag *= unsafe { *self.chol.get_unchecked((i, i)) };
|
||||
}
|
||||
prod_diag * prod_diag
|
||||
prod_diag.simd_modulus_squared()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ macro_rules! gen_tests(
|
||||
use na::dimension::{U4, Dynamic};
|
||||
use na::{DMatrix, DVector, Matrix4x3, Vector4};
|
||||
use rand::random;
|
||||
use simba::scalar::ComplexField;
|
||||
#[allow(unused_imports)]
|
||||
use crate::core::helper::{RandScalar, RandComplex};
|
||||
|
||||
@ -83,18 +84,20 @@ macro_rules! gen_tests(
|
||||
fn cholesky_determinant(n in PROPTEST_MATRIX_DIM) {
|
||||
let m = RandomSDP::new(Dynamic::new(n), || random::<$scalar>().0).unwrap();
|
||||
let lu_det = m.clone().lu().determinant();
|
||||
assert_relative_eq!(lu_det.imaginary(), 0., epsilon = 1.0e-7);
|
||||
let chol_det = m.cholesky().unwrap().determinant();
|
||||
|
||||
prop_assert!(relative_eq!(lu_det, chol_det, epsilon = 1.0e-7));
|
||||
prop_assert!(relative_eq!(lu_det.real(), chol_det, epsilon = 1.0e-7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cholesky_determinant_static(_n in PROPTEST_MATRIX_DIM) {
|
||||
let m = RandomSDP::new(U4, || random::<$scalar>().0).unwrap();
|
||||
let lu_det = m.clone().lu().determinant();
|
||||
assert_relative_eq!(lu_det.imaginary(), 0., epsilon = 1.0e-7);
|
||||
let chol_det = m.cholesky().unwrap().determinant();
|
||||
|
||||
prop_assert!(relative_eq!(lu_det, chol_det, epsilon = 1.0e-7));
|
||||
prop_assert!(relative_eq!(lu_det.real(), chol_det, epsilon = 1.0e-7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user