39 #include <visp3/core/vpConfig.h> 41 #include <visp3/core/vpColVector.h> 42 #include <visp3/core/vpMath.h> 43 #include <visp3/core/vpMatrix.h> 45 #ifdef VISP_HAVE_EIGEN3 50 #include <gsl/gsl_linalg.h> 51 #include <gsl/gsl_permutation.h> 54 #ifdef VISP_HAVE_LAPACK 55 #ifdef VISP_HAVE_LAPACK_BUILT_IN 56 typedef long int integer;
61 extern "C" int dgetrf_(integer *m, integer *n,
double *a, integer *lda, integer *ipiv, integer *info);
62 extern "C" void dgetri_(integer *n,
double *a, integer *lda, integer *ipiv,
double *work, integer *lwork,
66 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 67 #include <opencv2/core/core.hpp> 71 #include <visp3/core/vpException.h> 72 #include <visp3/core/vpMatrixException.h> 132 #if defined(VISP_HAVE_LAPACK) 134 #elif defined(VISP_HAVE_EIGEN3) 136 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 138 #elif defined(VISP_HAVE_GSL) 142 "Lapack, OpenCV or GSL 3rd party"));
183 return ((*
this)[0][0] * (*
this)[1][1] - (*
this)[0][1] * (*
this)[1][0]);
185 return ((*
this)[0][0] * ((*
this)[1][1] * (*
this)[2][2] - (*
this)[1][2] * (*
this)[2][1]) -
186 (*
this)[0][1] * ((*
this)[1][0] * (*
this)[2][2] - (*
this)[1][2] * (*
this)[2][0]) +
187 (*
this)[0][2] * ((*
this)[1][0] * (*
this)[2][1] - (*
this)[1][1] * (*
this)[2][0]));
189 #if defined(VISP_HAVE_LAPACK) 191 #elif defined(VISP_HAVE_EIGEN3) 193 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 195 #elif defined(VISP_HAVE_GSL) 199 "Eigen3, OpenCV or GSL 3rd party"));
205 #if defined(VISP_HAVE_GSL) 246 unsigned int tda = (
unsigned int)A->tda;
247 for (
unsigned int i = 0; i <
rowNum; i++) {
248 unsigned int k = i * tda;
249 for (
unsigned int j = 0; j <
colNum; j++)
250 A->data[k + j] = (*
this)[i][j];
258 inverse.tda = inverse.size2;
259 inverse.data = Ainv.
data;
263 gsl_permutation *p = gsl_permutation_alloc(rowNum);
267 gsl_linalg_LU_decomp(A, p, &s);
268 gsl_linalg_LU_invert(A, p, &inverse);
270 gsl_permutation_free(p);
313 unsigned int tda = (
unsigned int)A->tda;
314 for (
unsigned int i = 0; i <
rowNum; i++) {
315 unsigned int k = i * tda;
316 for (
unsigned int j = 0; j <
colNum; j++)
317 A->data[k + j] = (*
this)[i][j];
320 gsl_permutation *p = gsl_permutation_alloc(rowNum);
324 gsl_linalg_LU_decomp(A, p, &s);
325 det = gsl_linalg_LU_det(A, s);
327 gsl_permutation_free(p);
334 #ifdef VISP_HAVE_LAPACK 372 integer dim = (integer)
rowNum;
375 integer lwork = dim * dim;
376 integer *ipiv =
new integer[dim + 1];
377 double *work =
new double[lwork];
381 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
388 dgetri_(&dim, A.
data, &dim, &ipiv[1], work, &lwork, &info);
428 integer dim = (integer)
rowNum;
431 integer *ipiv =
new integer[dim + 1];
435 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
441 double det = A[0][0];
442 for (
unsigned int i = 1; i <
rowNum; i++) {
447 for (
int i = 1; i <= dim; i++) {
460 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 500 cv::Mat Minv = M.inv(cv::DECOMP_LU);
503 memcpy(A.
data, Minv.data, (
size_t)(8 * Minv.rows * Minv.cols));
543 det = cv::determinant(M);
549 #if defined(VISP_HAVE_EIGEN3) 589 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
591 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > A_(A.
data, this->getRows(),
631 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
634 return M.determinant();
Implementation of a matrix and operations on matrices.
vpMatrix inverseByLUGsl() const
double detByLULapack() const
error that can be emited by ViSP classes.
Type * data
Address of the first element of the data array.
unsigned int getCols() const
double detByLUOpenCV() const
double detByLUEigen3() const
unsigned int rowNum
Number of rows in the array.
vpMatrix inverseByLUOpenCV() const
unsigned int getRows() const
vpMatrix inverseByLUEigen3() const
double det(vpDetMethod method=LU_DECOMPOSITION) const
unsigned int colNum
Number of columns in the array.
vpMatrix inverseByLU() const
vpMatrix inverseByLULapack() const
double detByLUGsl() const