35 #ifndef _BLAZE_MATH_LAPACK_GEEV_H_ 36 #define _BLAZE_MATH_LAPACK_GEEV_H_ 44 #include <boost/cast.hpp> 77 template<
typename MT,
bool SO,
typename VT,
bool TF >
78 inline void geev( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w );
80 template<
typename MT1,
bool SO1,
typename MT2,
bool SO2,
typename VT,
bool TF >
81 inline void geev( DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& VL, DenseVector<VT,TF>& w );
83 template<
typename MT1,
bool SO1,
typename VT,
bool TF,
typename MT2,
bool SO2 >
84 inline void geev( DenseMatrix<MT1,SO1>& A, DenseVector<VT,TF>& w, DenseMatrix<MT2,SO2>& VR );
86 template<
typename MT1,
bool SO1,
typename MT2,
bool SO2,
typename VT,
bool TF,
typename MT3,
bool SO3 >
87 inline void geev( DenseMatrix<MT1,SO1>& A, DenseMatrix<MT2,SO2>& VL,
88 DenseVector<VT,TF>& w, DenseMatrix<MT3,SO3>& VR );
110 template<
typename MT
114 inline DisableIf_< IsComplex< ElementType_<MT> > >
115 geev_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
117 using boost::numeric_cast;
122 using CT = ElementType_<VT>;
123 using BT = ElementType_<MT>;
128 int n ( numeric_cast<int>( (~A).
rows() ) );
129 int lda ( numeric_cast<int>( (~A).
spacing() ) );
132 int lwork( 3*n + 2 );
133 const std::unique_ptr<BT[]> wr (
new BT[n] );
134 const std::unique_ptr<BT[]> wi (
new BT[n] );
135 const std::unique_ptr<BT[]> work(
new BT[lwork] );
137 geev(
'N',
'N', n, (~A).data(), lda, wr.get(), wi.get(),
138 nullptr, 1,
nullptr, 1, work.get(), lwork, &info );
146 for(
size_t i=0UL; i<(~A).
rows(); ++i ) {
147 (~w)[i] = CT( wr[i], wi[i] );
171 template<
typename MT
175 inline EnableIf_< IsComplex< ElementType_<MT> > >
176 geev_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& w )
178 using boost::numeric_cast;
183 using CT = ElementType_<MT>;
184 using BT = UnderlyingElement_<CT>;
189 int n ( numeric_cast<int>( (~A).
rows() ) );
190 int lda ( numeric_cast<int>( (~A).
spacing() ) );
193 int lwork( 2*n + 2 );
194 const std::unique_ptr<CT[]> work (
new CT[lwork] );
195 const std::unique_ptr<BT[]> rwork(
new BT[2*n] );
197 geev(
'N',
'N', n, (~A).data(), lda, (~w).data(),
198 nullptr, 1,
nullptr, 1, work.get(), lwork, rwork.get(), &info );
265 template<
typename MT
281 const size_t N( (~A).
rows() );
293 geev_backend( ~A, ~w );
316 template<
typename MT1
325 using boost::numeric_cast;
338 int n ( numeric_cast<int>( (~A).
rows() ) );
339 int lda ( numeric_cast<int>( (~A).
spacing() ) );
342 int lwork( 4*n + 2 );
343 const std::unique_ptr<BT[]> vl (
new BT[n*n] );
344 const std::unique_ptr<BT[]> wr (
new BT[n] );
345 const std::unique_ptr<BT[]> wi (
new BT[n] );
346 const std::unique_ptr<BT[]> work(
new BT[lwork] );
348 geev( ( SO1 ?
'V' :
'N' ), ( SO1 ?
'N' :
'V' ), n, (~A).data(), lda, wr.get(), wi.get(),
349 ( SO1 ? vl.get() : nullptr ), ( SO1 ? n : 1 ),
350 ( SO1 ? nullptr : vl.get() ), ( SO1 ? 1 : n ),
351 work.get(), lwork, &info );
359 const size_t N( (~A).
rows() );
361 for(
size_t j=0UL; j<N; ++j ) {
362 (~w)[j] = CT( wr[j], wi[j] );
365 for(
size_t j=0UL; j<N; ++j ) {
366 if( j+1UL < N &&
equal( (~w)[j],
conj( (~w)[j+1UL] ) ) ) {
367 for(
size_t i=0UL; i<N; ++i )
369 const size_t j1( SO1 ? j : j+1UL );
370 const size_t j2( SO1 ? j+1UL : j );
372 const BT vl1( vl[i+j*N] );
373 const BT vl2( vl[i+(j+1UL)*N] );
375 ( SO2 ? (~VL)(i,j1) : (~VL)(j1,i) ) = CT( vl1, ( SO2 ? vl2 : -vl2 ) );
376 ( SO2 ? (~VL)(i,j2) : (~VL)(j2,i) ) = CT( vl1, ( SO2 ? -vl2 : vl2 ) );
382 for(
size_t i=0UL; i<N; ++i ) {
383 ( SO2 ? (~VL)(i,j) : (~VL)(j,i) ) = CT( vl[i+j*N] );
410 template<
typename MT1
419 using boost::numeric_cast;
432 int n ( numeric_cast<int>( (~A).
rows() ) );
433 int lda ( numeric_cast<int>( (~A).
spacing() ) );
434 int ldvl( numeric_cast<int>( (~VL).
spacing() ) );
437 int lwork( 2*n + 2 );
438 const std::unique_ptr<CT[]> work (
new CT[lwork] );
439 const std::unique_ptr<BT[]> rwork(
new BT[2*n] );
441 geev( ( SO1 ?
'V' :
'N' ), ( SO1 ?
'N' :
'V' ), n, (~A).data(), lda, (~w).data(),
442 ( SO1 ? (~VL).data() :
nullptr ), ( SO1 ? ldvl : 1 ),
443 ( SO1 ?
nullptr : (~VL).data() ), ( SO1 ? 1 : ldvl ),
444 work.get(), lwork, rwork.get(), &info );
525 template<
typename MT1
549 const size_t N( (~A).
rows() );
556 resize( ~VL, N, N,
false );
562 geev_backend( ~A, ~VL, ~w );
585 template<
typename MT1
594 using boost::numeric_cast;
607 int n ( numeric_cast<int>( (~A).
rows() ) );
608 int lda ( numeric_cast<int>( (~A).
spacing() ) );
611 int lwork( 4*n + 2 );
612 const std::unique_ptr<BT[]> vr (
new BT[n*n] );
613 const std::unique_ptr<BT[]> wr (
new BT[n] );
614 const std::unique_ptr<BT[]> wi (
new BT[n] );
615 const std::unique_ptr<BT[]> work(
new BT[lwork] );
617 geev( ( SO1 ?
'N' :
'V' ), ( SO1 ?
'V' :
'N' ), n, (~A).data(), lda, wr.get(), wi.get(),
618 ( SO1 ? nullptr : vr.get() ), ( SO1 ? 1 : n ),
619 ( SO1 ? vr.get() : nullptr ), ( SO1 ? n : 1 ),
620 work.get(), lwork, &info );
628 const size_t N( (~A).
rows() );
630 for(
size_t j=0UL; j<N; ++j ) {
631 (~w)[j] = CT( wr[j], wi[j] );
634 for(
size_t j=0UL; j<N; ++j ) {
635 if( j+1UL < N &&
equal( (~w)[j],
conj( (~w)[j+1UL] ) ) ) {
636 for(
size_t i=0UL; i<N; ++i )
638 const size_t j1( SO1 ? j : j+1UL );
639 const size_t j2( SO1 ? j+1UL : j );
641 const BT vr1( vr[i+j*N] );
642 const BT vr2( vr[i+(j+1UL)*N] );
644 ( SO2 ? (~VR)(i,j1) : (~VR)(j1,i) ) = CT( vr1, ( SO2 ? vr2 : -vr2 ) );
645 ( SO2 ? (~VR)(i,j2) : (~VR)(j2,i) ) = CT( vr1, ( SO2 ? -vr2 : vr2 ) );
651 for(
size_t i=0UL; i<N; ++i ) {
652 ( SO2 ? (~VR)(i,j) : (~VR)(j,i) ) = CT( vr[i+j*N] );
679 template<
typename MT1
688 using boost::numeric_cast;
701 int n ( numeric_cast<int>( (~A).
rows() ) );
702 int lda ( numeric_cast<int>( (~A).
spacing() ) );
703 int ldvr( numeric_cast<int>( (~VR).
spacing() ) );
706 int lwork( 2*n + 2 );
707 const std::unique_ptr<CT[]> work (
new CT[lwork] );
708 const std::unique_ptr<BT[]> rwork(
new BT[2*n] );
710 geev( ( SO1 ?
'N' :
'V' ), ( SO1 ?
'V' :
'N' ), n, (~A).data(), lda, (~w).data(),
711 ( SO1 ?
nullptr : (~VR).data() ), ( SO1 ? 1 : ldvr ),
712 ( SO1 ? (~VR).data() :
nullptr ), ( SO1 ? ldvr : 1 ),
713 work.get(), lwork, rwork.get(), &info );
794 template<
typename MT1
818 const size_t N( (~A).
rows() );
825 resize( ~VR, N, N,
false );
831 geev_backend( ~A, ~w, ~VR );
855 template<
typename MT1
867 using boost::numeric_cast;
882 int n ( numeric_cast<int>( (~A).
rows() ) );
883 int lda ( numeric_cast<int>( (~A).
spacing() ) );
886 int lwork( 4*n + 2 );
887 const std::unique_ptr<BT[]> vl (
new BT[n*n] );
888 const std::unique_ptr<BT[]> vr (
new BT[n*n] );
889 const std::unique_ptr<BT[]> wr (
new BT[n] );
890 const std::unique_ptr<BT[]> wi (
new BT[n] );
891 const std::unique_ptr<BT[]> work(
new BT[lwork] );
893 geev(
'V',
'V', n, (~A).data(), lda, wr.get(), wi.get(),
894 ( SO1 ? vl.get() : vr.get() ), n, ( SO1 ? vr.get() : vl.get() ), n,
895 work.get(), lwork, &info );
903 const size_t N( (~A).
rows() );
905 for(
size_t j=0UL; j<N; ++j ) {
906 (~w)[j] = CT( wr[j], wi[j] );
909 for(
size_t j=0UL; j<N; ++j ) {
910 if( j+1UL < N &&
equal( (~w)[j],
conj( (~w)[j+1UL] ) ) ) {
911 for(
size_t i=0UL; i<N; ++i )
913 const size_t j1( SO1 ? j : j+1UL );
914 const size_t j2( SO1 ? j+1UL : j );
916 const BT vl1( vl[i+j*N] );
917 const BT vl2( vl[i+(j+1UL)*N] );
918 const BT vr1( vr[i+j*N] );
919 const BT vr2( vr[i+(j+1UL)*N] );
921 ( SO2 ? (~VL)(i,j1) : (~VL)(j1,i) ) = CT( vl1, ( SO2 ? vl2 : -vl2 ) );
922 ( SO2 ? (~VL)(i,j2) : (~VL)(j2,i) ) = CT( vl1, ( SO2 ? -vl2 : vl2 ) );
923 ( SO3 ? (~VR)(i,j1) : (~VR)(j1,i) ) = CT( vr1, ( SO3 ? vr2 : -vr2 ) );
924 ( SO3 ? (~VR)(i,j2) : (~VR)(j2,i) ) = CT( vr1, ( SO3 ? -vr2 : vr2 ) );
930 for(
size_t i=0UL; i<N; ++i ) {
931 ( SO2 ? (~VL)(i,j) : (~VL)(j,i) ) = CT( vl[i+j*N] );
932 ( SO3 ? (~VR)(i,j) : (~VR)(j,i) ) = CT( vr[i+j*N] );
960 template<
typename MT1
972 using boost::numeric_cast;
987 int n ( numeric_cast<int>( (~A).
rows() ) );
988 int lda ( numeric_cast<int>( (~A).
spacing() ) );
989 int ldvl( numeric_cast<int>( (~VL).
spacing() ) );
990 int ldvr( numeric_cast<int>( (~VR).
spacing() ) );
993 int lwork( 2*n + 2 );
994 const std::unique_ptr<CT[]> work (
new CT[lwork] );
995 const std::unique_ptr<BT[]> rwork(
new BT[2*n] );
997 geev(
'V',
'V', n, (~A).data(), lda, (~w).data(),
998 ( SO1 ? (~VL).data() : (~VR).data() ), ( SO1 ? ldvl : ldvr ),
999 ( SO1 ? (~VR).data() : (~VL).data() ), ( SO1 ? ldvr : ldvl ),
1000 work.get(), lwork, rwork.get(), &info );
1090 template<
typename MT1
1123 const size_t N( (~A).
rows() );
1130 resize( ~VL, N, N,
false );
1131 resize( ~VR, N, N,
false );
1137 geev_backend( ~A, ~VL, ~w, ~VR );
#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
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t spacing(const DenseMatrix< MT, SO > &dm) noexcept
Returns the spacing between the beginning of two rows/columns.
Definition: DenseMatrix.h:102
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1214
Header file for auxiliary alias declarations.
#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
constexpr bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:76
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:261
#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
Constraint on the data type.
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
Header file for the DenseVector base class.
Header file for the UnderlyingElement type trait.
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
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:71
Constraint on the data type.
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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:161
Header file for the DenseMatrix base class.
typename UnderlyingElement< T >::Type UnderlyingElement_
Auxiliary alias declaration for the UnderlyingElement type trait.The UnderlyingElement_ alias declara...
Definition: UnderlyingElement.h:133
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Header file for the equal shim.
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:544
Constraint on the data type.
Header file for the EnableIf class template.
Header file for run time assertion macros.
#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
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
#define BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE(T)
Constraint on the data type.In case the given data type T is not a built-in data type, a compilation error is created.
Definition: Builtin.h:60
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:320
#define BLAZE_CONSTRAINT_MUST_BE_COMPLEX_TYPE(T)
Constraint on the data type.This compile time constraint checks that the given data type T is a compl...
Definition: Complex.h:62
#define BLAZE_THROW_LAPACK_ERROR(MESSAGE)
Macro for the emission of an exception on detection of a LAPACK error.This macro encapsulates the def...
Definition: Exception.h:146
Header file for the IsComplex type trait.
Header file for the complex data type.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:677
Header file for the IsResizable type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Constraint on the data type.
Header file for the CLAPACK geev wrapper functions.