@@ -253,11 +253,11 @@ where
253
253
254
254
/// An interface for calculating determinants of Hermitian (or real symmetric) matrix refs.
255
255
pub trait DeterminantH {
256
- type Output ;
257
- type SignLnOutput ;
256
+ /// The element type of the matrix.
257
+ type Elem : Scalar ;
258
258
259
259
/// Computes the determinant of the Hermitian (or real symmetric) matrix.
260
- fn deth ( & self ) -> Self :: Output ;
260
+ fn deth ( & self ) -> Result < < Self :: Elem as AssociatedReal > :: Real > ;
261
261
262
262
/// Computes the `(sign, natural_log)` of the determinant of the Hermitian
263
263
/// (or real symmetric) matrix.
@@ -272,16 +272,23 @@ pub trait DeterminantH {
272
272
/// This method is more robust than `.deth()` to very small or very large
273
273
/// determinants since it returns the natural logarithm of the determinant
274
274
/// rather than the determinant itself.
275
- fn sln_deth ( & self ) -> Self :: SignLnOutput ;
275
+ fn sln_deth (
276
+ & self
277
+ ) -> Result <
278
+ (
279
+ <Self :: Elem as AssociatedReal >:: Real ,
280
+ <Self :: Elem as AssociatedReal >:: Real
281
+ ) ,
282
+ > ;
276
283
}
277
284
278
285
/// An interface for calculating determinants of Hermitian (or real symmetric) matrices.
279
286
pub trait DeterminantHInto {
280
- type Output ;
281
- type SignLnOutput ;
287
+ /// The element type of the matrix.
288
+ type Elem : Scalar ;
282
289
283
290
/// Computes the determinant of the Hermitian (or real symmetric) matrix.
284
- fn deth_into ( self ) -> Self :: Output ;
291
+ fn deth_into ( self ) -> Result < < Self :: Elem as AssociatedReal > :: Real > ;
285
292
286
293
/// Computes the `(sign, natural_log)` of the determinant of the Hermitian
287
294
/// (or real symmetric) matrix.
@@ -296,7 +303,14 @@ pub trait DeterminantHInto {
296
303
/// This method is more robust than `.deth_into()` to very small or very
297
304
/// large determinants since it returns the natural logarithm of the
298
305
/// determinant rather than the determinant itself.
299
- fn sln_deth_into ( self ) -> Self :: SignLnOutput ;
306
+ fn sln_deth_into (
307
+ self
308
+ ) -> Result <
309
+ (
310
+ <Self :: Elem as AssociatedReal >:: Real ,
311
+ <Self :: Elem as AssociatedReal >:: Real
312
+ ) ,
313
+ > ;
300
314
}
301
315
302
316
/// Returns the sign and natural log of the determinant.
@@ -346,38 +360,56 @@ where
346
360
( sign, ln_det)
347
361
}
348
362
349
- impl < A , S > DeterminantH for BKFactorized < S >
363
+ impl < A , S > BKFactorized < S >
350
364
where
351
365
A : Scalar ,
352
366
S : Data < Elem = A > ,
353
367
{
354
- type Output = A :: Real ;
355
- type SignLnOutput = ( A :: Real , A :: Real ) ;
356
-
357
- fn deth ( & self ) -> A :: Real {
368
+ /// Computes the determinant of the factorized Hermitian (or real
369
+ /// symmetric) matrix.
370
+ pub fn deth ( & self ) -> A :: Real {
358
371
let ( sign, ln_det) = self . sln_deth ( ) ;
359
372
sign * ln_det. exp ( )
360
373
}
361
374
362
- fn sln_deth ( & self ) -> ( A :: Real , A :: Real ) {
375
+ /// Computes the `(sign, natural_log)` of the determinant of the factorized
376
+ /// Hermitian (or real symmetric) matrix.
377
+ ///
378
+ /// The `natural_log` is the natural logarithm of the absolute value of the
379
+ /// determinant. If the determinant is zero, `sign` is 0 and `natural_log`
380
+ /// is negative infinity.
381
+ ///
382
+ /// To obtain the determinant, you can compute `sign * natural_log.exp()`
383
+ /// or just call `.deth()` instead.
384
+ ///
385
+ /// This method is more robust than `.deth()` to very small or very large
386
+ /// determinants since it returns the natural logarithm of the determinant
387
+ /// rather than the determinant itself.
388
+ pub fn sln_deth ( & self ) -> ( A :: Real , A :: Real ) {
363
389
bk_sln_det ( UPLO :: Upper , self . ipiv . iter ( ) . cloned ( ) , & self . a )
364
390
}
365
- }
366
391
367
- impl < A , S > DeterminantHInto for BKFactorized < S >
368
- where
369
- A : Scalar ,
370
- S : Data < Elem = A > ,
371
- {
372
- type Output = A :: Real ;
373
- type SignLnOutput = ( A :: Real , A :: Real ) ;
374
-
375
- fn deth_into ( self ) -> A :: Real {
392
+ /// Computes the determinant of the factorized Hermitian (or real
393
+ /// symmetric) matrix.
394
+ pub fn deth_into ( self ) -> A :: Real {
376
395
let ( sign, ln_det) = self . sln_deth_into ( ) ;
377
396
sign * ln_det. exp ( )
378
397
}
379
398
380
- fn sln_deth_into ( self ) -> ( A :: Real , A :: Real ) {
399
+ /// Computes the `(sign, natural_log)` of the determinant of the factorized
400
+ /// Hermitian (or real symmetric) matrix.
401
+ ///
402
+ /// The `natural_log` is the natural logarithm of the absolute value of the
403
+ /// determinant. If the determinant is zero, `sign` is 0 and `natural_log`
404
+ /// is negative infinity.
405
+ ///
406
+ /// To obtain the determinant, you can compute `sign * natural_log.exp()`
407
+ /// or just call `.deth_into()` instead.
408
+ ///
409
+ /// This method is more robust than `.deth_into()` to very small or very
410
+ /// large determinants since it returns the natural logarithm of the
411
+ /// determinant rather than the determinant itself.
412
+ pub fn sln_deth_into ( self ) -> ( A :: Real , A :: Real ) {
381
413
bk_sln_det ( UPLO :: Upper , self . ipiv . into_iter ( ) , & self . a )
382
414
}
383
415
}
@@ -387,8 +419,7 @@ where
387
419
A : Scalar ,
388
420
S : Data < Elem = A > ,
389
421
{
390
- type Output = Result < A :: Real > ;
391
- type SignLnOutput = Result < ( A :: Real , A :: Real ) > ;
422
+ type Elem = A ;
392
423
393
424
fn deth ( & self ) -> Result < A :: Real > {
394
425
let ( sign, ln_det) = self . sln_deth ( ) ?;
@@ -412,8 +443,7 @@ where
412
443
A : Scalar ,
413
444
S : DataMut < Elem = A > ,
414
445
{
415
- type Output = Result < A :: Real > ;
416
- type SignLnOutput = Result < ( A :: Real , A :: Real ) > ;
446
+ type Elem = A ;
417
447
418
448
fn deth_into ( self ) -> Result < A :: Real > {
419
449
let ( sign, ln_det) = self . sln_deth_into ( ) ?;
0 commit comments