Blaze  3.6
Eigen.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_EIGEN_H_
36 #define _BLAZE_MATH_DENSE_EIGEN_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
50 #include <blaze/math/lapack/geev.h>
58 #include <blaze/util/DisableIf.h>
59 #include <blaze/util/EnableIf.h>
60 #include <blaze/util/mpl/If.h>
63 
64 
65 namespace blaze {
66 
67 //=================================================================================================
68 //
69 // EIGENVALUE FUNCTIONS
70 //
71 //=================================================================================================
72 
73 //*************************************************************************************************
76 template< typename MT, bool SO, typename VT, bool TF >
77 inline void eigen( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w );
78 
79 template< typename MT1, bool SO1, typename VT, bool TF, typename MT2, bool SO2 >
80 inline void eigen( const DenseMatrix<MT1,SO1>& A, DenseVector<VT,TF>& w, DenseMatrix<MT2,SO2>& V );
82 //*************************************************************************************************
83 
84 
85 //*************************************************************************************************
104 template< typename MT // Type of the matrix A
105  , bool SO // Storage order of the matrix A
106  , typename VT // Type of the vector w
107  , bool TF > // Transpose flag of the vector w
108 inline auto eigen_backend( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
109  -> EnableIf_t< IsSymmetric_v<MT> && IsFloatingPoint_v< ElementType_t<MT> > >
110 {
111  using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
112 
116  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
117 
118  ATmp Atmp( A );
119 
120  syevd( Atmp, ~w, 'N', 'L' );
121 }
123 //*************************************************************************************************
124 
125 
126 //*************************************************************************************************
145 template< typename MT // Type of the matrix A
146  , bool SO // Storage order of the matrix A
147  , typename VT // Type of the vector w
148  , bool TF > // Transpose flag of the vector w
149 inline auto eigen_backend( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
150  -> EnableIf_t< IsHermitian_v<MT> && IsComplex_v< ElementType_t<MT> > >
151 {
152  using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
153 
157  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
158 
159  ATmp Atmp( A );
160 
161  heevd( Atmp, ~w, 'N', 'L' );
162 }
164 //*************************************************************************************************
165 
166 
167 //*************************************************************************************************
186 template< typename MT // Type of the matrix A
187  , bool SO // Storage order of the matrix A
188  , typename VT // Type of the vector w
189  , bool TF > // Transpose flag of the vector w
190 inline auto eigen_backend( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
191  -> DisableIf_t< ( IsSymmetric_v<MT> && IsFloatingPoint_v< ElementType_t<MT> > ) ||
192  ( IsHermitian_v<MT> && IsComplex_v< ElementType_t<MT> > ) >
193 {
194  using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
195 
199  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
200 
201  ATmp Atmp( A );
202 
203  geev( Atmp, ~w );
204 }
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
296 template< typename MT // Type of the matrix A
297  , bool SO // Storage order of the matrix A
298  , typename VT // Type of the vector w
299  , bool TF > // Transpose flag of the vector w
300 inline void eigen( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
301 {
304 
308 
309  using WTmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
310 
311  WTmp wtmp( ~w );
312 
313  eigen_backend( ~A, wtmp );
314 
315  if( IsContiguous_v<VT> ) {
316  (~w) = wtmp;
317  }
318 }
319 //*************************************************************************************************
320 
321 
322 //*************************************************************************************************
343 template< typename MT1 // Type of the matrix A
344  , bool SO1 // Storage order of the matrix A
345  , typename VT // Type of the vector w
346  , bool TF // Transpose flag of the vector w
347  , typename MT2 // Type of the matrix V
348  , bool SO2 > // Storage order of the matrix V
349 inline auto eigen_backend( const DenseMatrix<MT1,SO1>& A, DenseVector<VT,TF>& w, DenseMatrix<MT2,SO2>& V )
350  -> EnableIf_t< IsSymmetric_v<MT1> && IsFloatingPoint_v< ElementType_t<MT1> > >
351 {
352  using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
353 
357  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
358 
359  ATmp Atmp( A );
360 
361  syevd( Atmp, ~w, 'V', 'L' );
362 
363  (~V) = Atmp;
364 }
366 //*************************************************************************************************
367 
368 
369 //*************************************************************************************************
390 template< typename MT1 // Type of the matrix A
391  , bool SO1 // Storage order of the matrix A
392  , typename VT // Type of the vector w
393  , bool TF // Transpose flag of the vector w
394  , typename MT2 // Type of the matrix V
395  , bool SO2 > // Storage order of the matrix V
396 inline auto eigen_backend( const DenseMatrix<MT1,SO1>& A, DenseVector<VT,TF>& w, DenseMatrix<MT2,SO2>& V )
397  -> EnableIf_t< IsHermitian_v<MT1> && IsComplex_v< ElementType_t<MT1> > >
398 {
399  using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
400 
404  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
405 
406  ATmp Atmp( A );
407 
408  heevd( Atmp, ~w, 'V', 'L' );
409 
410  (~V) = Atmp;
411 }
413 //*************************************************************************************************
414 
415 
416 //*************************************************************************************************
437 template< typename MT1 // Type of the matrix A
438  , bool SO1 // Storage order of the matrix A
439  , typename VT // Type of the vector w
440  , bool TF // Transpose flag of the vector w
441  , typename MT2 // Type of the matrix V
442  , bool SO2 > // Storage order of the matrix V
443 inline auto eigen_backend( const DenseMatrix<MT1,SO1>& A, DenseVector<VT,TF>& w, DenseMatrix<MT2,SO2>& V )
444  -> DisableIf_t< ( IsSymmetric_v<MT1> && IsFloatingPoint_v< ElementType_t<MT1> > ) ||
445  ( IsHermitian_v<MT1> && IsComplex_v< ElementType_t<MT1> > ) >
446 {
447  using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
448 
452  BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE( ElementType_t<ATmp> );
453 
454  ATmp Atmp( A );
455 
456  if( IsRowMajorMatrix_v<MT1> )
457  geev( Atmp, ~V, ~w );
458  else
459  geev( Atmp, ~w, ~V );
460 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
566 template< typename MT1 // Type of the matrix A
567  , bool SO1 // Storage order of the matrix A
568  , typename VT // Type of the vector w
569  , bool TF // Transpose flag of the vector w
570  , typename MT2 // Type of the matrix V
571  , bool SO2 > // Storage order of the matrix V
573 {
576 
580 
585 
586  using WTmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
587  using VTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
588 
589  WTmp wtmp( ~w );
590  VTmp Vtmp( ~V );
591 
592  eigen_backend( ~A, wtmp, Vtmp );
593 
594  if( !IsContiguous_v<VT> ) {
595  (~w) = wtmp;
596  }
597 
598  if( !IsContiguous_v<MT2> ) {
599  (~V) = Vtmp;
600  }
601 }
602 //*************************************************************************************************
603 
604 } // namespace blaze
605 
606 #endif
Constraint on the data type.
Header file for auxiliary alias declarations.
constexpr bool IsComplex_v
Auxiliary variable template for the IsComplex type trait.The IsComplex_v variable template provides a...
Definition: IsComplex.h:139
#define BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS(T)
Constraint on the data type.In case the given data type T does not provide low-level data access to m...
Definition: MutableDataAccess.h:61
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
void heevd(char jobz, char uplo, int n, complex< float > *A, int lda, float *w, complex< float > *work, int lwork, float *rwork, int lrwork, int *iwork, int liwork, int *info)
LAPACK kernel for computing the eigenvalues of the given dense Hermitian single precision column-majo...
Definition: heevd.h:140
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
Header file for the DenseVector base class.
Constraint on the data type.
Header file for the LAPACK general matrix eigenvalue functions (geev)
#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
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
void geev(char jobvl, char jobvr, int n, float *A, int lda, float *wr, float *wi, float *VL, int ldvl, float *VR, int ldvr, float *work, int lwork, int *info)
LAPACK kernel for computing the eigenvalues of the given dense general single precision column-major ...
Definition: geev.h:172
Header file for the DenseMatrix base class.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the RemoveAdaptor type trait.
Constraint on the data type.
Header file for the EnableIf class template.
Header file for the IsContiguous type trait.
Header file for the LAPACK Hermitian matrix eigenvalue functions (heevd)
#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
Header file for the LAPACK symmetric matrix eigenvalue functions (syevd)
Header file for the IsRowMajorMatrix type trait.
Header file for the IsComplex type trait.
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
Header file for the IsHermitian type trait.
void syevd(char jobz, char uplo, int n, float *A, int lda, float *w, float *work, int lwork, int *iwork, int liwork, int *info)
LAPACK kernel for computing the eigenvalues of the given dense symmetric single precision column-majo...
Definition: syevd.h:136
void eigen(const DenseMatrix< MT, SO > &A, DenseVector< VT, TF > &w)
Eigenvalue computation of the given dense matrix.
Definition: Eigen.h:300