Skip to content

Commit 68d95e3

Browse files
committed
Implement determinant for Hermite
1 parent 38e1ca3 commit 68d95e3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/hermite.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use ndarray::{Ix2, Array, LinalgScalar};
44
use std::fmt::Debug;
55
use num_traits::float::Float;
6+
use num_traits::One;
67
use lapack::c::Layout;
78

89
use matrix::Matrix;
@@ -23,10 +24,12 @@ pub trait HermiteMatrix: SquareMatrix + Matrix {
2324
fn ssqrt(self) -> Result<Self, LinalgError>;
2425
/// Cholesky factorization
2526
fn cholesky(self) -> Result<Self, LinalgError>;
27+
/// calc determinant using Cholesky factorization
28+
fn deth(self) -> Result<Self::Scalar, LinalgError>;
2629
}
2730

2831
impl<A> HermiteMatrix for Array<A, Ix2>
29-
where A: ImplQR + ImplSVD + ImplNorm + ImplSolve + ImplEigh + ImplCholesky + LinalgScalar + Float + Debug
32+
where A: ImplQR + ImplSVD + ImplNorm + ImplSolve + ImplEigh + ImplCholesky + LinalgScalar + Float + Debug + One
3033
{
3134
fn eigh(self) -> Result<(Self::Vector, Self), LinalgError> {
3235
self.check_square()?;
@@ -67,4 +70,10 @@ impl<A> HermiteMatrix for Array<A, Ix2>
6770
}
6871
Ok(c)
6972
}
73+
fn deth(self) -> Result<Self::Scalar, LinalgError> {
74+
let (n, _) = self.size();
75+
let c = self.cholesky()?;
76+
let rt = (0..n).map(|i| c[(i, i)]).fold(A::one(), |det, c| det * c);
77+
Ok(rt * rt)
78+
}
7079
}

0 commit comments

Comments
 (0)