42 #include <visp3/core/vpConfig.h> 44 #include <visp3/core/vpColVector.h> 45 #include <visp3/core/vpMath.h> 46 #include <visp3/core/vpMatrix.h> 49 #include <visp3/core/vpException.h> 50 #include <visp3/core/vpMatrixException.h> 53 #include <visp3/core/vpDebug.h> 55 #ifdef VISP_HAVE_LAPACK 58 typedef MKL_INT integer;
60 integer allocate_work(
double **work)
62 integer dimWork = (integer)((*work)[0]);
64 *work =
new double[dimWork];
65 return (integer)dimWork;
68 # ifdef VISP_HAVE_LAPACK_BUILT_IN 69 typedef long int integer;
73 extern "C" int dgeqrf_(integer *m, integer *n,
double *a, integer *lda,
double *tau,
double *work, integer *lwork,
75 extern "C" int dormqr_(
char *side,
char *trans, integer *m, integer *n, integer *k,
double *a, integer *lda,
76 double *tau,
double *c__, integer *ldc,
double *work, integer *lwork, integer *info);
77 extern "C" int dorgqr_(integer *, integer *, integer *,
double *, integer *,
double *,
double *, integer *, integer *);
78 extern "C" int dtrtri_(
char *uplo,
char *diag, integer *n,
double *a, integer *lda, integer *info);
79 extern "C" int dgeqp3_(integer *m, integer *n,
double*a, integer *lda, integer *p,
80 double *tau,
double *work, integer* lwork, integer *info);
82 int allocate_work(
double **work);
84 int allocate_work(
double **work)
86 unsigned int dimWork = (
unsigned int)((*work)[0]);
88 *work =
new double[dimWork];
94 #if defined(VISP_HAVE_LAPACK) 131 integer rowNum_ = (integer)this->
getRows();
132 integer colNum_ = (integer)this->
getCols();
133 integer lda = (integer)rowNum_;
134 integer dimTau = (std::min)(rowNum_, colNum_);
135 integer dimWork = -1;
136 double *tau =
new double[dimTau];
137 double *work =
new double[1];
164 std::cout <<
"dgeqrf_:Preparation:" << -info <<
"th element had an illegal value" << std::endl;
167 dimWork = allocate_work(&work);
189 std::cout <<
"dgeqrf_:" << -info <<
"th element had an illegal value" << std::endl;
198 dtrtri_((
char *)
"U", (
char *)
"N", &dimTau, C.
data, &lda, &info);
201 std::cout <<
"dtrtri_:" << -info <<
"th element had an illegal value" << std::endl;
203 std::cout <<
"dtrtri_:R(" << info <<
"," << info <<
")" 204 <<
" is exactly zero. The triangular matrix is singular " 205 "and its inverse can not be computed." 207 std::cout <<
"R=" << std::endl << C << std::endl;
216 for (
unsigned int i = 0; i < C.
getRows(); i++)
217 for (
unsigned int j = 0; j < C.
getRows(); j++)
228 dormqr_((
char *)
"R", (
char *)
"T", &rowNum_, &colNum_, &dimTau, A.
data, &lda, tau, C.
data, &ldc, work, &dimWork,
231 std::cout <<
"dormqr_:Preparation" << -info <<
"th element had an illegal value" << std::endl;
234 dimWork = allocate_work(&work);
236 dormqr_((
char *)
"R", (
char *)
"T", &rowNum_, &colNum_, &dimTau, A.
data, &lda, tau, C.
data, &ldc, work, &dimWork,
240 std::cout <<
"dormqr_:" << -info <<
"th element had an illegal value" << std::endl;
287 #if defined(VISP_HAVE_LAPACK) 351 #if defined(VISP_HAVE_LAPACK) 352 integer m = (integer)
rowNum;
353 integer n = (integer)
colNum;
354 integer r = std::min(n, m);
366 Q.
resize(static_cast<unsigned int>(m), static_cast<unsigned int>(q));
368 R.
resize(static_cast<unsigned int>(r), static_cast<unsigned int>(r));
370 R.
resize(static_cast<unsigned int>(r), static_cast<unsigned int>(n));
374 integer dimWork = -1;
375 double * qrdata =
new double[m*na];
376 double *tau =
new double[std::min(m,q)];
377 double *work =
new double[1];
381 for (integer i = 0; i < m; ++i)
383 for (integer j = 0; j < n; ++j)
384 qrdata[i + m * j] =
data[j + n * i];
385 for (integer j = n; j < na; ++j)
386 qrdata[i + m * j] = 0;
403 std::cout <<
"dgeqrf_:Preparation:" << -info <<
"th element had an illegal value" << std::endl;
409 dimWork = allocate_work(&work);
423 std::cout <<
"dgeqrf_:" << -info <<
"th element had an illegal value" << std::endl;
436 for(
int i=0;i<na;i++)
438 for(
int j=i;j<na;j++)
439 R[i][j] = qrdata[i+m*j];
440 if(std::abs(qrdata[i+m*i]) < tol)
446 for(
int i=0;i<na;i++)
449 R[i][j] = qrdata[i+m*j];
450 if(std::abs(qrdata[i+m*i]) < tol)
468 for(
int i = 0; i < m; ++i)
469 for(
int j = 0; j < q; ++j)
470 Q[i][j] = qrdata[i+m*j];
475 return (
unsigned int) r;
551 #if defined(VISP_HAVE_LAPACK) 552 integer m = (integer)
rowNum;
553 integer n = (integer)
colNum;
554 integer r = std::min(n,m);
566 Q.
resize(static_cast<unsigned int>(m), static_cast<unsigned int>(q));
572 P.
resize(0, static_cast<unsigned int>(n));
576 R.
resize(static_cast<unsigned int>(r), static_cast<unsigned int>(n));
577 P.
resize(static_cast<unsigned int>(n), static_cast<unsigned int>(n));
582 integer dimWork = -1;
583 double* qrdata =
new double[m*na];
584 double* tau =
new double[std::min(q,m)];
585 double* work =
new double[1];
586 integer* p =
new integer[na];
587 for(
int i = 0; i < na; ++i)
593 for(integer i = 0; i < m; ++i)
595 for(integer j = 0; j < n; ++j)
596 qrdata[i+m*j] =
data[j + n*i];
597 for(integer j = n; j < na; ++j)
616 std::cout <<
"dgeqp3_:Preparation:" << -info <<
"th element had an illegal value" << std::endl;
624 dimWork = allocate_work(&work);
640 std::cout <<
"dgeqp3_:" << -info <<
" th element had an illegal value" << std::endl;
652 for(
int i = 0; i < na; ++i)
653 if(std::abs(qrdata[i+m*i]) < tol)
659 R.
resize(static_cast<unsigned int>(r), static_cast<unsigned int>(r));
662 R[i][j] = qrdata[i+m*j];
665 P.
resize(static_cast<unsigned int>(r), static_cast<unsigned int>(n));
666 for(
int i = 0; i < r; ++i)
671 R.
resize(static_cast<unsigned int>(na), static_cast<unsigned int>(n));
672 for(
int i=0;i<na;i++)
674 R[i][j] = qrdata[i+m*j];
676 P.
resize(static_cast<unsigned int>(n), static_cast<unsigned int>(n));
677 for(
int i = 0; i < n; ++i)
694 for(
int i = 0; i < m; ++i)
695 for(
int j = 0; j < q; ++j)
696 Q[i][j] = qrdata[i+m*j];
702 return (
unsigned int) r;
727 #if defined(VISP_HAVE_LAPACK) 731 integer n = (integer)
rowNum;
738 dtrtri_((
char *)
"L", (
char *)
"N", &n, R.
data, &n, &info);
740 dtrtri_((
char *)
"U", (
char *)
"N", &n, R.
data, &n, &info);
744 std::cout <<
"dtrtri_:" << -info <<
"th element had an illegal value" << std::endl;
746 std::cout <<
"dtrtri_:R(" << info <<
"," << info <<
")" 747 <<
" is exactly zero. The triangular matrix is singular " 748 "and its inverse can not be computed." 807 unsigned int r =
t().
qrPivot(Q, R, P,
false,
true);
vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const
Used to indicate that a value is not in the allowed range.
Implementation of a matrix and operations on matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
vpMatrix inverseByQR() const
unsigned int qrPivot(vpMatrix &Q, vpMatrix &R, vpMatrix &P, bool full=false, bool squareR=false, double tol=1e-6) const
error that can be emited by ViSP classes.
unsigned int getRows() const
Type * data
Address of the first element of the data array.
vpMatrix inverseTriangular(bool upper=true) const
vpMatrix inverseByQRLapack() const
unsigned int getCols() const
unsigned int rowNum
Number of rows in the array.
unsigned int qr(vpMatrix &Q, vpMatrix &R, bool full=false, bool squareR=false, double tol=1e-6) const
void solveByQR(const vpColVector &b, vpColVector &x) const
unsigned int colNum
Number of columns in the array.
Implementation of column vector and the associated operations.
error that can be emited by the vpMatrix class and its derivates