35 #ifndef _BLAZE_MATH_LAPACK_GESDD_H_ 36 #define _BLAZE_MATH_LAPACK_GESDD_H_ 75 template<
typename MT,
bool SO,
typename VT,
bool TF >
76 inline void gesdd( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s );
78 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF >
79 inline void gesdd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
80 DenseVector<VT,TF>& s,
char jobz );
82 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF >
83 inline void gesdd( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
84 DenseMatrix<MT2,SO>& V,
char jobz );
86 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF,
typename MT3 >
87 inline void gesdd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
88 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz );
110 template<
typename MT
114 inline auto gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
115 -> DisableIf_t< IsComplex_v< ElementType_t<MT> > >
119 using ET = ElementType_t<MT>;
121 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
122 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
123 int lda ( numeric_cast<int>( (~A).
spacing() ) );
126 const int minimum(
min( m, n ) );
127 const int maximum(
max( m, n ) );
129 int lwork( 3*minimum +
max( maximum, 7*minimum ) + 2 );
130 const std::unique_ptr<ET[]> work(
new ET[lwork] );
131 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
134 nullptr, 1,
nullptr, 1, work.get(), lwork, iwork.get(), &info );
163 template<
typename MT
167 inline auto gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
168 -> EnableIf_t< IsComplex_v< ElementType_t<MT> > >
172 using CT = ElementType_t<MT>;
173 using BT = UnderlyingElement_t<CT>;
175 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
176 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
177 int lda ( numeric_cast<int>( (~A).
spacing() ) );
180 const int minimum(
min( m, n ) );
181 const int maximum(
max( m, n ) );
183 int lwork( 2*minimum + maximum + 2 );
184 const std::unique_ptr<CT[]> work(
new CT[lwork] );
185 const std::unique_ptr<BT[]> rwork(
new BT[7*minimum] );
186 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
189 nullptr, 1,
nullptr, 1, work.get(), lwork, rwork.get(), iwork.get(), &info );
263 template<
typename MT
280 const size_t M( (~A).
rows() );
281 const size_t N( (~A).
columns() );
282 const size_t mindim(
min( M, N ) );
284 resize( ~s, mindim,
false );
286 if( M == 0UL || N == 0 ) {
290 gesdd_backend( A, s );
314 template<
typename MT1
319 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
320 DenseVector<VT,TF>& s,
char jobz )
321 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
328 using ET = ElementType_t<MT1>;
330 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
331 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
332 int lda ( numeric_cast<int>( (~A).
spacing() ) );
333 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
336 const int minimum(
min( m, n ) );
337 const int maximum(
max( m, n ) );
339 int lwork( ( jobz ==
'O' )
340 ?( 3*minimum +
max( maximum, 5*minimum*minimum + 4*maximum ) + 2 )
341 :( 3*minimum +
max( maximum, 7*minimum ) + 2 ) );
342 const std::unique_ptr<ET[]> work(
new ET[lwork] );
343 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
346 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
347 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
348 work.get(), lwork, iwork.get(), &info );
379 template<
typename MT1
384 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
385 DenseVector<VT,TF>& s,
char jobz )
386 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
393 using CT = ElementType_t<MT1>;
394 using BT = UnderlyingElement_t<CT>;
396 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
397 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
398 int lda ( numeric_cast<int>( (~A).
spacing() ) );
399 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
402 const int minimum(
min( m, n ) );
403 const int maximum(
max( m, n ) );
405 int lwork( ( jobz ==
'O' )
406 ?( 2*minimum*minimum + 2*minimum + maximum + 2 )
407 :( 2*minimum + maximum + 2 ) );
408 const int lrwork( ( jobz ==
'O' )
409 ?(
max( 5*minimum*minimum + 5*minimum,
410 2*maximum*minimum + 2*minimum*minimum + minimum ) )
412 const std::unique_ptr<CT[]> work(
new CT[lwork] );
413 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
414 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
417 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
418 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
419 work.get(), lwork, rwork.get(), iwork.get(), &info );
520 template<
typename MT1
545 const size_t M( (~A).
rows() );
546 const size_t N( (~A).
columns() );
547 const size_t mindim(
min( M, N ) );
549 if( jobz !=
'O' && jobz !=
'N' ) {
553 if( jobz ==
'O' && M >= N ) {
557 resize( ~s, mindim,
false );
560 resize( ~U, M, M,
false );
563 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
567 gesdd_backend( ~A, ~U, ~s, jobz );
591 template<
typename MT1
596 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
597 DenseMatrix<MT2,SO>& V,
char jobz )
598 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
605 using ET = ElementType_t<MT1>;
607 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
608 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
609 int lda ( numeric_cast<int>( (~A).
spacing() ) );
610 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
613 const int minimum(
min( m, n ) );
614 const int maximum(
max( m, n ) );
616 int lwork( ( jobz ==
'O' )
617 ?( 3*minimum +
max( maximum, 5*minimum*minimum + 4*maximum + 2 ) )
618 :( 3*minimum +
max( maximum, 7*minimum ) + 2 ) );
619 const std::unique_ptr<ET[]> work(
new ET[lwork] );
620 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
623 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
624 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
625 work.get(), lwork, iwork.get(), &info );
656 template<
typename MT1
661 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
662 DenseMatrix<MT2,SO>& V,
char jobz )
663 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
670 using CT = ElementType_t<MT1>;
671 using BT = UnderlyingElement_t<CT>;
673 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
674 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
675 int lda ( numeric_cast<int>( (~A).
spacing() ) );
676 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
679 const int minimum(
min( m, n ) );
680 const int maximum(
max( m, n ) );
682 int lwork( ( jobz ==
'O' )
683 ?( 2*minimum*minimum + 2*minimum + maximum + 2 )
684 :( 2*minimum + maximum + 2 ) );
685 const int lrwork( ( jobz ==
'O' )
686 ?(
max( 5*minimum*minimum + 5*minimum,
687 2*maximum*minimum + 2*minimum*minimum + minimum ) )
689 const std::unique_ptr<CT[]> work(
new CT[lwork] );
690 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
691 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
694 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
695 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
696 work.get(), lwork, rwork.get(), iwork.get(), &info );
788 template<
typename MT1
813 const size_t M( (~A).
rows() );
814 const size_t N( (~A).
columns() );
815 const size_t mindim(
min( M, N ) );
817 if( jobz !=
'O' && jobz !=
'N' ) {
821 if( jobz ==
'O' && M < N ) {
825 resize( ~s, mindim,
false );
828 resize( ~V, N, N,
false );
831 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
835 gesdd_backend( ~A, ~s, ~V, jobz );
860 template<
typename MT1
866 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
867 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz )
868 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
879 using ET = ElementType_t<MT1>;
881 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
882 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
883 int lda ( numeric_cast<int>( (~A).
spacing() ) );
884 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
885 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
888 const int minimum(
min( m, n ) );
889 const int maximum(
max( m, n ) );
891 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
892 const std::unique_ptr<ET[]> work(
new ET[lwork] );
893 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
896 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
897 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
898 work.get(), lwork, iwork.get(), &info );
930 template<
typename MT1
936 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
937 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz )
938 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
949 using CT = ElementType_t<MT1>;
950 using BT = UnderlyingElement_t<CT>;
952 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
953 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
954 int lda ( numeric_cast<int>( (~A).
spacing() ) );
955 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
956 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
959 const int minimum(
min( m, n ) );
960 const int maximum(
max( m, n ) );
962 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
963 const int lrwork(
max( 5*minimum*minimum + 5*minimum,
964 2*maximum*minimum + 2*minimum*minimum + minimum ) );
965 const std::unique_ptr<CT[]> work(
new CT[lwork] );
966 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
967 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
970 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
971 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
972 work.get(), lwork, rwork.get(), iwork.get(), &info );
1086 template<
typename MT1
1118 const size_t M( (~A).
rows() );
1119 const size_t N( (~A).
columns() );
1120 const size_t mindim(
min( M, N ) );
1122 if( jobz !=
'A' && jobz !=
'S' && jobz !=
'N' ) {
1126 resize( ~s, mindim,
false );
1129 resize( ~U, M, ( jobz ==
'A' ? M : mindim ),
false );
1130 resize( ~V, ( jobz ==
'A' ? N : mindim ), N,
false );
1133 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
1137 gesdd_backend( ~A, ~U, ~s, ~V, jobz );
#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.
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 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
void gesdd(char jobz, int m, int n, float *A, int lda, float *s, float *U, int ldu, float *V, int ldv, float *work, int lwork, int *iwork, int *info)
LAPACK kernel for the singular value decomposition (SVD) of the given dense general single precision ...
Definition: gesdd.h:165
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.
Header file for the CLAPACK gesdd wrapper functions.
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