35 #ifndef _BLAZE_MATH_LAPACK_GESVD_H_ 36 #define _BLAZE_MATH_LAPACK_GESVD_H_ 75 template<
typename MT,
bool SO,
typename VT,
bool TF >
76 inline void gesvd( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s,
char jobu,
char jobv );
78 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF >
79 inline void gesvd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
80 DenseVector<VT,TF>& s,
char jobu,
char jobv );
82 template<
typename MT1,
bool SO,
typename VT,
bool TF,
typename MT2 >
83 inline void gesvd( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
84 DenseMatrix<MT2,SO>& V,
char jobu,
char jobv );
86 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF,
typename MT3 >
87 inline void gesvd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
88 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobu,
char jobv );
112 template<
typename MT
116 inline DisableIf_< IsComplex< ElementType_<MT> > >
117 gesvd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s,
char jobu,
char jobv )
121 BLAZE_INTERNAL_ASSERT( jobu !=
'O' || jobv !=
'O',
"Invalid combination of jobu and jobv detected" );
124 using ET = ElementType_<MT>;
126 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
127 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
128 int lda ( numeric_cast<int>( (~A).
spacing() ) );
131 const int minimum(
min( m, n ) );
132 const int maximum(
max( m, n ) );
134 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
135 const std::unique_ptr<ET[]> work(
new ET[lwork] );
137 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ), m, n, (~A).
data(), lda,
138 (~s).
data(),
nullptr, 1,
nullptr, 1, work.get(), lwork, &info );
169 template<
typename MT
173 inline EnableIf_< IsComplex< ElementType_<MT> > >
174 gesvd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s,
char jobu,
char jobv )
178 BLAZE_INTERNAL_ASSERT( jobu !=
'O' || jobv !=
'O',
"Invalid combination of jobu and jobv detected" );
181 using CT = ElementType_<MT>;
182 using BT = UnderlyingElement_<CT>;
184 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
185 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
186 int lda ( numeric_cast<int>( (~A).
spacing() ) );
189 const int minimum(
min( m, n ) );
190 const int maximum(
max( m, n ) );
192 int lwork( 2*minimum + maximum + 2 );
193 const std::unique_ptr<CT[]> work (
new CT[lwork] );
194 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
196 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ), m, n, (~A).
data(), lda,
197 (~s).
data(),
nullptr, 1,
nullptr, 1, work.get(), lwork, rwork.get(), &info );
293 template<
typename MT
308 const size_t M( (~A).
rows() );
309 const size_t N( (~A).
columns() );
310 const size_t mindim(
min( M, N ) );
312 if( jobu !=
'O' && jobu !=
'N' ) {
316 if( jobv !=
'O' && jobv !=
'N' ) {
320 if( jobu ==
'O' && jobv ==
'O' ) {
324 resize( ~s, mindim,
false );
326 if( M == 0UL || N == 0UL ) {
330 gesvd_backend( ~A, ~s, jobu, jobv );
355 template<
typename MT1
373 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
374 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
375 int lda ( numeric_cast<int>( (~A).
spacing() ) );
376 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
379 const int minimum(
min( m, n ) );
380 const int maximum(
max( m, n ) );
382 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
383 const std::unique_ptr<ET[]> work(
new ET[lwork] );
385 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
386 m, n, (~A).
data(), lda, (~s).
data(),
387 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
388 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
389 work.get(), lwork, &info );
421 template<
typename MT1
440 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
441 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
442 int lda ( numeric_cast<int>( (~A).
spacing() ) );
443 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
446 const int minimum(
min( m, n ) );
447 const int maximum(
max( m, n ) );
449 int lwork( 2*minimum + maximum + 2 );
450 const std::unique_ptr<CT[]> work (
new CT[lwork] );
451 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
453 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
454 m, n, (~A).
data(), lda, (~s).
data(),
455 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
456 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
457 work.get(), lwork, rwork.get(), &info );
570 template<
typename MT1
592 const size_t M( (~A).
rows() );
593 const size_t N( (~A).
columns() );
594 const size_t mindim(
min( M, N ) );
596 if( jobu !=
'A' && jobu !=
'S' && jobu !=
'N' ) {
600 if( jobv !=
'O' && jobv !=
'N' ) {
604 resize( ~s, mindim,
false );
607 resize( ~U, M, ( jobu ==
'A' ? M : mindim ),
false );
610 if( M == 0UL || N == 0UL ) {
614 gesvd_backend( ~A, ~U, ~s, jobu, jobv );
639 template<
typename MT1
657 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
658 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
659 int lda ( numeric_cast<int>( (~A).
spacing() ) );
660 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
663 const int minimum(
min( m, n ) );
664 const int maximum(
max( m, n ) );
666 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
667 const std::unique_ptr<ET[]> work(
new ET[lwork] );
669 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
670 m, n, (~A).
data(), lda, (~s).
data(),
671 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
672 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
673 work.get(), lwork, &info );
705 template<
typename MT1
724 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
725 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
726 int lda ( numeric_cast<int>( (~A).
spacing() ) );
727 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
730 const int minimum(
min( m, n ) );
731 const int maximum(
max( m, n ) );
733 int lwork( 2*minimum + maximum + 2 );
734 const std::unique_ptr<CT[]> work (
new CT[lwork] );
735 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
737 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
738 m, n, (~A).
data(), lda, (~s).
data(),
739 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
740 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
741 work.get(), lwork, rwork.get(), &info );
854 template<
typename MT1
876 const size_t M( (~A).
rows() );
877 const size_t N( (~A).
columns() );
878 const size_t mindim(
min( M, N ) );
880 if( jobu !=
'O' && jobu !=
'N' ) {
884 if( jobv !=
'A' && jobv !=
'S' && jobv !=
'N' ) {
888 resize( ~s, mindim,
false );
891 resize( ~V, ( jobv ==
'A' ? N : mindim ), N,
false );
894 if( M == 0UL || N == 0UL ) {
898 gesvd_backend( ~A, ~s, ~V, jobu, jobv );
924 template<
typename MT1
946 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
947 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
948 int lda ( numeric_cast<int>( (~A).
spacing() ) );
949 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
950 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
953 const int minimum(
min( m, n ) );
954 const int maximum(
max( m, n ) );
956 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
957 const std::unique_ptr<ET[]> work(
new ET[lwork] );
959 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
960 m, n, (~A).
data(), lda, (~s).
data(),
961 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
962 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
963 work.get(), lwork, &info );
996 template<
typename MT1
1019 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
1020 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
1021 int lda ( numeric_cast<int>( (~A).
spacing() ) );
1022 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
1023 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
1026 const int minimum(
min( m, n ) );
1027 const int maximum(
max( m, n ) );
1029 int lwork( 2*minimum + maximum + 2 );
1030 const std::unique_ptr<CT[]> work (
new CT[lwork] );
1031 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
1033 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
1034 m, n, (~A).
data(), lda, (~s).
data(),
1035 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
1036 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
1037 work.get(), lwork, rwork.get(), &info );
1157 template<
typename MT1
1185 const size_t M( (~A).
rows() );
1186 const size_t N( (~A).
columns() );
1187 const size_t mindim(
min( M, N ) );
1189 if( jobu !=
'A' && jobu !=
'S' && jobu !=
'N' ) {
1193 if( jobv !=
'A' && jobv !=
'S' && jobv !=
'N' ) {
1197 resize( ~s, mindim,
false );
1200 resize( ~U, M, ( jobu ==
'A' ? M : mindim ),
false );
1201 resize( ~V, ( jobv ==
'A' ? N : mindim ), N,
false );
1204 if( M == 0UL || N == 0UL ) {
1208 gesvd_backend( ~A, ~U, ~s, ~V, jobu, jobv );
#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.
Header file for auxiliary alias declarations.
void gesvd(char jobu, char jobv, int m, int n, float *A, int lda, float *s, float *U, int ldu, float *V, int ldv, float *work, int lwork, int *info)
LAPACK kernel for the singular value decomposition (SVD) of the given dense general single precision ...
Definition: gesvd.h:163
Headerfile for the generic min algorithm.
#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
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
#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 CLAPACK gesvd wrapper functions.
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:224
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1903
Header file for the DenseVector base class.
Header file for the UnderlyingElement type trait.
Constraint on the data type.
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1950
Cast operators for numeric types.
#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:80
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:252
Headerfile for the generic max algorithm.
Constraint on the data type.
Header file for the DisableIf class template.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
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:132
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:76
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:506
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:714
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:224
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:490
BLAZE_ALWAYS_INLINE MT::ElementType * data(DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:169
#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.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:908
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