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 DisableIf_< IsComplex< ElementType_<MT> > >
115 gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
119 using ET = ElementType_<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] );
133 gesdd(
'N', m, n, (~A).data(), lda, (~s).data(),
134 nullptr, 1,
nullptr, 1, work.get(), lwork, iwork.get(), &info );
163 template<
typename MT
167 inline EnableIf_< IsComplex< ElementType_<MT> > >
168 gesdd_backend( DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
172 using CT = ElementType_<MT>;
173 using BT = UnderlyingElement_<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] );
188 gesdd(
'N', m, n, (~A).data(), lda, (~s).data(),
189 nullptr, 1,
nullptr, 1, work.get(), lwork, rwork.get(), iwork.get(), &info );
263 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
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] );
343 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
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
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] );
414 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
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
540 const size_t M( (~A).
rows() );
541 const size_t N( (~A).
columns() );
542 const size_t mindim(
min( M, N ) );
544 if( jobz !=
'O' && jobz !=
'N' ) {
548 if( jobz ==
'O' && M >= N ) {
552 resize( ~s, mindim,
false );
555 resize( ~U, M, M,
false );
558 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
562 gesdd_backend( ~A, ~U, ~s, jobz );
586 template<
typename MT1
602 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
603 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
604 int lda ( numeric_cast<int>( (~A).
spacing() ) );
605 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
608 const int minimum(
min( m, n ) );
609 const int maximum(
max( m, n ) );
611 int lwork( ( jobz ==
'O' )
612 ?( 3*minimum +
max( maximum, 5*minimum*minimum + 4*maximum + 2 ) )
613 :( 3*minimum +
max( maximum, 7*minimum ) + 2 ) );
614 const std::unique_ptr<ET[]> work(
new ET[lwork] );
615 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
617 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
618 ( SO ?
nullptr : (~V).data() ), ( SO ? 1 : ldv ),
619 ( SO ? (~V).data() :
nullptr ), ( SO ? ldv : 1 ),
620 work.get(), lwork, iwork.get(), &info );
651 template<
typename MT1
668 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
669 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
670 int lda ( numeric_cast<int>( (~A).
spacing() ) );
671 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
674 const int minimum(
min( m, n ) );
675 const int maximum(
max( m, n ) );
677 int lwork( ( jobz ==
'O' )
678 ?( 2*minimum*minimum + 2*minimum + maximum + 2 )
679 :( 2*minimum + maximum + 2 ) );
680 const int lrwork( ( jobz ==
'O' )
681 ?(
max( 5*minimum*minimum + 5*minimum,
682 2*maximum*minimum + 2*minimum*minimum + minimum ) )
684 const std::unique_ptr<CT[]> work(
new CT[lwork] );
685 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
686 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
688 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
689 ( SO ?
nullptr : (~V).data() ), ( SO ? 1 : ldv ),
690 ( SO ? (~V).data() :
nullptr ), ( SO ? ldv : 1 ),
691 work.get(), lwork, rwork.get(), iwork.get(), &info );
783 template<
typename MT1
805 const size_t M( (~A).
rows() );
806 const size_t N( (~A).
columns() );
807 const size_t mindim(
min( M, N ) );
809 if( jobz !=
'O' && jobz !=
'N' ) {
813 if( jobz ==
'O' && M < N ) {
817 resize( ~s, mindim,
false );
820 resize( ~V, N, N,
false );
823 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
827 gesdd_backend( ~A, ~s, ~V, jobz );
852 template<
typename MT1
873 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
874 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
875 int lda ( numeric_cast<int>( (~A).
spacing() ) );
876 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
877 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
880 const int minimum(
min( m, n ) );
881 const int maximum(
max( m, n ) );
883 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
884 const std::unique_ptr<ET[]> work(
new ET[lwork] );
885 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
887 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
888 ( SO ? (~U).data() : (~V).data() ), ( SO ? ldu : ldv ),
889 ( SO ? (~V).data() : (~U).data() ), ( SO ? ldv : ldu ),
890 work.get(), lwork, iwork.get(), &info );
922 template<
typename MT1
944 int m ( numeric_cast<int>( SO ? (~A).
rows() : (~A).
columns() ) );
945 int n ( numeric_cast<int>( SO ? (~A).
columns() : (~A).
rows() ) );
946 int lda ( numeric_cast<int>( (~A).
spacing() ) );
947 int ldu ( numeric_cast<int>( (~U).
spacing() ) );
948 int ldv ( numeric_cast<int>( (~V).
spacing() ) );
951 const int minimum(
min( m, n ) );
952 const int maximum(
max( m, n ) );
954 int lwork( 4*minimum*minimum + 6*minimum + maximum + 2 );
955 const int lrwork(
max( 5*minimum*minimum + 5*minimum,
956 2*maximum*minimum + 2*minimum*minimum + minimum ) );
957 const std::unique_ptr<CT[]> work(
new CT[lwork] );
958 const std::unique_ptr<BT[]> rwork(
new BT[lrwork] );
959 const std::unique_ptr<int[]> iwork(
new int[8*minimum] );
961 gesdd( jobz, m, n, (~A).data(), lda, (~s).data(),
962 ( SO ? (~U).data() : (~V).data() ), ( SO ? ldu : ldv ),
963 ( SO ? (~V).data() : (~U).data() ), ( SO ? ldv : ldu ),
964 work.get(), lwork, rwork.get(), iwork.get(), &info );
1078 template<
typename MT1
1106 const size_t M( (~A).
rows() );
1107 const size_t N( (~A).
columns() );
1108 const size_t mindim(
min( M, N ) );
1110 if( jobz !=
'A' && jobz !=
'S' && jobz !=
'N' ) {
1114 resize( ~s, mindim,
false );
1117 resize( ~U, M, ( jobz ==
'A' ? M : mindim ),
false );
1118 resize( ~V, ( jobz ==
'A' ? N : mindim ), N,
false );
1121 if( (~A).
rows() == 0UL || (~A).
columns() == 0UL ) {
1125 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
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
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:1762
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:1809
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:78
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:110
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:57
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:70
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:340
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.
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:548
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:324
#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.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:742
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