22#ifndef BELFEM_FN_GESVD_HPP
23#define BELFEM_FN_GESVD_HPP
135 template<
typename T >
154 "gesvd not implemented for selected data type" );
178 const_cast< char *
>( jobu ),
179 const_cast< char *
>( jobvt ),
180 const_cast< int_t *
>( m ),
181 const_cast< int_t *
>( n ),
183 const_cast< int_t *
>( lda ),
186 const_cast< int_t *
>( ldu ),
188 const_cast< int_t *
>( ldvt ),
190 const_cast< int_t *
>( lwork ),
216 const_cast< char *
>( jobu ),
217 const_cast< char *
>( jobvt ),
218 const_cast< int_t *
>( m ),
219 const_cast< int_t *
>( n ),
221 const_cast< int_t *
>( lda ),
224 const_cast< int_t *
>( ldu ),
226 const_cast< int_t *
>( ldvt ),
228 const_cast< int_t *
>( lwork ),
241 std::complex< float > * a,
244 std::complex< float > * u,
246 std::complex< float > * vt,
248 std::complex< float > * work,
254 const_cast< char *
>( jobu ),
255 const_cast< char *
>( jobvt ),
256 const_cast< int_t *
>( m ),
257 const_cast< int_t *
>( n ),
259 const_cast< int_t *
>( lda ),
262 const_cast< int_t *
>( ldu ),
264 const_cast< int_t *
>( ldvt ),
266 const_cast< int_t *
>( lwork ),
280 std::complex< double > * a,
283 std::complex< double > * u,
285 std::complex< double > * vt,
287 std::complex< double > * work,
293 const_cast< char *
>( jobu ),
294 const_cast< char *
>( jobvt ),
295 const_cast< int_t *
>( m ),
296 const_cast< int_t *
>( n ),
298 const_cast< int_t *
>( lda ),
301 const_cast< int_t *
>( ldu ),
303 const_cast< int_t *
>( ldvt ),
305 const_cast< int_t *
>( lwork ),
338 template<
typename T >
346 const char jobu =
'A',
347 const char jobvt =
'A',
348 const bool AbortOnError =
true )
351 "unsupported jobu flag '%c'", jobu );
353 "unsupported jobvt flag '%c'", jobvt );
356 constexpr int_t tRealsPerT =
357 std::is_same< T, lapack::real_t< T > >
::value ? 1 : 2 ;
361 int_t mn = std::min( m, n );
372 U.
set_size( m, jobu ==
'A' ? m : mn );
380 VT.
set_size( jobvt ==
'A' ? n : mn, n );
385 int_t tRWorkSize = tRealsPerT == 1 ? 0 : 5 * mn ;
389 int_t lwork = std::max< int_t >( 1, tRealsPerT == 1 ?
390 std::max( 3 * mn + std::max( m, n ), 5 * mn ) :
391 2 * mn + std::max( m, n ) );
396 if (
static_cast< int_t >( Work.length() ) < tRealsPerT * lwork + tRWorkSize )
401 if (
static_cast< int_t >( Work.length() ) < tRealsPerT + tRWorkSize )
403 Work.set_size( tRealsPerT + tRWorkSize );
410 reinterpret_cast< T *
>( Work.data() ), &query,
411 Work.data() + tRealsPerT, &info );
414 "LAPACK gesvd workspace query has thrown an error: %i", (
int ) info );
416 if ( info != 0 )
return info ;
425 Work.set_size( tRealsPerT * lwork + tRWorkSize );
430 lwork = ( (
int_t ) Work.length() - tRWorkSize ) / tRealsPerT ;
436 reinterpret_cast< T *
>( Work.data() ), &lwork,
437 Work.data() + tRealsPerT * lwork, &info );
441 "LAPACK gesvd has thrown an error: %i", (
int ) info );
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Dense column-major matrix.
Definition cl_BZ_Matrix.hpp:28
void set_size(const size_t aNumRows, const size_t aNumCols)
Definition cl_AR_Matrix.hpp:186
size_t n_rows() const
Definition cl_AR_Matrix.hpp:205
size_t n_cols() const
Definition cl_AR_Matrix.hpp:213
T * data()
Definition cl_AR_Matrix.hpp:135
Column vector.
Definition cl_BZ_Vector.hpp:41
Definition fn_gees.hpp:33
constexpr bool dependent_false
Definition lapacktools.hpp:49
float cplx_float_t
Definition lapacktools.hpp:90
void gesvd(const char *jobu, const char *jobvt, const int_t *m, const int_t *n, T *a, const int_t *lda, real_t< T > *s, T *u, const int_t *ldu, T *vt, const int_t *ldvt, T *work, const int_t *lwork, real_t< T > *rwork, int_t *info)
Definition fn_gesvd.hpp:136
int_t leading_dimension(const Vector< T > &A)
logical length of a vector operand, as passed to LAPACK as LDB; vector storage is contiguous under bo...
Definition lapacktools.hpp:143
void dgesvd_(char *jobu, char *jobvt, int_t *m, int_t *n, double *a, int_t *lda, double *s, double *u, int_t *ldu, double *vt, int_t *ldvt, double *work, int_t *lwork, int_t *info, fortran_charlen_t lu, fortran_charlen_t lvt)
void zgesvd_(char *jobu, char *jobvt, int_t *m, int_t *n, cplx_double_t *a, int_t *lda, double *s, cplx_double_t *u, int_t *ldu, cplx_double_t *vt, int_t *ldvt, cplx_double_t *work, int_t *lwork, double *rwork, int_t *info, fortran_charlen_t lu, fortran_charlen_t lvt)
int_t work_size(const float &aValue)
lapack reports the optimal work size in the first entry of the work array, which stays real valued fo...
Definition lapacktools.hpp:191
size_t fortran_charlen_t
Definition lapacktools.hpp:100
double cplx_double_t
Definition lapacktools.hpp:91
void cgesvd_(char *jobu, char *jobvt, int_t *m, int_t *n, cplx_float_t *a, int_t *lda, float *s, cplx_float_t *u, int_t *ldu, cplx_float_t *vt, int_t *ldvt, cplx_float_t *work, int_t *lwork, float *rwork, int_t *info, fortran_charlen_t lu, fortran_charlen_t lvt)
typename real_type< T >::type real_t
Definition lapacktools.hpp:63
void sgesvd_(char *jobu, char *jobvt, int_t *m, int_t *n, float *a, int_t *lda, float *s, float *u, int_t *ldu, float *vt, int_t *ldvt, float *work, int_t *lwork, int_t *info, fortran_charlen_t lu, fortran_charlen_t lvt)
USER GUIDES:
Definition cl_Capacitor.cpp:16
int_t gesvd(Matrix< T > &A, Vector< lapack::real_t< T > > &S, Matrix< T > &U, Matrix< T > &VT, Vector< lapack::real_t< T > > &Work, const char jobu='A', const char jobvt='A', const bool AbortOnError=true)
singular value decomposition A = U * diag( S ) * VT via LAPACK ?gesvd
Definition fn_gesvd.hpp:340
std::pair< real, unit > value
Definition typedefs.hpp:74
int32_t int_t
Definition typedefs.hpp:51