Blaze  3.6
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 
56 namespace blaze {
57 
58 //=================================================================================================
59 //
60 // SINGULAR VALUE DECOMPOSITION FUNCTIONS
61 //
62 //=================================================================================================
63 
64 //*************************************************************************************************
67 template< typename MT, bool SO, typename VT, bool TF >
68 inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s );
69 
70 template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3 >
71 inline void svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
72  DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V );
73 
74 template< typename MT, bool SO, typename VT, bool TF, typename ST >
75 inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp );
76 
77 template< typename MT1, bool SO, typename VT, bool TF, typename MT2, typename MT3, typename ST >
78 inline 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 //*************************************************************************************************
131 template< 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
135 inline void svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s )
136 {
139 
143 
144  using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
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 //*************************************************************************************************
221 template< typename MT1 // Type of the matrix A
222  , bool SO // Storage order of all matrices
223  , typename VT // Type of the vector s
224  , bool TF // Transpose flag of the vector s
225  , typename MT2 // Type of the matrix U
226  , typename MT3 > // Type of the matrix V
227 inline void svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
229 {
232 
237 
241 
246 
247  using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
248  using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
249  using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
250  using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
251 
256 
257  ATmp Atmp( ~A );
258  UTmp Utmp( ~U );
259  STmp stmp( ~s );
260  VTmp Vtmp( ~V );
261 
262  gesdd( Atmp, Utmp, stmp, Vtmp, 'S' );
263 
264  if( !IsContiguous_v<MT2> ) {
265  (~U) = Utmp;
266  }
267 
268  if( !IsContiguous_v<VT> ) {
269  (~s) = stmp;
270  }
271 
272  if( !IsContiguous_v<MT3> ) {
273  (~V) = Vtmp;
274  }
275 }
276 //*************************************************************************************************
277 
278 
279 //*************************************************************************************************
341 template< typename MT // Type of the matrix A
342  , bool SO // Storage order of the matrix A
343  , typename VT // Type of the vector s
344  , bool TF // Transpose flag of the vector s
345  , typename ST > // Type of the scalar boundary values
346 inline size_t svd( const DenseMatrix<MT,SO>& A, DenseVector<VT,TF>& s, ST low, ST upp )
347 {
350 
354 
356 
357  using ATmp = ResultType_t< RemoveAdaptor_t<MT> >;
358  using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
359 
364 
365  ATmp Atmp( ~A );
366  STmp stmp( ~s );
367 
368  const auto num = gesvdx( Atmp, stmp, low, upp );
369 
370  if( !IsContiguous_v<VT> ) {
371  (~s) = stmp;
372  }
373 
374  return num;
375 }
376 //*************************************************************************************************
377 
378 
379 //*************************************************************************************************
457 template< typename MT1 // Type of the matrix A
458  , bool SO // Storage order of all matrices
459  , typename VT // Type of the vector s
460  , bool TF // Transpose flag of the vector s
461  , typename MT2 // Type of the matrix U
462  , typename MT3 // Type of the matrix V
463  , typename ST > // Type of the scalar boundary values
464 inline size_t svd( const DenseMatrix<MT1,SO>& A, DenseMatrix<MT2,SO>& U,
465  DenseVector<VT,TF>& s, DenseMatrix<MT3,SO>& V, ST low, ST upp )
466 {
469 
474 
478 
483 
485 
486  using ATmp = ResultType_t< RemoveAdaptor_t<MT1> >;
487  using UTmp = If_t< IsContiguous_v<MT2>, MT2&, ResultType_t<MT2> >;
488  using STmp = If_t< IsContiguous_v<VT>, VT&, ResultType_t<VT> >;
489  using VTmp = If_t< IsContiguous_v<MT3>, MT3&, ResultType_t<MT3> >;
490 
495 
496  ATmp Atmp( ~A );
497  UTmp Utmp( ~U );
498  STmp stmp( ~s );
499  VTmp Vtmp( ~V );
500 
501  const auto num = gesvdx( Atmp, Utmp, stmp, Vtmp, low, upp );
502 
503  if( !IsContiguous_v<MT2> ) {
504  (~U) = Utmp;
505  }
506 
507  if( !IsContiguous_v<VT> ) {
508  (~s) = stmp;
509  }
510 
511  if( !IsContiguous_v<MT3> ) {
512  (~V) = Vtmp;
513  }
514 
515  return num;
516 }
517 //*************************************************************************************************
518 
519 } // namespace blaze
520 
521 #endif
Constraint on the data type.
#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
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
#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 LAPACK singular value decomposition functions (gesvdx)
Header file for the DenseVector base class.
Constraint on the data type.
#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
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
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 RemoveAdaptor type trait.
Constraint on the data type.
void svd(const DenseMatrix< MT, SO > &A, DenseVector< VT, TF > &s)
Singular value decomposition (SVD) of the given dense general matrix.
Definition: SVD.h:135
void gesvdx(char jobu, char jobv, char range, int m, int n, float *A, int lda, float vl, float vu, int il, int iu, int *ns, 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: gesvdx.h:192
Header file for the IsContiguous type trait.
#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
#define BLAZE_CONSTRAINT_MUST_BE_BUILTIN_TYPE(T)
Constraint on the data type.In case the given data type T is not a built-in data type,...
Definition: Builtin.h:60
Header file for the LAPACK singular value decomposition functions (gesdd)