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 auto gesvd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s,
char jobu,
char jobv )
117 -> DisableIf_t< IsComplex_v< ElementType_t<MT> > >
121 BLAZE_INTERNAL_ASSERT( jobu !=
'O' || jobv !=
'O',
"Invalid combination of jobu and jobv detected" );
124 using ET = ElementType_t<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 auto gesvd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s,
char jobu,
char jobv )
174 -> EnableIf_t< IsComplex_v< ElementType_t<MT> > >
178 BLAZE_INTERNAL_ASSERT( jobu !=
'O' || jobv !=
'O',
"Invalid combination of jobu and jobv detected" );
181 using CT = ElementType_t<MT>;
182 using BT = UnderlyingElement_t<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
310 const size_t M( (~A).
rows() );
311 const size_t N( (~A).
columns() );
312 const size_t mindim(
min( M, N ) );
314 if( jobu !=
'O' && jobu !=
'N' ) {
318 if( jobv !=
'O' && jobv !=
'N' ) {
322 if( jobu ==
'O' && jobv ==
'O' ) {
326 resize( ~s, mindim,
false );
328 if( M == 0UL || N == 0UL ) {
332 gesvd_backend( ~A, ~s, jobu, jobv );
357 template<
typename MT1
362 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
363 DenseVector<VT,TF>& s,
char jobu,
char jobv )
364 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
373 using ET = ElementType_t<MT1>;
375 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
376 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
377 int lda ( numeric_cast<int>( (~A).
spacing() ) );
378 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
381 const int minimum(
min( m, n ) );
382 const int maximum(
max( m, n ) );
384 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
385 const std::unique_ptr<ET[]> work(
new ET[lwork] );
387 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
388 m, n, (~A).
data(), lda, (~s).
data(),
389 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
390 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
391 work.get(), lwork, &info );
423 template<
typename MT1
428 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
429 DenseVector<VT,TF>& s,
char jobu,
char jobv )
430 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
439 using CT = ElementType_t<MT1>;
440 using BT = UnderlyingElement_t<CT>;
442 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
443 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
444 int lda ( numeric_cast<int>( (~A).
spacing() ) );
445 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
448 const int minimum(
min( m, n ) );
449 const int maximum(
max( m, n ) );
451 int lwork( 2*minimum + maximum + 2 );
452 const std::unique_ptr<CT[]> work (
new CT[lwork] );
453 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
455 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
456 m, n, (~A).
data(), lda, (~s).
data(),
457 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
458 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
459 work.get(), lwork, rwork.get(), &info );
572 template<
typename MT1
597 const size_t M( (~A).
rows() );
598 const size_t N( (~A).
columns() );
599 const size_t mindim(
min( M, N ) );
601 if( jobu !=
'A' && jobu !=
'S' && jobu !=
'N' ) {
605 if( jobv !=
'O' && jobv !=
'N' ) {
609 resize( ~s, mindim,
false );
612 resize( ~U, M, ( jobu ==
'A' ? M : mindim ),
false );
615 if( M == 0UL || N == 0UL ) {
619 gesvd_backend( ~A, ~U, ~s, jobu, jobv );
644 template<
typename MT1
649 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
650 DenseMatrix<MT2,SO>& V,
char jobu,
char jobv )
651 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
660 using ET = ElementType_t<MT1>;
662 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
663 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
664 int lda ( numeric_cast<int>( (~A).
spacing() ) );
665 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
668 const int minimum(
min( m, n ) );
669 const int maximum(
max( m, n ) );
671 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
672 const std::unique_ptr<ET[]> work(
new ET[lwork] );
674 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
675 m, n, (~A).
data(), lda, (~s).
data(),
676 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
677 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
678 work.get(), lwork, &info );
710 template<
typename MT1
715 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
716 DenseMatrix<MT2,SO>& V,
char jobu,
char jobv )
717 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
726 using CT = ElementType_t<MT1>;
727 using BT = UnderlyingElement_t<CT>;
729 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
730 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
731 int lda ( numeric_cast<int>( (~A).
spacing() ) );
732 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
735 const int minimum(
min( m, n ) );
736 const int maximum(
max( m, n ) );
738 int lwork( 2*minimum + maximum + 2 );
739 const std::unique_ptr<CT[]> work (
new CT[lwork] );
740 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
742 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
743 m, n, (~A).
data(), lda, (~s).
data(),
744 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
745 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
746 work.get(), lwork, rwork.get(), &info );
859 template<
typename MT1
884 const size_t M( (~A).
rows() );
885 const size_t N( (~A).
columns() );
886 const size_t mindim(
min( M, N ) );
888 if( jobu !=
'O' && jobu !=
'N' ) {
892 if( jobv !=
'A' && jobv !=
'S' && jobv !=
'N' ) {
896 resize( ~s, mindim,
false );
899 resize( ~V, ( jobv ==
'A' ? N : mindim ), N,
false );
902 if( M == 0UL || N == 0UL ) {
906 gesvd_backend( ~A, ~s, ~V, jobu, jobv );
932 template<
typename MT1
938 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
939 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobu,
char jobv )
940 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
952 using ET = ElementType_t<MT1>;
954 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
955 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
956 int lda ( numeric_cast<int>( (~A).
spacing() ) );
957 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
958 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
961 const int minimum(
min( m, n ) );
962 const int maximum(
max( m, n ) );
964 int lwork(
max( 3*minimum + maximum, 5*minimum ) + 2 );
965 const std::unique_ptr<ET[]> work(
new ET[lwork] );
967 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
968 m, n, (~A).
data(), lda, (~s).
data(),
969 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
970 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
971 work.get(), lwork, &info );
1004 template<
typename MT1
1010 inline auto gesvd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
1011 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobu,
char jobv )
1012 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
1024 using CT = ElementType_t<MT1>;
1025 using BT = UnderlyingElement_t<CT>;
1027 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
1028 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
1029 int lda ( numeric_cast<int>( (~A).
spacing() ) );
1030 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
1031 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
1034 const int minimum(
min( m, n ) );
1035 const int maximum(
max( m, n ) );
1037 int lwork( 2*minimum + maximum + 2 );
1038 const std::unique_ptr<CT[]> work (
new CT[lwork] );
1039 const std::unique_ptr<BT[]> rwork(
new BT[5*minimum] );
1041 gesvd( ( SO ? jobu : jobv ), ( SO ? jobv : jobu ),
1042 m, n, (~A).
data(), lda, (~s).
data(),
1043 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
1044 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
1045 work.get(), lwork, rwork.get(), &info );
1165 template<
typename MT1
1197 const size_t M( (~A).
rows() );
1198 const size_t N( (~A).
columns() );
1199 const size_t mindim(
min( M, N ) );
1201 if( jobu !=
'A' && jobu !=
'S' && jobu !=
'N' ) {
1205 if( jobv !=
'A' && jobv !=
'S' && jobv !=
'N' ) {
1209 resize( ~s, mindim,
false );
1212 resize( ~U, M, ( jobu ==
'A' ? M : mindim ),
false );
1213 resize( ~V, ( jobv ==
'A' ? N : mindim ), N,
false );
1216 if( M == 0UL || N == 0UL ) {
1220 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
MT::ElementType * data(DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:169
#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.
Header file for the DenseVector base class.
Header file for the UnderlyingElement type trait.
Constraint on the data type.
Constraint on the data type.
Cast operators for numeric types.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
#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
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
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
#define BLAZE_CONSTRAINT_MUST_BE_CONTIGUOUS_TYPE(T)
Constraint on the data type.In case the given data type T is not an array-like data type with contigu...
Definition: Contiguous.h:61
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
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 exception macros of the math module.
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1179
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:738
Constraint on the data type.
Header file for the EnableIf class template.
Header file for run time assertion macros.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
#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
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
#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.
bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:951
#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