39 #include <visp3/core/vpColVector.h> 40 #include <visp3/core/vpConfig.h> 41 #include <visp3/core/vpDebug.h> 42 #include <visp3/core/vpException.h> 43 #include <visp3/core/vpMath.h> 44 #include <visp3/core/vpMatrix.h> 45 #include <visp3/core/vpMatrixException.h> 51 #ifdef VISP_HAVE_EIGEN3 56 #include <gsl/gsl_linalg.h> 59 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 60 #include <opencv2/core/core.hpp> 63 #ifdef VISP_HAVE_LAPACK 66 typedef MKL_INT integer;
68 # if defined(VISP_HAVE_LAPACK_BUILT_IN) 69 typedef long int integer;
73 extern "C" int dgesdd_(
char *jobz, integer *m, integer *n,
double *a, integer *lda,
double *s,
double *u, integer *ldu,
74 double *vt, integer *ldvt,
double *work, integer *lwork, integer *iwork, integer *info);
86 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 156 int rows = (int)this->
getRows();
157 int cols = (int)this->
getCols();
158 cv::Mat m(rows, cols, CV_64F, this->
data);
159 cv::SVD opencvSVD(m);
160 cv::Mat opencvV = opencvSVD.vt;
161 cv::Mat opencvW = opencvSVD.w;
162 V.
resize((
unsigned int)opencvV.rows, (
unsigned int)opencvV.cols);
163 w.
resize((
unsigned int)(opencvW.rows * opencvW.cols));
165 memcpy(V.
data, opencvV.data, (
size_t)(8 * opencvV.rows * opencvV.cols));
167 memcpy(w.
data, opencvW.data, (
size_t)(8 * opencvW.rows * opencvW.cols));
168 this->
resize((
unsigned int)opencvSVD.u.rows, (
unsigned int)opencvSVD.u.cols);
169 memcpy(this->
data, opencvSVD.u.data, (
size_t)(8 * opencvSVD.u.rows * opencvSVD.u.cols));
174 #if defined(VISP_HAVE_LAPACK) 246 integer m = (integer)(this->
getCols());
247 integer n = (integer)(this->
getRows());
250 integer ldvt = (std::min)(m, n);
256 integer *iwork =
new integer[8 *
static_cast<integer
>((std::min)(n, m))];
259 double *a =
new double[
static_cast<unsigned int>(lda * n)];
262 double *vt = this->
data;
265 dgesdd_((
char *)
"S", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &wkopt, &lwork, iwork, &info);
267 work =
new double[
static_cast<unsigned int>(lwork)];
269 dgesdd_((
char *)
"S", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work, &lwork, iwork, &info);
357 gsl_vector *work = gsl_vector_alloc(nc);
382 gsl_linalg_SV_decomp(&A, &V_, &S, work);
384 gsl_vector_free(work);
388 #ifdef VISP_HAVE_EIGEN3 460 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > M(this->
data, this->
getRows(),
463 Eigen::JacobiSVD<Eigen::MatrixXd>
svd(M, Eigen::ComputeThinU | Eigen::ComputeThinV);
465 Eigen::Map<Eigen::VectorXd> w_(w.
data, w.
size());
466 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > V_(V.
data, V.
getRows(),
468 Eigen::Map<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > U_(this->
data, this->
getRows(),
470 w_ = svd.singularValues();
void svd(vpColVector &w, vpMatrix &V)
Implementation of a matrix and operations on matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
double * data
Address of the first element of the data array.
unsigned int size() const
Return the number of elements of the 2D array.
void svdLapack(vpColVector &w, vpMatrix &V)
unsigned int getCols() const
void svdOpenCV(vpColVector &w, vpMatrix &V)
vpMatrix transpose() const
void svdGsl(vpColVector &w, vpMatrix &V)
void resize(unsigned int i, bool flagNullify=true)
Implementation of column vector and the associated operations.
error that can be emited by the vpMatrix class and its derivates
void svdEigen3(vpColVector &w, vpMatrix &V)