52 #include <visp3/core/vpCPUFeatures.h>
53 #include <visp3/core/vpColVector.h>
54 #include <visp3/core/vpConfig.h>
55 #include <visp3/core/vpDebug.h>
56 #include <visp3/core/vpException.h>
57 #include <visp3/core/vpMath.h>
58 #include <visp3/core/vpMatrix.h>
59 #include <visp3/core/vpTranslationVector.h>
61 #include <Simd/SimdLib.hpp>
63 #ifdef VISP_HAVE_LAPACK
65 #include <gsl/gsl_eigen.h>
66 #include <gsl/gsl_linalg.h>
67 #include <gsl/gsl_math.h>
68 #elif defined(VISP_HAVE_MKL)
70 typedef MKL_INT integer;
72 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
73 double *work_data,
int lwork_,
int &info_)
75 MKL_INT n =
static_cast<MKL_INT
>(n_);
76 MKL_INT lda =
static_cast<MKL_INT
>(lda_);
77 MKL_INT lwork =
static_cast<MKL_INT
>(lwork_);
78 MKL_INT info =
static_cast<MKL_INT
>(info_);
80 dsyev(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
84 #if defined(VISP_HAVE_LAPACK_BUILT_IN)
85 typedef long int integer;
89 extern "C" integer dsyev_(
char *jobz,
char *uplo, integer *n,
double *a, integer *lda,
double *w,
double *WORK,
90 integer *lwork, integer *info);
92 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
93 double *work_data,
int lwork_,
int &info_)
95 integer n =
static_cast<integer
>(n_);
96 integer lda =
static_cast<integer
>(lda_);
97 integer lwork =
static_cast<integer
>(lwork_);
98 integer info =
static_cast<integer
>(info_);
100 dsyev_(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
102 lwork_ =
static_cast<int>(lwork);
103 info_ =
static_cast<int>(info);
108 #if !defined(VISP_USE_MSVC) || (defined(VISP_USE_MSVC) && !defined(VISP_BUILD_SHARED_LIBS))
109 const unsigned int vpMatrix::m_lapack_min_size_default = 0;
110 unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
117 unsigned int ncols,
double svThreshold,
vpMatrix &Ap,
int &rank_out,
int *rank_in,
120 Ap.
resize(ncols, nrows,
true,
false);
123 double maxsv = sv[0];
127 for (
unsigned int i = 0; i < ncols; i++) {
128 if (sv[i] > maxsv * svThreshold) {
133 unsigned int rank =
static_cast<unsigned int>(rank_out);
135 rank =
static_cast<unsigned int>(*rank_in);
138 for (
unsigned int i = 0; i < ncols; i++) {
139 for (
unsigned int j = 0; j < nrows; j++) {
140 for (
unsigned int k = 0; k < rank; k++) {
141 Ap[i][j] += V[i][k] * U[j][k] / sv[k];
150 for (
unsigned int i = 0; i < nrows; i++) {
151 for (
unsigned int j = 0; j < rank; j++) {
152 (*imA)[i][j] = U[i][j];
159 imAt->
resize(ncols, rank);
160 for (
unsigned int i = 0; i < ncols; i++) {
161 for (
unsigned int j = 0; j < rank; j++) {
162 (*imAt)[i][j] = V[i][j];
169 kerAt->
resize(ncols - rank, ncols);
171 for (
unsigned int k = 0; k < (ncols - rank); k++) {
172 unsigned j = k + rank;
173 for (
unsigned int i = 0; i < V.
getRows(); i++) {
174 (*kerAt)[k][i] = V[i][j];
189 if (((r + nrows) > M.
rowNum) || ((c + ncols) > M.
colNum)) {
191 "Cannot construct a sub matrix (%dx%d) starting at "
192 "position (%d,%d) that is not contained in the "
193 "original matrix (%dx%d)",
197 init(M, r, c, nrows, ncols);
200 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
267 vpMatrix::vpMatrix(
unsigned int nrows,
unsigned int ncols,
const std::initializer_list<double> &list)
345 unsigned int rnrows = r + nrows;
346 unsigned int cncols = c + ncols;
354 resize(nrows, ncols,
false,
false);
358 for (
unsigned int i = 0; i < nrows; i++) {
359 memcpy((*
this)[i], &M[i + r][c], ncols *
sizeof(
double));
406 unsigned int rnrows = r + nrows;
407 unsigned int cncols = c + ncols;
417 M.
resize(nrows, ncols,
false,
false);
418 for (
unsigned int i = 0; i < nrows; i++) {
419 memcpy(M[i], &(*
this)[i + r][c], ncols *
sizeof(
double));
448 for (
unsigned int i = 0; i <
rowNum; i++) {
449 for (
unsigned int j = 0; j <
colNum; j++) {
485 for (
unsigned int i = 0; i <
rowNum; i++) {
486 for (
unsigned int j = 0; j <
colNum; j++) {
487 At[j][i] = (*this)[i][j];
527 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
528 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
533 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
534 const double alpha = 1.0;
535 const double beta = 0.0;
536 const char transa =
't';
537 const char transb =
'n';
539 vpMatrix::blas_dgemm(transa, transb,
rowNum,
rowNum,
colNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
545 for (
unsigned int i = 0; i <
rowNum; i++) {
546 for (
unsigned int j = i; j <
rowNum; j++) {
552 for (
unsigned int k = 0; k <
colNum; k++)
553 ssum += *(pi++) * *(pj++);
580 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
581 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
586 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
587 const double alpha = 1.0;
588 const double beta = 0.0;
589 const char transa =
'n';
590 const char transb =
't';
592 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
597 for (
unsigned int i = 0; i <
colNum; i++) {
599 for (
unsigned int j = 0; j < i; j++) {
602 for (
unsigned int k = 0; k <
rowNum; k++) {
603 s += (*(ptr + i)) * (*(ptr + j));
611 for (
unsigned int k = 0; k <
rowNum; k++) {
612 s += (*(ptr + i)) * (*(ptr + i));
661 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
675 if (
this != &other) {
687 other.rowPtrs = NULL;
719 if (
dsize !=
static_cast<unsigned int>(list.size())) {
720 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
723 std::copy(list.begin(), list.end(),
data);
753 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
754 for (
auto &l : lists) {
755 if (
static_cast<unsigned int>(l.size()) > ncols) {
756 ncols =
static_cast<unsigned int>(l.size());
760 resize(nrows, ncols,
false,
false);
761 auto it = lists.begin();
762 for (
unsigned int i = 0; i <
rowNum; i++, ++it) {
763 std::copy(it->begin(), it->end(),
rowPtrs[i]);
784 for (
unsigned int i = 0; i <
rowNum; i++) {
785 for (
unsigned int j = 0; j <
colNum; j++) {
794 resize(1, 1,
false,
false);
843 unsigned int rows = A.
getRows();
847 for (
unsigned int i = 0; i < rows; i++)
848 (*
this)[i][i] = A[i];
885 for (
unsigned int i = 0; i < min_; i++)
902 unsigned int rows = A.
getRows();
903 DA.
resize(rows, rows,
true);
905 for (
unsigned int i = 0; i < rows; i++)
922 for (
unsigned int j = 0; j < 3; j++)
925 for (
unsigned int j = 0; j < 3; j++) {
927 for (
unsigned int i = 0; i < 3; i++) {
928 t_out[i] +=
rowPtrs[i][j] * tj;
964 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size);
965 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
970 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
976 vpMatrix::blas_dgemv(trans, A.
colNum, A.
rowNum, alpha, A.
data, A.
colNum, v.
data, incr, beta, w.
data, incr);
981 for (
unsigned int j = 0; j < A.
colNum; j++) {
983 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1014 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1015 B.
colNum > vpMatrix::m_lapack_min_size);
1016 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1021 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1022 const double alpha = 1.0;
1023 const double beta = 0.0;
1024 const char trans =
'n';
1025 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1031 const unsigned int BcolNum = B.
colNum;
1032 const unsigned int BrowNum = B.
rowNum;
1033 double **BrowPtrs = B.
rowPtrs;
1034 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1035 const double *rowptri = A.
rowPtrs[i];
1037 for (
unsigned int j = 0; j < BcolNum; j++) {
1039 for (
unsigned int k = 0; k < BrowNum; k++)
1040 s += rowptri[k] * BrowPtrs[k][j];
1064 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1069 const unsigned int BcolNum = B.
colNum;
1070 const unsigned int BrowNum = B.
rowNum;
1071 double **BrowPtrs = B.
rowPtrs;
1072 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1073 const double *rowptri = A.
rowPtrs[i];
1075 for (
unsigned int j = 0; j < BcolNum; j++) {
1077 for (
unsigned int k = 0; k < BrowNum; k++)
1078 s += rowptri[k] * BrowPtrs[k][j];
1101 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1110 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1111 B.
colNum > vpMatrix::m_lapack_min_size);
1112 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1117 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1118 const double alpha = 1.0;
1119 const double beta = 0.0;
1120 const char trans =
'n';
1121 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1127 const unsigned int BcolNum = B.
colNum;
1128 const unsigned int BrowNum = B.
rowNum;
1129 double **BrowPtrs = B.
rowPtrs;
1130 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1131 const double *rowptri = A.
rowPtrs[i];
1133 for (
unsigned int j = 0; j < BcolNum; j++) {
1135 for (
unsigned int k = 0; k < BrowNum; k++)
1136 s += rowptri[k] * BrowPtrs[k][j];
1186 unsigned int RcolNum = R.
getCols();
1187 unsigned int RrowNum = R.
getRows();
1188 for (
unsigned int i = 0; i <
rowNum; i++) {
1191 for (
unsigned int j = 0; j < RcolNum; j++) {
1193 for (
unsigned int k = 0; k < RrowNum; k++)
1194 s += rowptri[k] * R[k][j];
1215 const unsigned int McolNum = M.
getCols();
1216 const unsigned int MrowNum = M.
getRows();
1217 for (
unsigned int i = 0; i <
rowNum; i++) {
1218 const double *rowptri =
rowPtrs[i];
1220 for (
unsigned int j = 0; j < McolNum; j++) {
1222 for (
unsigned int k = 0; k < MrowNum; k++)
1223 s += rowptri[k] * M[k][j];
1249 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1250 V.
colNum > vpMatrix::m_lapack_min_size);
1251 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1256 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1257 const double alpha = 1.0;
1258 const double beta = 0.0;
1259 const char trans =
'n';
1260 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
1289 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1290 V.
getCols() > vpMatrix::m_lapack_min_size);
1291 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1296 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1297 const double alpha = 1.0;
1298 const double beta = 0.0;
1299 const char trans =
'n';
1300 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
1332 double **ArowPtrs = A.
rowPtrs;
1333 double **BrowPtrs = B.
rowPtrs;
1334 double **CrowPtrs = C.
rowPtrs;
1336 for (
unsigned int i = 0; i < A.
rowNum; i++)
1337 for (
unsigned int j = 0; j < A.
colNum; j++)
1338 CrowPtrs[i][j] = wB * BrowPtrs[i][j] + wA * ArowPtrs[i][j];
1360 double **ArowPtrs = A.
rowPtrs;
1361 double **BrowPtrs = B.
rowPtrs;
1362 double **CrowPtrs = C.
rowPtrs;
1364 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1365 for (
unsigned int j = 0; j < A.
colNum; j++) {
1366 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1393 double **ArowPtrs = A.
rowPtrs;
1394 double **BrowPtrs = B.
rowPtrs;
1395 double **CrowPtrs = C.
rowPtrs;
1397 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1398 for (
unsigned int j = 0; j < A.
colNum; j++) {
1399 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1440 double **ArowPtrs = A.
rowPtrs;
1441 double **BrowPtrs = B.
rowPtrs;
1442 double **CrowPtrs = C.
rowPtrs;
1444 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1445 for (
unsigned int j = 0; j < A.
colNum; j++) {
1446 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1473 double **ArowPtrs = A.
rowPtrs;
1474 double **BrowPtrs = B.
rowPtrs;
1475 double **CrowPtrs = C.
rowPtrs;
1477 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1478 for (
unsigned int j = 0; j < A.
colNum; j++) {
1479 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1504 double **BrowPtrs = B.
rowPtrs;
1506 for (
unsigned int i = 0; i <
rowNum; i++)
1507 for (
unsigned int j = 0; j <
colNum; j++)
1508 rowPtrs[i][j] += BrowPtrs[i][j];
1521 double **BrowPtrs = B.
rowPtrs;
1522 for (
unsigned int i = 0; i <
rowNum; i++)
1523 for (
unsigned int j = 0; j <
colNum; j++)
1524 rowPtrs[i][j] -= BrowPtrs[i][j];
1543 double **ArowPtrs = A.
rowPtrs;
1544 double **CrowPtrs = C.
rowPtrs;
1546 for (
unsigned int i = 0; i < A.
rowNum; i++)
1547 for (
unsigned int j = 0; j < A.
colNum; j++)
1548 CrowPtrs[i][j] = -ArowPtrs[i][j];
1565 for (
unsigned int i = 0; i <
rowNum; i++) {
1566 for (
unsigned int j = 0; j <
colNum; j++) {
1588 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1592 unsigned int Brow = B.
getRows();
1593 unsigned int Bcol = B.
getCols();
1596 C.
resize(Brow, Bcol,
false,
false);
1598 for (
unsigned int i = 0; i < Brow; i++)
1599 for (
unsigned int j = 0; j < Bcol; j++)
1600 C[i][j] = B[i][j] * x;
1611 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1618 for (
unsigned int i = 0; i <
rowNum; i++)
1619 for (
unsigned int j = 0; j <
colNum; j++)
1628 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1632 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
1639 double xinv = 1 / x;
1641 for (
unsigned int i = 0; i <
rowNum; i++)
1642 for (
unsigned int j = 0; j <
colNum; j++)
1643 C[i][j] =
rowPtrs[i][j] * xinv;
1651 for (
unsigned int i = 0; i <
rowNum; i++)
1652 for (
unsigned int j = 0; j <
colNum; j++)
1661 for (
unsigned int i = 0; i <
rowNum; i++)
1662 for (
unsigned int j = 0; j <
colNum; j++)
1674 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1678 for (
unsigned int i = 0; i <
rowNum; i++)
1679 for (
unsigned int j = 0; j <
colNum; j++)
1688 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1692 if (std::fabs(x) < std::numeric_limits<double>::epsilon())
1695 double xinv = 1 / x;
1697 for (
unsigned int i = 0; i <
rowNum; i++)
1698 for (
unsigned int j = 0; j <
colNum; j++)
1717 double *optr = out.
data;
1718 for (
unsigned int j = 0; j <
colNum; j++) {
1719 for (
unsigned int i = 0; i <
rowNum; i++) {
1786 unsigned int r1 = m1.
getRows();
1787 unsigned int c1 = m1.
getCols();
1788 unsigned int r2 = m2.
getRows();
1789 unsigned int c2 = m2.
getCols();
1791 out.
resize(r1 * r2, c1 * c2,
false,
false);
1793 for (
unsigned int r = 0; r < r1; r++) {
1794 for (
unsigned int c = 0; c < c1; c++) {
1795 double alpha = m1[r][c];
1796 double *m2ptr = m2[0];
1797 unsigned int roffset = r * r2;
1798 unsigned int coffset = c * c2;
1799 for (
unsigned int rr = 0; rr < r2; rr++) {
1800 for (
unsigned int cc = 0; cc < c2; cc++) {
1801 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
1824 unsigned int r1 = m1.
getRows();
1825 unsigned int c1 = m1.
getCols();
1826 unsigned int r2 = m2.
getRows();
1827 unsigned int c2 = m2.
getCols();
1830 out.
resize(r1 * r2, c1 * c2,
false,
false);
1832 for (
unsigned int r = 0; r < r1; r++) {
1833 for (
unsigned int c = 0; c < c1; c++) {
1834 double alpha = m1[r][c];
1835 double *m2ptr = m2[0];
1836 unsigned int roffset = r * r2;
1837 unsigned int coffset = c * c2;
1838 for (
unsigned int rr = 0; rr < r2; rr++) {
1839 for (
unsigned int cc = 0; cc < c2; cc++) {
1840 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
2029 #if defined(VISP_HAVE_LAPACK)
2031 #elif defined(VISP_HAVE_EIGEN3)
2033 #elif defined(VISP_HAVE_OPENCV)
2098 #if defined(VISP_HAVE_LAPACK)
2100 #elif defined(VISP_HAVE_EIGEN3)
2102 #elif defined(VISP_HAVE_OPENCV)
2108 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2174 #if defined(VISP_HAVE_LAPACK)
2176 #elif defined(VISP_HAVE_EIGEN3)
2178 #elif defined(VISP_HAVE_OPENCV)
2184 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2240 #if defined(VISP_HAVE_LAPACK)
2242 #elif defined(VISP_HAVE_EIGEN3)
2244 #elif defined(VISP_HAVE_OPENCV)
2249 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2305 #if defined(VISP_HAVE_LAPACK)
2307 #elif defined(VISP_HAVE_EIGEN3)
2309 #elif defined(VISP_HAVE_OPENCV)
2314 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2318 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2319 #if defined(VISP_HAVE_LAPACK)
2358 unsigned int nrows =
getRows();
2359 unsigned int ncols =
getCols();
2365 Ap.
resize(ncols, nrows,
false,
false);
2367 if (nrows < ncols) {
2368 U.
resize(ncols, ncols,
true);
2372 U.
resize(nrows, ncols,
false);
2379 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2426 unsigned int nrows =
getRows();
2427 unsigned int ncols =
getCols();
2433 Ap.
resize(ncols, nrows,
false,
false);
2435 if (nrows < ncols) {
2436 U.
resize(ncols, ncols,
true);
2440 U.
resize(nrows, ncols,
false);
2447 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2449 return static_cast<unsigned int>(rank_out);
2500 unsigned int nrows =
getRows();
2501 unsigned int ncols =
getCols();
2507 Ap.
resize(ncols, nrows,
false,
false);
2509 if (nrows < ncols) {
2510 U.
resize(ncols, ncols,
true);
2514 U.
resize(nrows, ncols,
false);
2521 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2527 return static_cast<unsigned int>(rank_out);
2639 unsigned int nrows =
getRows();
2640 unsigned int ncols =
getCols();
2645 if (nrows < ncols) {
2646 U.
resize(ncols, ncols,
true);
2650 U.
resize(nrows, ncols,
false);
2657 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
2663 return static_cast<unsigned int>(rank_out);
2704 unsigned int nrows =
getRows();
2705 unsigned int ncols =
getCols();
2707 double svThreshold = 1e-26;
2712 Ap.
resize(ncols, nrows,
false,
false);
2714 if (nrows < ncols) {
2715 U.
resize(ncols, ncols,
true);
2719 U.
resize(nrows, ncols,
false);
2726 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2779 unsigned int nrows =
getRows();
2780 unsigned int ncols =
getCols();
2782 double svThreshold = 1e-26;
2787 Ap.
resize(ncols, nrows,
false,
false);
2789 if (nrows < ncols) {
2790 U.
resize(ncols, ncols,
true);
2794 U.
resize(nrows, ncols,
false);
2801 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2861 unsigned int nrows =
getRows();
2862 unsigned int ncols =
getCols();
2864 double svThreshold = 1e-26;
2869 Ap.
resize(ncols, nrows,
false,
false);
2871 if (nrows < ncols) {
2872 U.
resize(ncols, ncols,
true);
2876 U.
resize(nrows, ncols,
false);
2883 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3006 unsigned int nrows =
getRows();
3007 unsigned int ncols =
getCols();
3009 double svThreshold = 1e-26;
3013 if (nrows < ncols) {
3014 U.
resize(ncols, ncols,
true);
3018 U.
resize(nrows, ncols,
false);
3025 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3035 #if defined(VISP_HAVE_EIGEN3)
3074 unsigned int nrows =
getRows();
3075 unsigned int ncols =
getCols();
3081 Ap.
resize(ncols, nrows,
false,
false);
3083 if (nrows < ncols) {
3084 U.
resize(ncols, ncols,
true);
3088 U.
resize(nrows, ncols,
false);
3095 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3142 unsigned int nrows =
getRows();
3143 unsigned int ncols =
getCols();
3149 Ap.
resize(ncols, nrows,
false,
false);
3151 if (nrows < ncols) {
3152 U.
resize(ncols, ncols,
true);
3156 U.
resize(nrows, ncols,
false);
3163 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3165 return static_cast<unsigned int>(rank_out);
3216 unsigned int nrows =
getRows();
3217 unsigned int ncols =
getCols();
3223 Ap.
resize(ncols, nrows,
false,
false);
3225 if (nrows < ncols) {
3226 U.
resize(ncols, ncols,
true);
3230 U.
resize(nrows, ncols,
false);
3237 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3243 return static_cast<unsigned int>(rank_out);
3355 unsigned int nrows =
getRows();
3356 unsigned int ncols =
getCols();
3361 if (nrows < ncols) {
3362 U.
resize(ncols, ncols,
true);
3366 U.
resize(nrows, ncols,
false);
3373 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
3379 return static_cast<unsigned int>(rank_out);
3420 unsigned int nrows =
getRows();
3421 unsigned int ncols =
getCols();
3423 double svThreshold = 1e-26;
3428 Ap.
resize(ncols, nrows,
false,
false);
3430 if (nrows < ncols) {
3431 U.
resize(ncols, ncols,
true);
3435 U.
resize(nrows, ncols,
false);
3442 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3495 unsigned int nrows =
getRows();
3496 unsigned int ncols =
getCols();
3498 double svThreshold = 1e-26;
3503 Ap.
resize(ncols, nrows,
false,
false);
3505 if (nrows < ncols) {
3506 U.
resize(ncols, ncols,
true);
3510 U.
resize(nrows, ncols,
false);
3517 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3577 unsigned int nrows =
getRows();
3578 unsigned int ncols =
getCols();
3580 double svThreshold = 1e-26;
3585 Ap.
resize(ncols, nrows,
false,
false);
3587 if (nrows < ncols) {
3588 U.
resize(ncols, ncols,
true);
3592 U.
resize(nrows, ncols,
false);
3599 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3722 unsigned int nrows =
getRows();
3723 unsigned int ncols =
getCols();
3725 double svThreshold = 1e-26;
3729 if (nrows < ncols) {
3730 U.
resize(ncols, ncols,
true);
3734 U.
resize(nrows, ncols,
false);
3741 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3751 #if defined(VISP_HAVE_OPENCV)
3790 unsigned int nrows =
getRows();
3791 unsigned int ncols =
getCols();
3797 Ap.
resize(ncols, nrows,
false,
false);
3799 if (nrows < ncols) {
3800 U.
resize(ncols, ncols,
true);
3804 U.
resize(nrows, ncols,
false);
3811 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3858 unsigned int nrows =
getRows();
3859 unsigned int ncols =
getCols();
3865 Ap.
resize(ncols, nrows,
false,
false);
3867 if (nrows < ncols) {
3868 U.
resize(ncols, ncols,
true);
3872 U.
resize(nrows, ncols,
false);
3879 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3881 return static_cast<unsigned int>(rank_out);
3932 unsigned int nrows =
getRows();
3933 unsigned int ncols =
getCols();
3939 Ap.
resize(ncols, nrows,
false,
false);
3941 if (nrows < ncols) {
3942 U.
resize(ncols, ncols,
true);
3946 U.
resize(nrows, ncols,
false);
3953 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3959 return static_cast<unsigned int>(rank_out);
4071 unsigned int nrows =
getRows();
4072 unsigned int ncols =
getCols();
4077 if (nrows < ncols) {
4078 U.
resize(ncols, ncols,
true);
4082 U.
resize(nrows, ncols,
false);
4089 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
4095 return static_cast<unsigned int>(rank_out);
4136 unsigned int nrows =
getRows();
4137 unsigned int ncols =
getCols();
4139 double svThreshold = 1e-26;
4144 Ap.
resize(ncols, nrows,
false,
false);
4146 if (nrows < ncols) {
4147 U.
resize(ncols, ncols,
true);
4151 U.
resize(nrows, ncols,
false);
4158 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4211 unsigned int nrows =
getRows();
4212 unsigned int ncols =
getCols();
4214 double svThreshold = 1e-26;
4219 Ap.
resize(ncols, nrows,
false,
false);
4221 if (nrows < ncols) {
4222 U.
resize(ncols, ncols,
true);
4226 U.
resize(nrows, ncols,
false);
4233 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4293 unsigned int nrows =
getRows();
4294 unsigned int ncols =
getCols();
4296 double svThreshold = 1e-26;
4301 Ap.
resize(ncols, nrows,
false,
false);
4303 if (nrows < ncols) {
4304 U.
resize(ncols, ncols,
true);
4308 U.
resize(nrows, ncols,
false);
4315 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4438 unsigned int nrows =
getRows();
4439 unsigned int ncols =
getCols();
4441 double svThreshold = 1e-26;
4445 if (nrows < ncols) {
4446 U.
resize(ncols, ncols,
true);
4450 U.
resize(nrows, ncols,
false);
4457 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
4532 #if defined(VISP_HAVE_LAPACK)
4534 #elif defined(VISP_HAVE_EIGEN3)
4536 #elif defined(VISP_HAVE_OPENCV)
4543 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4615 #if defined(VISP_HAVE_LAPACK)
4617 #elif defined(VISP_HAVE_EIGEN3)
4619 #elif defined(VISP_HAVE_OPENCV)
4626 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4707 return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt);
4931 #if defined(VISP_HAVE_LAPACK)
4933 #elif defined(VISP_HAVE_EIGEN3)
4935 #elif defined(VISP_HAVE_OPENCV)
4945 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5091 #if defined(VISP_HAVE_LAPACK)
5093 #elif defined(VISP_HAVE_EIGEN3)
5095 #elif defined(VISP_HAVE_OPENCV)
5105 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5156 for (
unsigned int i = 0; i < column_size; i++)
5157 c[i] = (*
this)[i_begin + i][j];
5284 if (r.
data != NULL &&
data != NULL) {
5285 memcpy(r.
data, (*
this)[i] + j_begin, row_size *
sizeof(
double));
5332 diag.resize(min_size,
false);
5334 for (
unsigned int i = 0; i < min_size; i++) {
5335 diag[i] = (*this)[i][i];
5374 unsigned int nra = A.
getRows();
5375 unsigned int nrb = B.
getRows();
5385 std::cerr <<
"A and C must be two different objects!" << std::endl;
5390 std::cerr <<
"B and C must be two different objects!" << std::endl;
5396 if (C.
data != NULL && A.
data != NULL && A.
size() > 0) {
5401 if (C.
data != NULL && B.
data != NULL && B.
size() > 0) {
5438 std::cerr <<
"A and C must be two different objects!" << std::endl;
5477 std::cerr <<
"A and C must be two different objects!" << std::endl;
5562 unsigned int nca = A.
getCols();
5563 unsigned int ncb = B.
getCols();
5572 if (B.
getRows() == 0 || nca + ncb == 0) {
5573 std::cerr <<
"B.getRows() == 0 || nca+ncb == 0" << std::endl;
5608 typedef std::string::size_type size_type;
5613 std::vector<std::string> values(m * n);
5614 std::ostringstream oss;
5615 std::ostringstream ossFixed;
5616 std::ios_base::fmtflags original_flags = oss.flags();
5618 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
5620 size_type maxBefore = 0;
5621 size_type maxAfter = 0;
5623 for (
unsigned int i = 0; i < m; ++i) {
5624 for (
unsigned int j = 0; j < n; ++j) {
5626 oss << (*this)[i][j];
5627 if (oss.str().find(
"e") != std::string::npos) {
5629 ossFixed << (*this)[i][j];
5630 oss.str(ossFixed.str());
5633 values[i * n + j] = oss.str();
5634 size_type thislen = values[i * n + j].size();
5635 size_type p = values[i * n + j].find(
'.');
5637 if (p == std::string::npos) {
5648 size_type totalLength = length;
5652 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
5656 s <<
"[" << m <<
"," << n <<
"]=\n";
5658 for (
unsigned int i = 0; i < m; i++) {
5660 for (
unsigned int j = 0; j < n; j++) {
5661 size_type p = values[i * n + j].find(
'.');
5662 s.setf(std::ios::right, std::ios::adjustfield);
5663 s.width((std::streamsize)maxBefore);
5664 s << values[i * n + j].substr(0, p).c_str();
5667 s.setf(std::ios::left, std::ios::adjustfield);
5668 if (p != std::string::npos) {
5669 s.width((std::streamsize)maxAfter);
5670 s << values[i * n + j].substr(p, maxAfter).c_str();
5673 s.width((std::streamsize)maxAfter);
5683 s.flags(original_flags);
5685 return (
int)(maxBefore + maxAfter);
5727 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5728 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5729 os << (*this)[i][j] <<
", ";
5731 if (this->
getRows() != i + 1) {
5732 os <<
";" << std::endl;
5735 os <<
"]" << std::endl;
5771 os <<
"([ " << std::endl;
5772 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5774 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5775 os << (*this)[i][j] <<
", ";
5777 os <<
"]," << std::endl;
5779 os <<
"])" << std::endl;
5812 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5813 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5814 os << (*this)[i][j];
5815 if (!(j == (this->
getCols() - 1)))
5861 os <<
"vpMatrix " << matrixName <<
" (" << this->
getRows() <<
", " << this->
getCols() <<
"); " << std::endl;
5863 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5864 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5866 os << matrixName <<
"[" << i <<
"][" << j <<
"] = " << (*this)[i][j] <<
"; " << std::endl;
5869 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
5870 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"][" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
5871 << (
unsigned int)((
unsigned char *)&((*this)[i][j]))[k] <<
"; " << std::endl;
5895 unsigned int rowNumOld =
rowNum;
5927 if (r.
size() == 0) {
5931 unsigned int oldSize =
size();
5936 memcpy(
data + oldSize, r.
data,
sizeof(
double) * r.
size());
5968 if (c.
size() == 0) {
5973 unsigned int oldColNum =
colNum;
5978 for (
unsigned int i = 0; i <
rowNum; i++) {
5979 memcpy(
data + i *
colNum, tmp.
data + i * oldColNum,
sizeof(
double) * oldColNum);
6003 for (
unsigned int i = r; i < (r + A.
getRows()); i++) {
6061 for (
unsigned int i = 0; i <
rowNum; i++) {
6062 for (
unsigned int j = 0; j <
rowNum; j++) {
6064 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6070 #if defined(VISP_HAVE_LAPACK)
6071 #if defined(VISP_HAVE_GSL)
6073 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6076 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6079 unsigned int Atda = (
unsigned int)m->tda;
6080 for (
unsigned int i = 0; i <
rowNum; i++) {
6081 unsigned int k = i * Atda;
6082 for (
unsigned int j = 0; j <
colNum; j++)
6083 m->data[k + j] = (*
this)[i][j];
6085 gsl_eigen_symmv(m, eval, evec, w);
6087 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6089 for (
unsigned int i = 0; i <
rowNum; i++) {
6090 evalue[i] = gsl_vector_get(eval, i);
6093 gsl_eigen_symmv_free(w);
6094 gsl_vector_free(eval);
6096 gsl_matrix_free(evec);
6100 const char jobz =
'N';
6101 const char uplo =
'U';
6108 lwork =
static_cast<int>(wkopt);
6116 "You should install Lapack 3rd party"));
6180 for (
unsigned int i = 0; i <
rowNum; i++) {
6181 for (
unsigned int j = 0; j <
rowNum; j++) {
6183 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6193 #if defined(VISP_HAVE_LAPACK)
6194 #if defined(VISP_HAVE_GSL)
6196 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6199 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6202 unsigned int Atda = (
unsigned int)m->tda;
6203 for (
unsigned int i = 0; i <
rowNum; i++) {
6204 unsigned int k = i * Atda;
6205 for (
unsigned int j = 0; j <
colNum; j++)
6206 m->data[k + j] = (*
this)[i][j];
6208 gsl_eigen_symmv(m, eval, evec, w);
6210 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6212 for (
unsigned int i = 0; i <
rowNum; i++) {
6213 evalue[i] = gsl_vector_get(eval, i);
6215 Atda = (
unsigned int)evec->tda;
6216 for (
unsigned int i = 0; i <
rowNum; i++) {
6217 unsigned int k = i * Atda;
6218 for (
unsigned int j = 0; j <
rowNum; j++) {
6219 evector[i][j] = evec->
data[k + j];
6223 gsl_eigen_symmv_free(w);
6224 gsl_vector_free(eval);
6226 gsl_matrix_free(evec);
6230 const char jobz =
'V';
6231 const char uplo =
'U';
6238 lwork =
static_cast<int>(wkopt);
6247 "You should install Lapack 3rd party"));
6272 unsigned int nbline =
getRows();
6273 unsigned int nbcol =
getCols();
6278 V.
resize(nbcol, nbcol,
false);
6285 U.
resize(nbcol, nbcol,
true);
6287 U.
resize(nbline, nbcol,
false);
6295 for (
unsigned int i = 0; i < nbcol; i++) {
6296 if (sv[i] > maxsv) {
6301 unsigned int rank = 0;
6302 for (
unsigned int i = 0; i < nbcol; i++) {
6303 if (sv[i] > maxsv * svThreshold) {
6308 kerAt.
resize(nbcol - rank, nbcol);
6309 if (rank != nbcol) {
6310 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6312 if ((sv[j] <= maxsv * svThreshold) &&
6313 (std::fabs(V.
getCol(j).
sumSquare()) > std::numeric_limits<double>::epsilon())) {
6314 for (
unsigned int i = 0; i < V.
getRows(); i++) {
6315 kerAt[k][i] = V[i][j];
6343 unsigned int nbrow =
getRows();
6344 unsigned int nbcol =
getCols();
6349 V.
resize(nbcol, nbcol,
false);
6356 U.
resize(nbcol, nbcol,
true);
6358 U.
resize(nbrow, nbcol,
false);
6365 double maxsv = sv[0];
6367 unsigned int rank = 0;
6368 for (
unsigned int i = 0; i < nbcol; i++) {
6369 if (sv[i] > maxsv * svThreshold) {
6374 kerA.
resize(nbcol, nbcol - rank);
6375 if (rank != nbcol) {
6376 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6378 if (sv[j] <= maxsv * svThreshold) {
6379 for (
unsigned int i = 0; i < nbcol; i++) {
6380 kerA[i][k] = V[i][j];
6387 return (nbcol - rank);
6408 unsigned int nbrow =
getRows();
6409 unsigned int nbcol =
getCols();
6410 unsigned int dim_ =
static_cast<unsigned int>(dim);
6415 V.
resize(nbcol, nbcol,
false);
6422 U.
resize(nbcol, nbcol,
true);
6424 U.
resize(nbrow, nbcol,
false);
6430 kerA.
resize(nbcol, dim_);
6432 unsigned int rank = nbcol - dim_;
6433 for (
unsigned int k = 0; k < dim_; k++) {
6434 unsigned int j = k + rank;
6435 for (
unsigned int i = 0; i < nbcol; i++) {
6436 kerA[i][k] = V[i][j];
6441 double maxsv = sv[0];
6442 unsigned int rank = 0;
6443 for (
unsigned int i = 0; i < nbcol; i++) {
6444 if (sv[i] > maxsv * 1e-6) {
6448 return (nbcol - rank);
6507 #ifdef VISP_HAVE_GSL
6509 double *b =
new double[size_];
6510 for (
size_t i = 0; i < size_; i++)
6512 gsl_matrix_view m = gsl_matrix_view_array(this->
data,
rowNum, colNum);
6513 gsl_matrix_view em = gsl_matrix_view_array(b,
rowNum,
colNum);
6514 gsl_linalg_exponential_ss(&m.matrix, &em.matrix, 0);
6518 memcpy(expA.
data, b, size_ *
sizeof(
double));
6539 for (
unsigned int i = 0; i <
rowNum; i++) {
6541 for (
unsigned int j = 0; j <
colNum; j++) {
6542 sum += fabs((*
this)[i][j]);
6544 if (
sum > nA || i == 0) {
6553 double sca = 1.0 / pow(2.0, s);
6556 _expE = c * exp + _eye;
6557 _expD = -c * exp + _eye;
6558 for (
int k = 2; k <= q; k++) {
6559 c = c * ((double)(q - k + 1)) / ((
double)(k * (2 * q - k + 1)));
6560 _expcX = exp * _expX;
6563 _expE = _expE + _expcX;
6565 _expD = _expD + _expcX;
6567 _expD = _expD - _expcX;
6571 exp = _expX * _expE;
6572 for (
int k = 1; k <= s; k++) {
6605 for (
unsigned int i = 0; i < col; i++) {
6606 for (
unsigned int j = 0; j < row; j++)
6607 M_comp[i][j] = M[i][j];
6608 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6609 M_comp[i][j - 1] = M[i][j];
6611 for (
unsigned int i = col + 1; i < M.
getCols(); i++) {
6612 for (
unsigned int j = 0; j < row; j++)
6613 M_comp[i - 1][j] = M[i][j];
6614 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6615 M_comp[i - 1][j - 1] = M[i][j];
6631 unsigned int nbline =
getRows();
6632 unsigned int nbcol =
getCols();
6637 V.
resize(nbcol, nbcol,
false);
6644 U.
resize(nbcol, nbcol,
true);
6646 U.
resize(nbline, nbcol,
false);
6654 for (
unsigned int i = 0; i < nbcol; i++) {
6655 if (sv[i] > maxsv) {
6661 unsigned int rank = 0;
6662 for (
unsigned int i = 0; i < nbcol; i++) {
6663 if (sv[i] > maxsv * svThreshold) {
6669 double minsv = maxsv;
6670 for (
unsigned int i = 0; i < rank; i++) {
6671 if (sv[i] < minsv) {
6676 if (std::fabs(minsv) > std::numeric_limits<double>::epsilon()) {
6677 return maxsv / minsv;
6680 return std::numeric_limits<double>::infinity();
6698 for (
unsigned int i = 0; i < H.
getCols(); i++) {
6699 HLM[i][i] += alpha * H[i][i];
6713 for (
unsigned int i = 0; i <
dsize; i++) {
6714 double x = *(
data + i);
6731 if (this->
dsize != 0) {
6740 unsigned int maxRank = std::min(this->
getCols(), this->
getRows());
6743 unsigned int boundary = std::min(maxRank, w.
size());
6748 for (
unsigned int i = 0; i < boundary; i++) {
6773 for (
unsigned int i = 0; i <
rowNum; i++) {
6775 for (
unsigned int j = 0; j <
colNum; j++) {
6776 x += fabs(*(*(
rowPtrs + i) + j));
6793 double sum_square = 0.0;
6796 for (
unsigned int i = 0; i <
rowNum; i++) {
6797 for (
unsigned int j = 0; j <
colNum; j++) {
6799 sum_square += x * x;
6805 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
6853 for (
unsigned int j = 0; j <
getCols(); j++)
6854 c[j] = (*
this)[i - 1][j];
6879 for (
unsigned int i = 0; i <
getRows(); i++)
6880 c[i] = (*
this)[i][j - 1];
6892 for (
unsigned int i = 0; i <
rowNum; i++)
6893 for (
unsigned int j = 0; j <
colNum; j++)
6895 (*this)[i][j] = val;
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
double * data
Address of the first element of the data array.
double ** rowPtrs
Address of the first element of each rows.
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int rowNum
Number of rows in the array.
unsigned int dsize
Current array size (rowNum * colNum)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
unsigned int colNum
Number of columns in the array.
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
@ functionNotImplementedError
Function not implemented.
@ dimensionError
Bad dimension.
@ divideByZeroError
Division by zero.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static Type maximum(const Type &a, const Type &b)
Implementation of a matrix and operations on matrices.
void svdLapack(vpColVector &w, vpMatrix &V)
vpColVector eigenValues() const
vpMatrix pseudoInverseOpenCV(double svThreshold=1e-6) const
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpMatrix & operator<<(double *)
double cond(double svThreshold=1e-6) const
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
vpMatrix hadamard(const vpMatrix &m) const
vpMatrix operator-() const
vp_deprecated void setIdentity(const double &val=1.0)
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
std::ostream & maplePrint(std::ostream &os) const
unsigned int kernel(vpMatrix &kerAt, double svThreshold=1e-6) const
vpMatrix inverseByLU() const
vpMatrix operator*(const vpMatrix &B) const
vpMatrix operator/(double x) const
Cij = Aij / x (A is unchanged)
void stack(const vpMatrix &A)
vp_deprecated void stackMatrices(const vpMatrix &A)
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
vpMatrix & operator*=(double x)
Multiply all the element of the matrix by x : Aij = Aij * x.
vpMatrix operator*(const double &x, const vpMatrix &B)
static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B)
vp_deprecated double euclideanNorm() const
vpColVector stackColumns()
vp_deprecated vpColVector column(unsigned int j)
static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
void svd(vpColVector &w, vpMatrix &V)
vpMatrix operator+(const vpMatrix &B) const
void diag(const double &val=1.0)
vpRowVector getRow(unsigned int i) const
void svdOpenCV(vpColVector &w, vpMatrix &V)
vpMatrix & operator+=(const vpMatrix &B)
Operation A = A + B.
static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, vpMatrix &C)
double inducedL2Norm() const
double infinityNorm() const
vpMatrix & operator=(const vpArray2D< double > &A)
double frobeniusNorm() const
vpColVector getDiag() const
static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA)
void solveBySVD(const vpColVector &B, vpColVector &x) const
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
vpMatrix pseudoInverseLapack(double svThreshold=1e-6) const
vpMatrix pseudoInverse(double svThreshold=1e-6) const
vpMatrix & operator,(double val)
static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w)
vp_deprecated vpRowVector row(unsigned int i)
vpColVector getCol(unsigned int j) const
double det(vpDetMethod method=LU_DECOMPOSITION) const
vp_deprecated void init()
static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
void svdEigen3(vpColVector &w, vpMatrix &V)
void kron(const vpMatrix &m1, vpMatrix &out) const
vpMatrix transpose() const
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
static void negateMatrix(const vpMatrix &A, vpMatrix &C)
std::ostream & csvPrint(std::ostream &os) const
unsigned int nullSpace(vpMatrix &kerA, double svThreshold=1e-6) const
std::ostream & matlabPrint(std::ostream &os) const
vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
Class that consider the case of a translation vector.