QL.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_QL_H_
36 #define _BLAZE_MATH_DENSE_QL_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 // QL DECOMPOSITION FUNCTIONS
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
80 template< typename MT1, bool SO1, typename MT2, bool SO2, typename MT3, bool SO3 >
81 void ql( const DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& Q, DenseMatrix<MT3,SO3>& L );
83 //*************************************************************************************************
84 
85 
86 //*************************************************************************************************
98 template< typename MT1 > // Type of matrix A
99 inline typename EnableIf< IsBuiltin< typename MT1::ElementType > >::Type
100  ql_backend( MT1& A, const typename MT1::ElementType* tau )
101 {
103 
104  orgql( 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  ql_backend( MT1& A, const typename MT1::ElementType* tau )
125 {
127 
128  ungql( 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 Q
185  , bool SO2 // Storage order of matrix Q
186  , typename MT3 // Type of matrix L
187  , bool SO3 > // Storage order of matrix L
189 {
192 
195 
202 
203  typedef typename RemoveAdaptor<MT1>::Type UMT1;
204  typedef typename If< IsRowMajorMatrix<UMT1>, typename UMT1::OppositeType, UMT1 >::Type Tmp;
205  typedef typename MT1::ElementType ET1;
206 
209 
210  const size_t m( (~A).rows() );
211  const size_t n( (~A).columns() );
212  const size_t mindim( min( m, n ) );
213 
214  if( ( !IsResizable<MT2>::value && ( (~Q).rows() != m || (~Q).columns() != mindim ) ) ||
215  ( !IsResizable<MT3>::value && ( (~L).rows() != mindim || (~L).columns() != n ) ) ) {
216  BLAZE_THROW_INVALID_ARGUMENT( "Dimensions of fixed size matrix do not match" );
217  }
218 
219  if( IsSquare<MT3>::value && mindim != n ) {
220  BLAZE_THROW_INVALID_ARGUMENT( "Square matrix cannot be resized to min(m,n)-by-n" );
221  }
222 
223  Tmp tmp( ~A );
224  UniqueArray<ET1> tau( new ET1[mindim] );
225 
226  geqlf( tmp, tau.get() );
227 
228  typename DerestrictTrait<MT2>::Type l( derestrict( ~L ) );
229  resize( ~L, mindim, n );
230  reset( l );
231 
232  const size_t ioffset( ( m > n )?( m-n ):( 0UL ) );
233  const size_t joffset( ( m < n )?( n-m ):( 0UL ) );
234 
235  for( size_t i=0UL; i<mindim; ++i ) {
236  for( size_t j=0UL; j<=i+joffset; ++j ) {
237  l(i,j) = tmp(i+ioffset,j);
238  }
239  }
240 
241  ql_backend( tmp, tau.get() );
242 
243  (~Q) = submatrix( tmp, 0UL, joffset, m, min( m, n ) );
244 }
245 //*************************************************************************************************
246 
247 } // namespace blaze
248 
249 #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
Header file for the LAPACK functions to reconstruct Q from a QL decomposition (ungql) ...
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
Header file for the LAPACK functions to reconstruct Q from a QL decomposition (orgql) ...
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
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
void ql(const DenseMatrix< MT1, SO1 > &A, DenseMatrix< MT2, SO2 > &Q, DenseMatrix< MT3, SO3 > &L)
QL decomposition of the given dense matrix.
Definition: QL.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.
Header file for the LAPACK QL decomposition functions (geqlf)
void orgql(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 QL decomposition.
Definition: orgql.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
void ungql(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 QL decomposition.
Definition: ungql.h:129
#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.
void geqlf(int m, int n, float *A, int lda, float *tau, float *work, int lwork, int *info)
LAPACK kernel for the QL decomposition of the given dense single precision column-major matrix...
Definition: geqlf.h:156
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