Blaze 3.9
SVD.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_DENSE_SVD_H_
36#define _BLAZE_MATH_DENSE_SVD_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
53#include <blaze/util/mpl/If.h>
54
55
56namespace blaze {
57
58//=================================================================================================
59//
60// SINGULAR VALUE DECOMPOSITION FUNCTIONS
61//
62//=================================================================================================
63
64//*************************************************************************************************
67template< typename MT, bool SO, typename VT, bool TF >
68inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s );
69
70template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3 >
71inline void svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
72 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, bool square = false );
73
74template< typename MT, bool SO, typename VT, bool TF, typename ST >
75inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp );
76
77template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3, typename ST >
78inline size_t svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
79 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, ST low, ST upp );
81//*************************************************************************************************
82
83
84//*************************************************************************************************
131template< typename MT // Type of the matrix A
132 , bool SO // Storage order of the matrix A
133 , typename VT // Type of the vector s
134 , bool TF > // Transpose flag of the vector s
135inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
136{
139
143
145 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
146
151
152 ATmp Atmp( *A );
153 STmp stmp( *s );
154
155 gesdd( Atmp, stmp );
156
157 if( !IsContiguous_v<VT> ) {
158 (*s) = stmp;
159 }
160}
161//*************************************************************************************************
162
163
164//*************************************************************************************************
222template< typename MT1 // Type of the matrix A
223 , bool SO // Storage order of all matrices
224 , typename VT // Type of the vector s
225 , bool TF // Transpose flag of the vector s
226 , typename MT2 // Type of the matrix U
227 , typename MT3 > // Type of the matrix V
229 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, bool square )
230{
233
238
242
247
249 using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
250 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
251 using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
252
257
258 ATmp Atmp( *A );
259 UTmp Utmp( *U );
260 STmp stmp( *s );
261 VTmp Vtmp( *V );
262
263 gesdd( Atmp, Utmp, stmp, Vtmp, (square) ? 'A' : 'S' );
264
265 if( !IsContiguous_v<MT2> ) {
266 (*U) = Utmp;
267 }
268
269 if( !IsContiguous_v<VT> ) {
270 (*s) = stmp;
271 }
272
273 if( !IsContiguous_v<MT3> ) {
274 (*V) = Vtmp;
275 }
276}
277//*************************************************************************************************
278
279
280//*************************************************************************************************
342template< typename MT // Type of the matrix A
343 , bool SO // Storage order of the matrix A
344 , typename VT // Type of the vector s
345 , bool TF // Transpose flag of the vector s
346 , typename ST > // Type of the scalar boundary values
347inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp )
348{
351
355
357
359 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
360
365
366 ATmp Atmp( *A );
367 STmp stmp( *s );
368
369 const auto num = gesvdx( Atmp, stmp, low, upp );
370
371 if( !IsContiguous_v<VT> ) {
372 (*s) = stmp;
373 }
374
375 return num;
376}
377//*************************************************************************************************
378
379
380//*************************************************************************************************
458template< typename MT1 // Type of the matrix A
459 , bool SO // Storage order of all matrices
460 , typename VT // Type of the vector s
461 , bool TF // Transpose flag of the vector s
462 , typename MT2 // Type of the matrix U
463 , typename MT3 // Type of the matrix V
464 , typename ST > // Type of the scalar boundary values
465inline size_t svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
466 DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, ST low, ST upp )
467{
470
475
479
484
486
488 using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
489 using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
490 using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
491
496
497 ATmp Atmp( *A );
498 UTmp Utmp( *U );
499 STmp stmp( *s );
500 VTmp Vtmp( *V );
501
502 const auto num = gesvdx( Atmp, Utmp, stmp, Vtmp, low, upp );
503
504 if( !IsContiguous_v<MT2> ) {
505 (*U) = Utmp;
506 }
507
508 if( !IsContiguous_v<VT> ) {
509 (*s) = stmp;
510 }
511
512 if( !IsContiguous_v<MT3> ) {
513 (*V) = Vtmp;
514 }
515
516 return num;
517}
518//*************************************************************************************************
519
520} // namespace blaze
521
522#endif
Constraint on the data type.
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
Constraint on the data type.
Header file for the If class template.
Header file for the IsContiguous type trait.
Constraint on the data type.
Header file for the RemoveAdaptor type trait.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Constraint on the data type.
Header file for the DenseMatrix base class.
Header file for the DenseVector base class.
Header file for the LAPACK singular value decomposition functions (gesdd)
Header file for the LAPACK singular value decomposition functions (gesvdx)
#define BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE(T)
Constraint on the data type.
Definition: Builtin.h:60
size_t svd(const DenseMatrix< MT1, SO > &A, DenseMatrix< MT2, SO > &U, DenseVector< VT, TF > &s, DenseMatrix< MT3, SO > &V, ST low, ST upp)
Singular value decomposition (SVD) of the given dense general matrix.
Definition: SVD.h:465
void gesdd(char jobz, blas_int_t m, blas_int_t n, float *A, blas_int_t lda, float *s, float *U, blas_int_t ldu, float *V, blas_int_t ldv, float *work, blas_int_t lwork, blas_int_t *iwork, blas_int_t *info)
LAPACK kernel for the singular value decomposition (SVD) of the given dense general single precision ...
Definition: gesdd.h:185
void gesvdx(char jobu, char jobv, char range, blas_int_t m, blas_int_t n, float *A, blas_int_t lda, float vl, float vu, blas_int_t il, blas_int_t iu, blas_int_t *ns, float *s, float *U, blas_int_t ldu, float *V, blas_int_t ldv, float *work, blas_int_t lwork, blas_int_t *iwork, blas_int_t *info)
LAPACK kernel for the singular value decomposition (SVD) of the given dense general single precision ...
Definition: gesvdx.h:213
#define BLAZE_CONSTRAINT_MUST_BE_BLAS_COMPATIBLE_TYPE(T)
Constraint on the data type.
Definition: BLASCompatible.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ADAPTOR_TYPE(T)
Constraint on the data type.
Definition: Adaptor.h:81
#define BLAZE_CONSTRAINT_MUST_HAVE_MUTABLE_DATA_ACCESS(T)
Constraint on the data type.
Definition: MutableDataAccess.h:61
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108