RQ.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_RQ_H_
36 #define _BLAZE_MATH_DENSE_RQ_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <memory>
44 #include <blaze/math/Aliases.h>
52 #include <blaze/math/Exception.h>
54 #include <blaze/math/Functions.h>
62 #include <blaze/util/EnableIf.h>
63 
64 
65 namespace blaze {
66 
67 //=================================================================================================
68 //
69 // RQ DECOMPOSITION FUNCTIONS
70 //
71 //=================================================================================================
72 
73 //*************************************************************************************************
76 template< typename MT1, bool SO1, typename MT2, bool SO2, typename MT3, bool SO3 >
77 void rq( const DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& R, DenseMatrix<MT3,SO3>& Q );
79 //*************************************************************************************************
80 
81 
82 //*************************************************************************************************
94 template< typename MT1 > // Type of matrix A
95 inline EnableIf_<IsBuiltin< ElementType_<MT1> > >
96  rq_backend( MT1& A, const ElementType_<MT1>* tau )
97 {
98  orgrq( A, tau );
99 }
101 //*************************************************************************************************
102 
103 
104 //*************************************************************************************************
116 template< typename MT1 > // Type of matrix A
117 inline EnableIf_<IsComplex< ElementType_<MT1> > >
118  rq_backend( MT1& A, const ElementType_<MT1>* tau )
119 {
120  ungrq( A, tau );
121 }
123 //*************************************************************************************************
124 
125 
126 //*************************************************************************************************
175 template< typename MT1 // Type of matrix A
176  , bool SO1 // Storage order of matrix A
177  , typename MT2 // Type of matrix R
178  , bool SO2 // Storage order of matrix R
179  , typename MT3 // Type of matrix Q
180  , bool SO3 > // Storage order of matrix Q
182 {
185 
192 
195 
196  typedef ElementType_<MT1> ET1;
197 
198  const size_t m( (~A).rows() );
199  const size_t n( (~A).columns() );
200  const size_t mindim( min( m, n ) );
201 
202  if( ( !IsResizable<MT2>::value && ( (~R).rows() != m || (~R).columns() != mindim ) ) ||
203  ( !IsResizable<MT3>::value && ( (~Q).rows() != mindim || (~Q).columns() != n ) ) ) {
204  BLAZE_THROW_INVALID_ARGUMENT( "Dimensions of fixed size matrix do not match" );
205  }
206 
207  if( IsSquare<MT2>::value && m != mindim ) {
208  BLAZE_THROW_INVALID_ARGUMENT( "Square matrix cannot be resized to m-by-min(m,n)" );
209  }
210 
211  const std::unique_ptr<ET1[]> tau( new ET1[mindim] );
212  DerestrictTrait_<MT2> r( derestrict( ~R ) );
213 
214  if( m < n )
215  {
216  (~Q) = A;
217  gerqf( ~Q, tau.get() );
218 
219  resize( ~R, m, m );
220  reset( r );
221 
222  for( size_t i=0UL; i<m; ++i ) {
223  for( size_t j=i; j<m; ++j ) {
224  r(i,j) = (~Q)(i,j+n-m);
225  }
226  }
227 
228  rq_backend( ~Q, tau.get() );
229  }
230  else
231  {
232  r = A;
233  gerqf( r, tau.get() );
234  (~Q) = submatrix( r, m-n, 0UL, n, n );
235  rq_backend( ~Q, tau.get() );
236 
237  for( size_t i=m-n; i<m; ++i ) {
238  for( size_t j=0UL; j<i+n-m; ++j ) {
239  reset( r(i,j) );
240  }
241  }
242  }
243 }
244 //*************************************************************************************************
245 
246 } // namespace blaze
247 
248 #endif
Header file for the implementation of the Submatrix view.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Header file for mathematical functions.
typename DerestrictTrait< T >::Type DerestrictTrait_
Auxiliary alias declaration for the DerestrictTrait type trait.The DerestrictTrait_ alias declaration...
Definition: DerestrictTrait.h:110
void gerqf(int m, int n, float *A, int lda, float *tau, float *work, int lwork, int *info)
LAPACK kernel for the RQ decomposition of the given dense single precision column-major matrix...
Definition: gerqf.h:144
void orgrq(int m, int n, int k, float *A, int lda, const float *tau, float *work, int lwork, int *info)
LAPACK kernel for the reconstruction of the orthogonal matrix Q from a RQ decomposition.
Definition: orgrq.h:117
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:81
void rq(const DenseMatrix< MT1, SO1 > &A, DenseMatrix< MT2, SO2 > &R, DenseMatrix< MT3, SO3 > &Q)
RQ decomposition of the given dense matrix.
Definition: RQ.h:181
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE(T)
Constraint on the data type.In case the given data type T is an adaptor type (as for instance LowerMa...
Definition: Adaptor.h:81
Header file for the LAPACK RQ decomposition functions (gerqf)
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Constraint on the data type.
Header file for the IsSquare type trait.
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the DenseMatrix base class.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Compile time check for square matrices.This type trait tests whether or not the given template parame...
Definition: IsSquare.h:88
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:330
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:538
Header file for the EnableIf class template.
Header file for the DerestrictTrait class template.
Constraint on the data type.
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a BLAS compatible data type (i...
Definition: BLASCompatible.h:61
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_STRICTLY_TRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a strictly lower or upper triangular mat...
Definition: StrictlyTriangular.h:81
Header file for the LAPACK functions to reconstruct Q from a RQ decomposition (ungrq) ...
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
void ungrq(int m, int n, int k, complex< float > *A, int lda, const complex< float > *tau, complex< float > *work, int lwork, int *info)
LAPACK kernel for the reconstruction of the orthogonal matrix Q from a RQ decomposition.
Definition: ungrq.h:117
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:79
SubmatrixExprTrait_< MT, unaligned > submatrix(Matrix< MT, SO > &matrix, size_t row, size_t column, size_t m, size_t n)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:167
Header file for the IsResizable type trait.
Header file for the LAPACK functions to reconstruct Q from a RQ decomposition (orgrq) ...