@@ -4,12 +4,14 @@ use lapack::c;
4
4
5
5
use error:: * ;
6
6
use layout:: MatrixLayout ;
7
+ use num_traits:: Zero ;
7
8
use types:: * ;
8
9
9
10
use super :: { Pivot , Transpose , into_result} ;
11
+ use super :: NormType ;
10
12
11
13
/// Wraps `*getrf`, `*getri`, and `*getrs`
12
- pub trait Solve_ : Sized {
14
+ pub trait Solve_ : AssociatedReal + Sized {
13
15
/// Computes the LU factorization of a general `m x n` matrix `a` using
14
16
/// partial pivoting with row interchanges.
15
17
///
@@ -20,11 +22,15 @@ pub trait Solve_: Sized {
20
22
/// if it is used to solve a system of equations.
21
23
unsafe fn lu ( MatrixLayout , a : & mut [ Self ] ) -> Result < Pivot > ;
22
24
unsafe fn inv ( MatrixLayout , a : & mut [ Self ] , & Pivot ) -> Result < ( ) > ;
25
+ /// Estimates the the reciprocal of the condition number of the matrix in 1-norm.
26
+ ///
27
+ /// `anorm` should be the 1-norm of the matrix `a`.
28
+ unsafe fn rcond ( MatrixLayout , a : & [ Self ] , anorm : Self :: Real ) -> Result < Self :: Real > ;
23
29
unsafe fn solve ( MatrixLayout , Transpose , a : & [ Self ] , & Pivot , b : & mut [ Self ] ) -> Result < ( ) > ;
24
30
}
25
31
26
32
macro_rules! impl_solve {
27
- ( $scalar: ty, $getrf: path, $getri: path, $getrs: path) => {
33
+ ( $scalar: ty, $getrf: path, $getri: path, $gecon : path , $ getrs: path) => {
28
34
29
35
impl Solve_ for $scalar {
30
36
unsafe fn lu( l: MatrixLayout , a: & mut [ Self ] ) -> Result <Pivot > {
@@ -41,6 +47,13 @@ impl Solve_ for $scalar {
41
47
into_result( info, ( ) )
42
48
}
43
49
50
+ unsafe fn rcond( l: MatrixLayout , a: & [ Self ] , anorm: Self :: Real ) -> Result <Self :: Real > {
51
+ let ( n, _) = l. size( ) ;
52
+ let mut rcond = Self :: Real :: zero( ) ;
53
+ let info = $gecon( l. lapacke_layout( ) , NormType :: One as u8 , n, a, l. lda( ) , anorm, & mut rcond) ;
54
+ into_result( info, rcond)
55
+ }
56
+
44
57
unsafe fn solve( l: MatrixLayout , t: Transpose , a: & [ Self ] , ipiv: & Pivot , b: & mut [ Self ] ) -> Result <( ) > {
45
58
let ( n, _) = l. size( ) ;
46
59
let nrhs = 1 ;
@@ -52,7 +65,7 @@ impl Solve_ for $scalar {
52
65
53
66
} } // impl_solve!
54
67
55
- impl_solve ! ( f64 , c:: dgetrf, c:: dgetri, c:: dgetrs) ;
56
- impl_solve ! ( f32 , c:: sgetrf, c:: sgetri, c:: sgetrs) ;
57
- impl_solve ! ( c64, c:: zgetrf, c:: zgetri, c:: zgetrs) ;
58
- impl_solve ! ( c32, c:: cgetrf, c:: cgetri, c:: cgetrs) ;
68
+ impl_solve ! ( f64 , c:: dgetrf, c:: dgetri, c:: dgecon , c :: dgetrs) ;
69
+ impl_solve ! ( f32 , c:: sgetrf, c:: sgetri, c:: sgecon , c :: sgetrs) ;
70
+ impl_solve ! ( c64, c:: zgetrf, c:: zgetri, c:: zgecon , c :: zgetrs) ;
71
+ impl_solve ! ( c32, c:: cgetrf, c:: cgetri, c:: cgecon , c :: cgetrs) ;
0 commit comments