File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -4,18 +4,23 @@ pub type Result<T> = ::std::result::Result<T, Error>;
4
4
5
5
#[ derive( Error , Debug ) ]
6
6
pub enum Error {
7
- #[ error( "LAPACK call failed with {return_code}" ) ]
8
- Lapack { return_code : i32 } ,
7
+ #[ error( "LAPACK call with invalid value {return_code}" ) ]
8
+ LapackInvalidValue { return_code : i32 } ,
9
+
10
+ #[ error( "Computational failure in LAPACK routine: {return_code}" ) ]
11
+ LapackComputationalFailure { return_code : i32 } ,
9
12
10
13
/// Strides of the array is not supported
11
14
#[ error( "Invalid shape" ) ]
12
15
InvalidShape ,
13
16
}
14
17
15
18
pub fn into_result < T > ( return_code : i32 , val : T ) -> Result < T > {
16
- if return_code == 0 {
17
- Ok ( val)
18
- } else {
19
- Err ( Error :: Lapack { return_code } )
19
+ if return_code > 0 {
20
+ return Err ( Error :: LapackComputationalFailure { return_code } ) ;
21
+ }
22
+ if return_code < 0 {
23
+ return Err ( Error :: LapackInvalidValue { return_code } ) ;
20
24
}
25
+ Ok ( val)
21
26
}
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ pub enum LinalgError {
13
13
NotSquare { rows : i32 , cols : i32 } ,
14
14
15
15
/// LAPACK subroutine returns non-zero code
16
- #[ error( "LAPACK: return_code = {}" , return_code ) ]
17
- Lapack { return_code : i32 } ,
16
+ #[ error( transparent ) ]
17
+ Lapack ( # [ from ] lapack :: error :: Error ) ,
18
18
19
19
/// Strides of the array is not supported
20
20
#[ error( "invalid stride: s0={}, s1={}" , s0, s1) ]
Original file line number Diff line number Diff line change @@ -476,7 +476,8 @@ where
476
476
self . ensure_square ( ) ?;
477
477
match self . factorize ( ) {
478
478
Ok ( fac) => fac. sln_det ( ) ,
479
- Err ( LinalgError :: Lapack { return_code } ) if return_code > 0 => {
479
+ Err ( LinalgError :: Lapack ( e) ) if matches ! ( e, lapack:: error:: Error :: LapackComputationalFailure { ..} ) =>
480
+ {
480
481
// The determinant is zero.
481
482
Ok ( ( A :: zero ( ) , A :: Real :: neg_infinity ( ) ) )
482
483
}
@@ -494,7 +495,8 @@ where
494
495
self . ensure_square ( ) ?;
495
496
match self . factorize_into ( ) {
496
497
Ok ( fac) => fac. sln_det_into ( ) ,
497
- Err ( LinalgError :: Lapack { return_code } ) if return_code > 0 => {
498
+ Err ( LinalgError :: Lapack ( e) ) if matches ! ( e, lapack:: error:: Error :: LapackComputationalFailure { .. } ) =>
499
+ {
498
500
// The determinant is zero.
499
501
Ok ( ( A :: zero ( ) , A :: Real :: neg_infinity ( ) ) )
500
502
}
@@ -538,11 +540,11 @@ where
538
540
{
539
541
fn rcond ( & self ) -> Result < A :: Real > {
540
542
unsafe {
541
- A :: rcond (
543
+ Ok ( A :: rcond (
542
544
self . a . layout ( ) ?,
543
545
self . a . as_allocated ( ) ?,
544
546
self . a . opnorm_one ( ) ?,
545
- )
547
+ ) ? )
546
548
}
547
549
}
548
550
}
You can’t perform that action at this time.
0 commit comments