@@ -102,12 +102,15 @@ where
102
102
type Output = <A as AssociatedReal >:: Real ;
103
103
104
104
fn detc ( & self ) -> Self :: Output {
105
+ self . ln_detc ( ) . exp ( )
106
+ }
107
+
108
+ fn ln_detc ( & self ) -> Self :: Output {
105
109
self . factor
106
110
. diag ( )
107
111
. iter ( )
108
112
. map ( |elem| elem. abs_sqr ( ) . ln ( ) )
109
113
. sum :: < Self :: Output > ( )
110
- . exp ( )
111
114
}
112
115
}
113
116
@@ -121,6 +124,10 @@ where
121
124
fn detc_into ( self ) -> Self :: Output {
122
125
self . detc ( )
123
126
}
127
+
128
+ fn ln_detc_into ( self ) -> Self :: Output {
129
+ self . ln_detc ( )
130
+ }
124
131
}
125
132
126
133
impl < A , S > InverseC for CholeskyFactorized < S >
@@ -391,6 +398,14 @@ pub trait DeterminantC {
391
398
/// Computes the determinant of the Hermitian (or real symmetric) positive
392
399
/// definite matrix.
393
400
fn detc ( & self ) -> Self :: Output ;
401
+
402
+ /// Computes the natural log of the determinant of the Hermitian (or real
403
+ /// symmetric) positive definite matrix.
404
+ ///
405
+ /// This method is more robust than `.detc()` to very small or very large
406
+ /// determinants since it returns the natural logarithm of the determinant
407
+ /// rather than the determinant itself.
408
+ fn ln_detc ( & self ) -> Self :: Output ;
394
409
}
395
410
396
411
@@ -401,6 +416,14 @@ pub trait DeterminantCInto {
401
416
/// Computes the determinant of the Hermitian (or real symmetric) positive
402
417
/// definite matrix.
403
418
fn detc_into ( self ) -> Self :: Output ;
419
+
420
+ /// Computes the natural log of the determinant of the Hermitian (or real
421
+ /// symmetric) positive definite matrix.
422
+ ///
423
+ /// This method is more robust than `.detc_into()` to very small or very
424
+ /// large determinants since it returns the natural logarithm of the
425
+ /// determinant rather than the determinant itself.
426
+ fn ln_detc_into ( self ) -> Self :: Output ;
404
427
}
405
428
406
429
impl < A , S > DeterminantC for ArrayBase < S , Ix2 >
@@ -411,7 +434,11 @@ where
411
434
type Output = Result < <A as AssociatedReal >:: Real > ;
412
435
413
436
fn detc ( & self ) -> Self :: Output {
414
- Ok ( self . factorizec ( UPLO :: Upper ) ?. detc ( ) )
437
+ Ok ( self . ln_detc ( ) ?. exp ( ) )
438
+ }
439
+
440
+ fn ln_detc ( & self ) -> Self :: Output {
441
+ Ok ( self . factorizec ( UPLO :: Upper ) ?. ln_detc ( ) )
415
442
}
416
443
}
417
444
@@ -423,6 +450,10 @@ where
423
450
type Output = Result < <A as AssociatedReal >:: Real > ;
424
451
425
452
fn detc_into ( self ) -> Self :: Output {
426
- Ok ( self . factorizec_into ( UPLO :: Upper ) ?. detc_into ( ) )
453
+ Ok ( self . ln_detc_into ( ) ?. exp ( ) )
454
+ }
455
+
456
+ fn ln_detc_into ( self ) -> Self :: Output {
457
+ Ok ( self . factorizec_into ( UPLO :: Upper ) ?. ln_detc_into ( ) )
427
458
}
428
459
}
0 commit comments