43 #include <visp/vpConfig.h>
45 #include <visp/vpMatrix.h>
46 #include <visp/vpMath.h>
47 #include <visp/vpColVector.h>
50 #include <visp/vpException.h>
51 #include <visp/vpMatrixException.h>
54 #include <visp/vpDebug.h>
56 int allocate_work(
double** work);
58 #ifdef VISP_HAVE_LAPACK
59 extern "C" int dgeqrf_(
int *m,
int *n,
double*a,
int *lda,
double *tau,
double *work,
int *lwork,
int *info);
60 extern "C" int dormqr_(
char *side,
char *trans,
int *m,
int *n,
61 int *k,
double *a,
int *lda,
double *tau,
double *c__,
62 int *ldc,
double *work,
int *lwork,
int *info);
63 extern "C" int dorgqr_(
int *,
int *,
int *,
double *,
int *,
64 double *,
double *,
int *,
int *);
65 extern "C" int dtrtri_(
char *uplo,
char *diag,
int *n,
double *a,
int *lda,
int *info);
68 int allocate_work(
double** work)
70 unsigned int dimWork = (
unsigned int)((*work)[0]);
72 *work =
new double[dimWork];
75 #ifdef VISP_HAVE_LAPACK
77 int rowNum_ = (int)this->
getRows();
78 int colNum_ = (int)this->
getCols();
79 int lda = (int)rowNum_;
80 int dimTau = std::min(rowNum_,colNum_);
82 double *tau =
new double[dimTau];
83 double *work =
new double[1];
110 std::cout <<
"dgeqrf_:Preparation:" << -info <<
"th element had an illegal value" << std::endl;
113 dimWork = allocate_work(&work);
136 std::cout <<
"dgeqrf_:" << -info <<
"th element had an illegal value" << std::endl;
144 dtrtri_((
char*)
"U",(
char*)
"N",&dimTau,C.
data,&lda,&info);
147 std::cout <<
"dtrtri_:"<< -info <<
"th element had an illegal value" << std::endl;
149 std::cout <<
"dtrtri_:R("<< info <<
"," <<info <<
")"<<
" is exactly zero. The triangular matrix is singular and its inverse can not be computed." << std::endl;
150 std::cout <<
"R=" << std::endl << C << std::endl;
158 for(
unsigned int i=0;i<C.
getRows();i++)
159 for(
unsigned int j=0;j<C.
getRows();j++)
160 if(j>i) C[i][j] = 0.;
169 dormqr_((
char*)
"R", (
char*)
"T", &rowNum_, &colNum_, &dimTau, A.
data, &lda, tau, C.
data, &ldc, work, &dimWork, &info);
171 std::cout <<
"dormqr_:Preparation"<< -info <<
"th element had an illegal value" << std::endl;
174 dimWork = allocate_work(&work);
176 dormqr_((
char*)
"R", (
char*)
"T", &rowNum_, &colNum_, &dimTau, A.
data, &lda, tau, C.
data, &ldc, work, &dimWork, &info);
179 std::cout <<
"dormqr_:"<< -info <<
"th element had an illegal value" << std::endl;
226 #if defined(VISP_HAVE_LAPACK)
235 "Cannot invert a non-square vpMatrix")) ;
237 #ifdef VISP_HAVE_LAPACK
Definition of the vpMatrix class.
double * data
address of the first element of the data array
vpMatrix inverseByQR() const
unsigned int rowNum
number of rows
unsigned int getCols() const
Return the number of columns of the matrix.
error that can be emited by the vpMatrix class and its derivates
unsigned int colNum
number of columns
unsigned int getRows() const
Return the number of rows of the matrix.
vpMatrix inverseByQRLapack() const