@@ -4,12 +4,14 @@ use lapack::c;
44
55use error:: * ;
66use layout:: MatrixLayout ;
7+ use num_traits:: Zero ;
78use types:: * ;
89
910use super :: { Pivot , Transpose , into_result} ;
11+ use super :: NormType ;
1012
1113/// Wraps `*getrf`, `*getri`, and `*getrs`
12- pub trait Solve_ : Sized {
14+ pub trait Solve_ : AssociatedReal + Sized {
1315 /// Computes the LU factorization of a general `m x n` matrix `a` using
1416 /// partial pivoting with row interchanges.
1517 ///
@@ -20,11 +22,15 @@ pub trait Solve_: Sized {
2022 /// if it is used to solve a system of equations.
2123 unsafe fn lu ( MatrixLayout , a : & mut [ Self ] ) -> Result < Pivot > ;
2224 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 > ;
2329 unsafe fn solve ( MatrixLayout , Transpose , a : & [ Self ] , & Pivot , b : & mut [ Self ] ) -> Result < ( ) > ;
2430}
2531
2632macro_rules! impl_solve {
27- ( $scalar: ty, $getrf: path, $getri: path, $getrs: path) => {
33+ ( $scalar: ty, $getrf: path, $getri: path, $gecon : path , $ getrs: path) => {
2834
2935impl Solve_ for $scalar {
3036 unsafe fn lu( l: MatrixLayout , a: & mut [ Self ] ) -> Result <Pivot > {
@@ -41,6 +47,13 @@ impl Solve_ for $scalar {
4147 into_result( info, ( ) )
4248 }
4349
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+
4457 unsafe fn solve( l: MatrixLayout , t: Transpose , a: & [ Self ] , ipiv: & Pivot , b: & mut [ Self ] ) -> Result <( ) > {
4558 let ( n, _) = l. size( ) ;
4659 let nrhs = 1 ;
@@ -52,7 +65,7 @@ impl Solve_ for $scalar {
5265
5366} } // impl_solve!
5467
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