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 void gesdd( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s );
78 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF >
79 void gesdd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U, DenseVector<VT,TF>& s,
char jobz );
81 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF >
82 void gesdd( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s, DenseMatrix<MT2,SO>& V,
char jobz );
84 template<
typename MT1,
bool SO,
typename MT2,
typename VT,
bool TF,
typename MT3 >
85 void gesdd( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
86 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz );
108 template<
typename MT
112 inline auto gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
113 -> DisableIf_t< IsComplex_v< ElementType_t<MT> > >
117 using ET = ElementType_t<MT>;
119 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
120 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
121 int lda ( numeric_cast<int>( (~A).
spacing() ) );
124 const int minimum(
min( m, n ) );
125 const int maximum(
max( m, n ) );
127 int lwork( 3*minimum +
max( maximum, 7*minimum ) + 2 );
128 const std::unique_ptr<ET[]> work(
new ET[lwork] );
129 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
132 nullptr, 1,
nullptr, 1, work.get(), lwork, iwork.get(), &info );
161 template<
typename MT
165 inline auto gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
166 -> EnableIf_t< IsComplex_v< ElementType_t<MT> > >
170 using CT = ElementType_t<MT>;
171 using BT = UnderlyingElement_t<CT>;
173 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
174 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
175 int lda ( numeric_cast<int>( (~A).
spacing() ) );
178 const int minimum(
min( m, n ) );
179 const int maximum(
max( m, n ) );
181 int lwork( 2*minimum + maximum + 2 );
182 const std::unique_ptr<CT[]> work(
new CT[lwork] );
183 const std::unique_ptr<BT[]> rwork(
new BT[7*minimum] );
184 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
187 nullptr, 1,
nullptr, 1, work.get(), lwork, rwork.get(), iwork.get(), &info );
261 template<
typename MT
278 const size_t M( (~A).
rows() );
279 const size_t N( (~A).
columns() );
280 const size_t mindim(
min( M, N ) );
282 resize( ~s, mindim,
false );
284 if( M == 0UL || N == 0 ) {
288 gesdd_backend( A, s );
312 template<
typename MT1
317 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
318 DenseVector<VT,TF>& s,
char jobz )
319 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
326 using ET = ElementType_t<MT1>;
328 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
329 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
330 int lda ( numeric_cast<int>( (~A).
spacing() ) );
331 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
334 const int minimum(
min( m, n ) );
335 const int maximum(
max( m, n ) );
337 int lwork( ( jobz ==
'O' )
338 ?( 3*minimum +
max( maximum, 5*minimum*minimum + 4*maximum ) + 2 )
339 :( 3*minimum +
max( maximum, 7*minimum ) + 2 ) );
340 const std::unique_ptr<ET[]> work(
new ET[lwork] );
341 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
344 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
345 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
346 work.get(), lwork, iwork.get(), &info );
377 template<
typename MT1
382 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
383 DenseVector<VT,TF>& s,
char jobz )
384 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
391 using CT = ElementType_t<MT1>;
392 using BT = UnderlyingElement_t<CT>;
394 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
395 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
396 int lda ( numeric_cast<int>( (~A).
spacing() ) );
397 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
400 const int minimum(
min( m, n ) );
401 const int maximum(
max( m, n ) );
403 int lwork( ( jobz ==
'O' )
404 ?( 2*minimum*minimum + 2*minimum + maximum + 2 )
405 :( 2*minimum + maximum + 2 ) );
406 const int lrwork( ( jobz ==
'O' )
407 ?(
max( 5*minimum*minimum + 5*minimum,
408 2*maximum*minimum + 2*minimum*minimum + minimum ) )
410 const std::unique_ptr<CT[]> work(
new CT[lwork] );
411 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
412 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
415 ( SO ? (~U).
data() :
nullptr ), ( SO ? ldu : 1 ),
416 ( SO ?
nullptr : (~U).
data() ), ( SO ? 1 : ldu ),
417 work.get(), lwork, rwork.get(), iwork.get(), &info );
518 template<
typename MT1
543 const size_t M( (~A).
rows() );
544 const size_t N( (~A).
columns() );
545 const size_t mindim(
min( M, N ) );
547 if( jobz !=
'O' && jobz !=
'N' ) {
551 if( jobz ==
'O' && M >= N ) {
555 resize( ~s, mindim,
false );
558 resize( ~U, M, M,
false );
561 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
565 gesdd_backend( ~A, ~U, ~s, jobz );
589 template<
typename MT1
594 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
595 DenseMatrix<MT2,SO>& V,
char jobz )
596 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
603 using ET = ElementType_t<MT1>;
605 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
606 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
607 int lda ( numeric_cast<int>( (~A).
spacing() ) );
608 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
611 const int minimum(
min( m, n ) );
612 const int maximum(
max( m, n ) );
614 int lwork( ( jobz ==
'O' )
615 ?( 3*minimum +
max( maximum, 5*minimum*minimum + 4*maximum + 2 ) )
616 :( 3*minimum +
max( maximum, 7*minimum ) + 2 ) );
617 const std::unique_ptr<ET[]> work(
new ET[lwork] );
618 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
621 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
622 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
623 work.get(), lwork, iwork.get(), &info );
654 template<
typename MT1
659 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseVector<VT,TF>& s,
660 DenseMatrix<MT2,SO>& V,
char jobz )
661 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
668 using CT = ElementType_t<MT1>;
669 using BT = UnderlyingElement_t<CT>;
671 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
672 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
673 int lda ( numeric_cast<int>( (~A).
spacing() ) );
674 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
677 const int minimum(
min( m, n ) );
678 const int maximum(
max( m, n ) );
680 int lwork( ( jobz ==
'O' )
681 ?( 2*minimum*minimum + 2*minimum + maximum + 2 )
682 :( 2*minimum + maximum + 2 ) );
683 const int lrwork( ( jobz ==
'O' )
684 ?(
max( 5*minimum*minimum + 5*minimum,
685 2*maximum*minimum + 2*minimum*minimum + minimum ) )
687 const std::unique_ptr<CT[]> work(
new CT[lwork] );
688 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
689 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
692 ( SO ?
nullptr : (~V).
data() ), ( SO ? 1 : ldv ),
693 ( SO ? (~V).
data() :
nullptr ), ( SO ? ldv : 1 ),
694 work.get(), lwork, rwork.get(), iwork.get(), &info );
786 template<
typename MT1
811 const size_t M( (~A).
rows() );
812 const size_t N( (~A).
columns() );
813 const size_t mindim(
min( M, N ) );
815 if( jobz !=
'O' && jobz !=
'N' ) {
819 if( jobz ==
'O' && M < N ) {
823 resize( ~s, mindim,
false );
826 resize( ~V, N, N,
false );
829 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
833 gesdd_backend( ~A, ~s, ~V, jobz );
858 template<
typename MT1
864 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
865 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz )
866 -> DisableIf_t< IsComplex_v< ElementType_t<MT1> > >
877 using ET = ElementType_t<MT1>;
879 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
880 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
881 int lda ( numeric_cast<int>( (~A).
spacing() ) );
882 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
883 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
886 const int minimum(
min( m, n ) );
887 const int maximum(
max( m, n ) );
889 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
890 const std::unique_ptr<ET[]> work(
new ET[lwork] );
891 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
894 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
895 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
896 work.get(), lwork, iwork.get(), &info );
928 template<
typename MT1
934 inline auto gesdd_backend( DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
935 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V,
char jobz )
936 -> EnableIf_t< IsComplex_v< ElementType_t<MT1> > >
947 using CT = ElementType_t<MT1>;
948 using BT = UnderlyingElement_t<CT>;
950 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
951 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
952 int lda ( numeric_cast<int>( (~A).
spacing() ) );
953 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
954 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
957 const int minimum(
min( m, n ) );
958 const int maximum(
max( m, n ) );
960 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
961 const int lrwork(
max( 5*minimum*minimum + 5*minimum,
962 2*maximum*minimum + 2*minimum*minimum + minimum ) );
963 const std::unique_ptr<CT[]> work(
new CT[lwork] );
964 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
965 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
968 ( SO ? (~U).
data() : (~V).
data() ), ( SO ? ldu : ldv ),
969 ( SO ? (~V).
data() : (~U).
data() ), ( SO ? ldv : ldu ),
970 work.get(), lwork, rwork.get(), iwork.get(), &info );
1084 template<
typename MT1
1116 const size_t M( (~A).
rows() );
1117 const size_t N( (~A).
columns() );
1118 const size_t mindim(
min( M, N ) );
1120 if( jobz !=
'A' && jobz !=
'S' && jobz !=
'N' ) {
1124 resize( ~s, mindim,
false );
1127 resize( ~U, M, ( jobz ==
'A' ? M : mindim ),
false );
1128 resize( ~V, ( jobz ==
'A' ? N : mindim ), N,
false );
1131 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
1135 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:170
#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:81
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:253
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:1162
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:174
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:1198
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,...
Definition: Assert.h:101