LQ.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_LQ_H_
36 #define _BLAZE_MATH_DENSE_LQ_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 // LQ DECOMPOSITION FUNCTIONS
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
80 template< typename MT1, bool SO1, typename MT2, bool SO2, typename MT3, bool SO3 >
81 void lq( const DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& Q, DenseMatrix<MT3,SO3>& R );
83 //*************************************************************************************************
84 
85 
86 //*************************************************************************************************
98 template< typename MT1 > // Type of matrix A
99 inline typename EnableIf< IsBuiltin< typename MT1::ElementType > >::Type
100  lq_backend( MT1& A, const typename MT1::ElementType* tau )
101 {
103 
104  orglq( 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  lq_backend( MT1& A, const typename MT1::ElementType* tau )
125 {
127 
128  unglq( A, tau );
129 }
131 //*************************************************************************************************
132 
133 
134 //*************************************************************************************************
182 template< typename MT1 // Type of matrix A
183  , bool SO1 // Storage order of matrix A
184  , typename MT2 // Type of matrix L
185  , bool SO2 // Storage order of matrix L
186  , typename MT3 // Type of matrix Q
187  , bool SO3 > // Storage order of matrix Q
189 {
192 
198 
201 
202  typedef typename RemoveAdaptor<MT1>::Type UMT1;
203  typedef typename If< IsRowMajorMatrix<UMT1>, typename UMT1::OppositeType, UMT1 >::Type Tmp;
204  typedef typename MT1::ElementType ET1;
205 
208 
209  const size_t m( (~A).rows() );
210  const size_t n( (~A).columns() );
211  const size_t mindim( min( m, n ) );
212 
213  if( ( !IsResizable<MT2>::value && ( (~L).rows() != m || (~L).columns() != mindim ) ) ||
214  ( !IsResizable<MT3>::value && ( (~Q).rows() != mindim || (~Q).columns() != n ) ) ) {
215  BLAZE_THROW_INVALID_ARGUMENT( "Dimensions of fixed size matrix do not match" );
216  }
217 
218  if( IsSquare<MT2>::value && m != mindim ) {
219  BLAZE_THROW_INVALID_ARGUMENT( "Square matrix cannot be resized to m-by-min(m,n)" );
220  }
221 
222  Tmp tmp( ~A );
223  UniqueArray<ET1> tau( new ET1[mindim] );
224 
225  gelqf( tmp, tau.get() );
226 
227  typename DerestrictTrait<MT3>::Type l( derestrict( ~L ) );
228  resize( ~L, m, mindim );
229  reset( l );
230 
231  for( size_t i=0UL; i<m; ++i ) {
232  for( size_t j=0UL; j<min(i+1UL,n); ++j ) {
233  l(i,j) = tmp(i,j);
234  }
235  }
236 
237  lq_backend( tmp, tau.get() );
238 
239  (~Q) = submatrix( tmp, 0UL, 0UL, min( m, n ), n );
240 }
241 //*************************************************************************************************
242 
243 } // namespace blaze
244 
245 #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 orglq(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 LQ decomposition.
Definition: orglq.h:129
Pointer get() const
Returns a pointer to the managed array.
Definition: UniqueArray.h:245
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
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
Header file for the LAPACK functions to reconstruct Q from a LQ decomposition (unglq) ...
#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
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
Header file for the LAPACK functions to reconstruct Q from a LQ decomposition (orglq) ...
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
void lq(const DenseMatrix< MT1, SO1 > &A, DenseMatrix< MT2, SO2 > &Q, DenseMatrix< MT3, SO3 > &R)
LQ decomposition of the given dense matrix.
Definition: LQ.h:188
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
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 gelqf(int m, int n, float *A, int lda, float *tau, float *work, int lwork, int *info)
LAPACK kernel for the LQ decomposition of the given dense single precision column-major matrix...
Definition: gelqf.h:155
void unglq(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 LQ decomposition.
Definition: unglq.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.
Scope-limited management of dynamically allocated arrays.The UniqueArray class implements a scope-res...
Definition: UniqueArray.h:97
Header file for the LAPACK LQ decomposition functions (gelqf)