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 
53 #include <blaze/math/Functions.h>
65 #include <blaze/util/Exception.h>
66 #include <blaze/util/mpl/If.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // RQ DECOMPOSITION FUNCTIONS
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
80 template< typename MT1, bool SO1, typename MT2, bool SO2, typename MT3, bool SO3 >
81 void rq( const DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& R, DenseMatrix<MT3,SO3>& Q );
83 //*************************************************************************************************
84 
85 
86 //*************************************************************************************************
98 template< typename MT1 > // Type of matrix A
99 inline typename EnableIf< IsBuiltin< typename MT1::ElementType > >::Type
100  rq_backend( MT1& A, const typename MT1::ElementType* tau )
101 {
103 
104  orgrq( A, tau );
105 }
107 //*************************************************************************************************
108 
109 
110 //*************************************************************************************************
122 template< typename MT1 > // Type of matrix A
123 inline typename EnableIf< IsComplex< typename MT1::ElementType > >::Type
124  rq_backend( MT1& A, const typename MT1::ElementType* tau )
125 {
127 
128  ungrq( A, tau );
129 }
131 //*************************************************************************************************
132 
133 
134 //*************************************************************************************************
183 template< typename MT1 // Type of matrix A
184  , bool SO1 // Storage order of matrix A
185  , typename MT2 // Type of matrix R
186  , bool SO2 // Storage order of matrix R
187  , typename MT3 // Type of matrix Q
188  , bool SO3 > // Storage order of matrix Q
190 {
193 
200 
203 
204  typedef typename RemoveAdaptor<MT1>::Type UMT1;
205  typedef typename If< IsRowMajorMatrix<UMT1>, typename UMT1::OppositeType, UMT1 >::Type Tmp;
206  typedef typename MT1::ElementType ET1;
207 
210 
211  const size_t m( (~A).rows() );
212  const size_t n( (~A).columns() );
213  const size_t mindim( min( m, n ) );
214 
215  if( ( !IsResizable<MT2>::value && ( (~R).rows() != m || (~R).columns() != mindim ) ) ||
216  ( !IsResizable<MT3>::value && ( (~Q).rows() != mindim || (~Q).columns() != n ) ) ) {
217  BLAZE_THROW_INVALID_ARGUMENT( "Dimensions of fixed size matrix do not match" );
218  }
219 
220  if( IsSquare<MT2>::value && m != mindim ) {
221  BLAZE_THROW_INVALID_ARGUMENT( "Square matrix cannot be resized to m-by-min(m,n)" );
222  }
223 
224  Tmp tmp( ~A );
225  UniqueArray<ET1> tau( new ET1[mindim] );
226 
227  gerqf( tmp, tau.get() );
228 
229  typename DerestrictTrait<MT2>::Type r( derestrict( ~R ) );
230  resize( ~R, m, mindim );
231  reset( r );
232 
233  const size_t ioffset( ( m > n )?( m-n ):( 0UL ) );
234  const size_t joffset( ( m < n )?( n-m ):( 0UL ) );
235 
236  for( size_t i=0UL; i<ioffset; ++i ) {
237  for( size_t j=0UL; j<mindim; ++j ) {
238  r(i,j) = tmp(i,j);
239  }
240  }
241 
242  for( size_t i=ioffset; i<m; ++i ) {
243  for( size_t j=i-ioffset; j<mindim; ++j ) {
244  r(i,j) = tmp(i,j+joffset);
245  }
246  }
247 
248  rq_backend( tmp, tau.get() );
249 
250  (~Q) = submatrix( tmp, ioffset, 0UL, min( m, n ), n );
251 }
252 //*************************************************************************************************
253 
254 } // namespace blaze
255 
256 #endif
Header file for all restructuring submatrix functions.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Data type constraint.
Header file for mathematical functions.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
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:156
Pointer get() const
Returns a pointer to the managed array.
Definition: UniqueArray.h:245
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:129
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:308
#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:118
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:189
Constraint on the data type.
Constraint on the data type.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2584
#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:118
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.
Header file for the DenseSubmatrix class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:79
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
Header file for the DenseMatrix base class.
#define BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(A, B)
Data type constraint.In case the two types A and B are not the same (ignoring all cv-qualifiers of bo...
Definition: SameType.h:89
Compile time check for square matrices.This type trait tests whether or not the given template parame...
Definition: IsSquare.h:87
Constraints on the storage order of matrix types.
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:532
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Constraint on the data type.
Header file for the RemoveAdaptor type trait.
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:116
Constraint on the data type.
#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:118
#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:79
Constraint on the data type.
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
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:118
Header file for the LAPACK functions to reconstruct Q from a RQ decomposition (ungrq) ...
SubmatrixExprTrait< MT, unaligned >::Type 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:146
Removal of top level adaptor types.In case the given type is an adaptor type (SymmetricMatrix, LowerMatrix, UpperMatrix, ...), the RemoveAdaptor type trait removes the adaptor and extracts the contained general matrix type. Else the given type is returned as is. Note that cv-qualifiers are preserved.
Definition: RemoveAdaptor.h:76
Header file for the IsRowMajorMatrix type trait.
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:129
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
#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:116
Header file for exception macros.
Header file for the IsResizable type trait.
Header file for the LAPACK functions to reconstruct Q from a RQ decomposition (orgrq) ...
Scope-limited management of dynamically allocated arrays.The UniqueArray class implements a scope-res...
Definition: UniqueArray.h:97