@@ -90,12 +90,12 @@ pub mod layout;
9090pub mod eig;
9191pub mod eigh;
9292pub mod eigh_generalized;
93+ pub mod qr;
9394
9495mod alloc;
9596mod cholesky;
9697mod least_squares;
9798mod opnorm;
98- mod qr;
9999mod rcond;
100100mod solve;
101101mod solveh;
@@ -108,7 +108,6 @@ pub use self::cholesky::*;
108108pub use self :: flags:: * ;
109109pub use self :: least_squares:: * ;
110110pub use self :: opnorm:: * ;
111- pub use self :: qr:: * ;
112111pub use self :: rcond:: * ;
113112pub use self :: solve:: * ;
114113pub use self :: solveh:: * ;
@@ -126,7 +125,6 @@ pub type Pivot = Vec<i32>;
126125/// Trait for primitive types which implements LAPACK subroutines
127126pub trait Lapack :
128127 OperatorNorm_
129- + QR_
130128 + SVD_
131129 + SVDDC_
132130 + Solve_
@@ -160,6 +158,18 @@ pub trait Lapack:
160158 a : & mut [ Self ] ,
161159 b : & mut [ Self ] ,
162160 ) -> Result < Vec < Self :: Real > > ;
161+
162+ /// Execute Householder reflection as the first step of QR-decomposition
163+ ///
164+ /// For C-continuous array,
165+ /// this will call LQ-decomposition of the transposed matrix $ A^T = LQ^T $
166+ fn householder ( l : MatrixLayout , a : & mut [ Self ] ) -> Result < Vec < Self > > ;
167+
168+ /// Reconstruct Q-matrix from Householder-reflectors
169+ fn q ( l : MatrixLayout , a : & mut [ Self ] , tau : & [ Self ] ) -> Result < ( ) > ;
170+
171+ /// Execute QR-decomposition at once
172+ fn qr ( l : MatrixLayout , a : & mut [ Self ] ) -> Result < Vec < Self > > ;
163173}
164174
165175macro_rules! impl_lapack {
@@ -198,6 +208,26 @@ macro_rules! impl_lapack {
198208 let work = EighGeneralizedWork :: <$s>:: new( calc_eigenvec, layout) ?;
199209 work. eval( uplo, a, b)
200210 }
211+
212+ fn householder( l: MatrixLayout , a: & mut [ Self ] ) -> Result <Vec <Self >> {
213+ use qr:: * ;
214+ let work = HouseholderWork :: <$s>:: new( l) ?;
215+ work. eval( a)
216+ }
217+
218+ fn q( l: MatrixLayout , a: & mut [ Self ] , tau: & [ Self ] ) -> Result <( ) > {
219+ use qr:: * ;
220+ let mut work = QWork :: <$s>:: new( l) ?;
221+ work. calc( a, tau) ?;
222+ Ok ( ( ) )
223+ }
224+
225+ fn qr( l: MatrixLayout , a: & mut [ Self ] ) -> Result <Vec <Self >> {
226+ let tau = Self :: householder( l, a) ?;
227+ let r = Vec :: from( & * a) ;
228+ Self :: q( l, a, & tau) ?;
229+ Ok ( r)
230+ }
201231 }
202232 } ;
203233}
0 commit comments