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) 133 return inverseByLULapack();
134 #elif defined(VISP_HAVE_EIGEN3) 135 return inverseByLUEigen3();
136 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 137 return inverseByLUOpenCV();
138 #elif defined(VISP_HAVE_GSL) 139 return inverseByLUGsl();
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) 190 return detByLULapack();
191 #elif defined(VISP_HAVE_EIGEN3) 192 return detByLUEigen3();
193 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) 194 return detByLUOpenCV();
195 #elif defined(VISP_HAVE_GSL) 199 "Eigen3, OpenCV or GSL 3rd party"));
204 #ifndef DOXYGEN_SHOULD_SKIP_THIS 206 #if defined(VISP_HAVE_GSL) 238 vpMatrix vpMatrix::inverseByLUGsl()
const 247 unsigned int tda = (
unsigned int)A->tda;
248 for (
unsigned int i = 0; i <
rowNum; i++) {
249 unsigned int k = i * tda;
250 for (
unsigned int j = 0; j <
colNum; j++)
251 A->data[k + j] = (*
this)[i][j];
259 inverse.tda = inverse.size2;
260 inverse.data = Ainv.
data;
264 gsl_permutation *p = gsl_permutation_alloc(rowNum);
268 gsl_linalg_LU_decomp(A, p, &s);
269 gsl_linalg_LU_invert(A, p, &inverse);
271 gsl_permutation_free(p);
302 double vpMatrix::detByLUGsl()
const 314 unsigned int tda = (
unsigned int)A->tda;
315 for (
unsigned int i = 0; i <
rowNum; i++) {
316 unsigned int k = i * tda;
317 for (
unsigned int j = 0; j <
colNum; j++)
318 A->data[k + j] = (*
this)[i][j];
321 gsl_permutation *p = gsl_permutation_alloc(rowNum);
325 gsl_linalg_LU_decomp(A, p, &s);
326 det = gsl_linalg_LU_det(A, s);
328 gsl_permutation_free(p);
335 #ifdef VISP_HAVE_LAPACK 367 vpMatrix vpMatrix::inverseByLULapack()
const 373 integer dim = (integer)
rowNum;
376 integer lwork = dim * dim;
377 integer *ipiv =
new integer[dim + 1];
378 double *work =
new double[lwork];
382 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
389 dgetri_(&dim, A.
data, &dim, &ipiv[1], work, &lwork, &info);
422 double vpMatrix::detByLULapack()
const 429 integer dim = (integer)
rowNum;
432 integer *ipiv =
new integer[dim + 1];
436 dgetrf_(&dim, &dim, A.
data, &lda, &ipiv[1], &info);
442 double det = A[0][0];
443 for (
unsigned int i = 1; i <
rowNum; i++) {
448 for (
int i = 1; i <= dim; i++) {
461 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 493 vpMatrix vpMatrix::inverseByLUOpenCV()
const 501 cv::Mat Minv = M.inv(cv::DECOMP_LU);
504 memcpy(A.
data, Minv.data, (
size_t)(8 * Minv.rows * Minv.cols));
534 double vpMatrix::detByLUOpenCV()
const 544 det = cv::determinant(M);
550 #if defined(VISP_HAVE_EIGEN3) 583 vpMatrix vpMatrix::inverseByLUEigen3()
const 590 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
592 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > A_(A.
data, this->getRows(),
625 double vpMatrix::detByLUEigen3()
const 632 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
635 return M.determinant();
639 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS Implementation of a matrix and operations on matrices.
double det(vpDetMethod method=LU_DECOMPOSITION) const
vpMatrix inverseByLU() const
error that can be emited by ViSP classes.
unsigned int getRows() 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.
unsigned int colNum
Number of columns in the array.