22#ifndef BELFEM_FN_GELS_HPP
23#define BELFEM_FN_GELS_HPP
115 template<
typename T >
130 "gels not implemented for selected data type" );
150 const_cast< char *
>(
trans ),
151 const_cast< int_t *
>( m ),
152 const_cast< int_t *
>( n ),
153 const_cast< int_t *
>( nrhs ),
155 const_cast< int_t *
>( lda ),
157 const_cast< int_t *
>( ldb ),
159 const_cast< int_t *
>( lwork ),
181 const_cast< char *
>(
trans ),
182 const_cast< int_t *
>( m ),
183 const_cast< int_t *
>( n ),
184 const_cast< int_t *
>( nrhs ),
186 const_cast< int_t *
>( lda ),
188 const_cast< int_t *
>( ldb ),
190 const_cast< int_t *
>( lwork ),
203 std::complex< float > * a,
205 std::complex< float > * b,
207 std::complex< float > * work,
212 const_cast< char *
>(
trans ),
213 const_cast< int_t *
>( m ),
214 const_cast< int_t *
>( n ),
215 const_cast< int_t *
>( nrhs ),
217 const_cast< int_t *
>( lda ),
219 const_cast< int_t *
>( ldb ),
221 const_cast< int_t *
>( lwork ),
234 std::complex< double > * a,
236 std::complex< double > * b,
238 std::complex< double > * work,
243 const_cast< char *
>(
trans ),
244 const_cast< int_t *
>( m ),
245 const_cast< int_t *
>( n ),
246 const_cast< int_t *
>( nrhs ),
248 const_cast< int_t *
>( lda ),
250 const_cast< int_t *
>( ldb ),
252 const_cast< int_t *
>( lwork ),
276 template<
typename T >
285 "Length of rhs vector is %i, but must be at least %i.",
286 (
int ) B.length(), (
int ) std::max( m, n ) );
296 int_t mn = std::min( m, n );
297 int_t lwork = std::max< int_t >( 1, mn + std::max( mn, nrhs ) );
301 if (
static_cast< int_t >( Work.
length() ) < lwork )
308 lapack::gels( &
trans, &m, &n, &nrhs, A.
data(), &lda, B.data(), &ldb, Work.
data(), &query, &info );
311 "LAPACK gels workspace query has thrown an error: %i", (
int ) info );
313 if ( info != 0 )
return info ;
340 "LAPACK gels has thrown an error: %i", (
int ) info );
359 template<
typename T >
368 "Number of rows of rhs matrix is %i, but must be at least %i.",
369 (
int ) B.n_rows(), (
int ) std::max( m, n ) );
373 int_t nrhs = B.n_cols() ;
378 int_t mn = std::min( m, n );
379 int_t lwork = std::max< int_t >( 1, mn + std::max( mn, nrhs ) );
383 if (
static_cast< int_t >( Work.
length() ) < lwork )
390 lapack::gels( &
trans, &m, &n, &nrhs, A.
data(), &lda, B.data(), &ldb, Work.
data(), &query, &info );
393 "LAPACK gels workspace query has thrown an error: %i", (
int ) info );
395 if ( info != 0 )
return info ;
407 lapack::gels( &
trans, &m, &n, &nrhs, A.
data(), &lda, B.data(), &ldb, Work.
data(), &lwork, &info );
412 "LAPACK gels 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
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
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_AR_Vector.hpp:182
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
Definition fn_gees.hpp:33
void dgels_(char *trans, int_t *m, int_t *n, int_t *nrhs, double *a, int_t *lda, double *b, int_t *ldb, double *work, int_t *lwork, int_t *info, fortran_charlen_t lt)
constexpr bool dependent_false
Definition lapacktools.hpp:49
float cplx_float_t
Definition lapacktools.hpp:90
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 sgels_(char *trans, int_t *m, int_t *n, int_t *nrhs, float *a, int_t *lda, float *b, int_t *ldb, float *work, int_t *lwork, int_t *info, fortran_charlen_t lt)
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
void cgels_(char *trans, int_t *m, int_t *n, int_t *nrhs, cplx_float_t *a, int_t *lda, cplx_float_t *b, int_t *ldb, cplx_float_t *work, int_t *lwork, int_t *info, fortran_charlen_t lt)
size_t fortran_charlen_t
Definition lapacktools.hpp:100
void zgels_(char *trans, int_t *m, int_t *n, int_t *nrhs, cplx_double_t *a, int_t *lda, cplx_double_t *b, int_t *ldb, cplx_double_t *work, int_t *lwork, int_t *info, fortran_charlen_t lt)
double cplx_double_t
Definition lapacktools.hpp:91
void gels(const char *trans, const int_t *m, const int_t *n, const int_t *nrhs, T *a, const int_t *lda, T *b, const int_t *ldb, T *work, const int_t *lwork, int_t *info)
Definition fn_gels.hpp:117
USER GUIDES:
Definition cl_Capacitor.cpp:16
int_t gels(Matrix< T > &A, Vector< T > &B, Vector< T > &Work, const bool AbortOnError=true)
solve the least squares problem min || A * x - b || via LAPACK ?gels ( QR or LQ factorization,...
Definition fn_gels.hpp:278
auto trans(Matrix< T > &aMatrix) -> decltype(trans(aMatrix.matrix_data()))
Definition fn_trans.hpp:74
int32_t int_t
Definition typedefs.hpp:51