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 57 typedef MKL_INT integer;
59 # ifdef VISP_HAVE_LAPACK_BUILT_IN 60 typedef long int integer;
64 extern "C" int dgetrf_(integer *m, integer *n,
double *a, integer *lda, integer *ipiv, integer *info);
65 extern "C" void dgetri_(integer *n,
double *a, integer *lda, integer *ipiv,
double *work, integer *lwork,
70 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 71 #include <opencv2/core/core.hpp> 75 #include <visp3/core/vpException.h> 76 #include <visp3/core/vpMatrixException.h> 136 #if defined(VISP_HAVE_LAPACK) 138 #elif defined(VISP_HAVE_EIGEN3) 140 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 142 #elif defined(VISP_HAVE_GSL) 146 "Lapack, OpenCV or GSL 3rd party"));
187 return ((*
this)[0][0] * (*
this)[1][1] - (*
this)[0][1] * (*
this)[1][0]);
189 return ((*
this)[0][0] * ((*
this)[1][1] * (*
this)[2][2] - (*
this)[1][2] * (*
this)[2][1]) -
190 (*
this)[0][1] * ((*
this)[1][0] * (*
this)[2][2] - (*
this)[1][2] * (*
this)[2][0]) +
191 (*
this)[0][2] * ((*
this)[1][0] * (*
this)[2][1] - (*
this)[1][1] * (*
this)[2][0]));
193 #if defined(VISP_HAVE_LAPACK) 195 #elif defined(VISP_HAVE_EIGEN3) 197 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 199 #elif defined(VISP_HAVE_GSL) 203 "Eigen3, OpenCV or GSL 3rd party"));
209 #if defined(VISP_HAVE_GSL) 250 unsigned int tda = (
unsigned int)A->tda;
251 for (
unsigned int i = 0; i <
rowNum; i++) {
252 unsigned int k = i * tda;
253 for (
unsigned int j = 0; j <
colNum; j++)
254 A->data[k + j] = (*
this)[i][j];
262 inverse.tda = inverse.size2;
263 inverse.data = Ainv.
data;
267 gsl_permutation *p = gsl_permutation_alloc(rowNum);
271 gsl_linalg_LU_decomp(A, p, &s);
272 gsl_linalg_LU_invert(A, p, &inverse);
274 gsl_permutation_free(p);
317 unsigned int tda = (
unsigned int)A->tda;
318 for (
unsigned int i = 0; i <
rowNum; i++) {
319 unsigned int k = i * tda;
320 for (
unsigned int j = 0; j <
colNum; j++)
321 A->data[k + j] = (*
this)[i][j];
324 gsl_permutation *p = gsl_permutation_alloc(rowNum);
328 gsl_linalg_LU_decomp(A, p, &s);
329 det = gsl_linalg_LU_det(A, s);
331 gsl_permutation_free(p);
338 #if defined(VISP_HAVE_LAPACK) 376 integer dim = (integer)
rowNum;
379 integer lwork = dim * dim;
380 integer *ipiv =
new integer[dim + 1];
381 double *work =
new double[lwork];
385 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
392 dgetri_(&dim, A.
data, &dim, &ipiv[1], work, &lwork, &info);
432 integer dim = (integer)
rowNum;
435 integer *ipiv =
new integer[dim + 1];
439 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
445 double det = A[0][0];
446 for (
unsigned int i = 1; i <
rowNum; i++) {
451 for (
int i = 1; i <= dim; i++) {
464 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 504 cv::Mat Minv = M.inv(cv::DECOMP_LU);
507 memcpy(A.
data, Minv.data, (
size_t)(8 * Minv.rows * Minv.cols));
547 det = cv::determinant(M);
553 #if defined(VISP_HAVE_EIGEN3) 593 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
595 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > A_(A.
data, this->getRows(),
635 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
638 return M.determinant();
Implementation of a matrix and operations on matrices.
double det(vpDetMethod method=LU_DECOMPOSITION) const
vpMatrix inverseByLUEigen3() const
vpMatrix inverseByLU() const
error that can be emited by ViSP classes.
unsigned int getRows() const
vpMatrix inverseByLUOpenCV() const
Type * data
Address of the first element of the data array.
unsigned int getCols() const
unsigned int rowNum
Number of rows in the array.
double detByLUEigen3() const
double detByLUGsl() const
double detByLUOpenCV() const
unsigned int colNum
Number of columns in the array.
vpMatrix inverseByLULapack() const
double detByLULapack() const
vpMatrix inverseByLUGsl() const