File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 3
3
use ndarray:: { Ix2 , Array , LinalgScalar } ;
4
4
use std:: fmt:: Debug ;
5
5
use num_traits:: float:: Float ;
6
+ use num_traits:: One ;
6
7
use lapack:: c:: Layout ;
7
8
8
9
use matrix:: Matrix ;
@@ -23,10 +24,12 @@ pub trait HermiteMatrix: SquareMatrix + Matrix {
23
24
fn ssqrt ( self ) -> Result < Self , LinalgError > ;
24
25
/// Cholesky factorization
25
26
fn cholesky ( self ) -> Result < Self , LinalgError > ;
27
+ /// calc determinant using Cholesky factorization
28
+ fn deth ( self ) -> Result < Self :: Scalar , LinalgError > ;
26
29
}
27
30
28
31
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
30
33
{
31
34
fn eigh ( self ) -> Result < ( Self :: Vector , Self ) , LinalgError > {
32
35
self . check_square ( ) ?;
@@ -67,4 +70,10 @@ impl<A> HermiteMatrix for Array<A, Ix2>
67
70
}
68
71
Ok ( c)
69
72
}
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
+ }
70
79
}
You can’t perform that action at this time.
0 commit comments