Fix tests for the UDU decomposition.
This commit is contained in:
parent
89ca2fe5fb
commit
ab0d335b61
|
@ -7,7 +7,7 @@ use crate::dimension::Dim;
|
|||
use crate::storage::Storage;
|
||||
use simba::scalar::RealField;
|
||||
|
||||
/// UDU factorization
|
||||
/// UDU factorization.
|
||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde-serialize",
|
||||
|
@ -42,8 +42,11 @@ impl<N: RealField, D: Dim> UDU<N, D>
|
|||
where
|
||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
||||
{
|
||||
/// Computes the UDU^T factorization
|
||||
/// The input matrix `p` is assumed to be symmetric and this decomposition will only read the upper-triangular part of `p`.
|
||||
/// Computes the UDU^T factorization.
|
||||
///
|
||||
/// The input matrix `p` is assumed to be symmetric and this decomposition will only read
|
||||
/// the upper-triangular part of `p`.
|
||||
///
|
||||
/// Ref.: "Optimal control and estimation-Dover Publications", Robert F. Stengel, (1994) page 360
|
||||
pub fn new(p: MatrixN<N, D>) -> Self {
|
||||
let n = p.ncols();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use na::Matrix3;
|
||||
use na::UDU;
|
||||
use na::{Matrix3, UDU};
|
||||
|
||||
#[test]
|
||||
#[rustfmt::skip]
|
||||
|
@ -40,19 +39,14 @@ mod quickcheck_tests {
|
|||
macro_rules! gen_tests(
|
||||
($module: ident, $scalar: ty) => {
|
||||
mod $module {
|
||||
use std::cmp;
|
||||
use na::{DMatrix, Matrix4};
|
||||
use na::{UDU, DMatrix, Matrix4};
|
||||
#[allow(unused_imports)]
|
||||
use crate::core::helper::{RandScalar, RandComplex};
|
||||
|
||||
quickcheck! {
|
||||
fn udu(m: DMatrix<$scalar>) -> bool {
|
||||
let mut m = m;
|
||||
if m.len() == 0 {
|
||||
m = DMatrix::<$scalar>::new_random(1, 1);
|
||||
}
|
||||
|
||||
let m = m.map(|e| e.0);
|
||||
fn udu(n: usize) -> bool {
|
||||
let n = std::cmp::max(1, std::cmp::min(n, 10));
|
||||
let m = DMatrix::<$scalar>::new_random(n, n).map(|e| e.0).hermitian_part();
|
||||
|
||||
let udu = UDU::new(m.clone());
|
||||
let p = &udu.u * &udu.d_matrix() * &udu.u.transpose();
|
||||
|
@ -61,18 +55,17 @@ mod quickcheck_tests {
|
|||
}
|
||||
|
||||
fn udu_static(m: Matrix4<$scalar>) -> bool {
|
||||
let m = m.map(|e| e.0);
|
||||
let m = m.map(|e| e.0).hermitian_part();
|
||||
|
||||
let udu = UDU::new(m.clone());
|
||||
let p = udu.u * udu.d_matrix() * udu.u.transpose();
|
||||
|
||||
relative_eq!(m, p, epsilon = 3.0e-16)
|
||||
relative_eq!(m, p, epsilon = 1.0e-7)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
gen_tests!(complex, RandComplex<f64>);
|
||||
gen_tests!(f64, RandScalar<f64>);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue