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)
346 unsigned int rnrows = r + nrows;
347 unsigned int cncols = c + ncols;
355 resize(nrows, ncols,
false,
false);
359 for (
unsigned int i = 0; i < nrows; i++) {
360 memcpy((*
this)[i], &M[i + r][c], ncols *
sizeof(
double));
407 unsigned int rnrows = r + nrows;
408 unsigned int cncols = c + ncols;
418 M.
resize(nrows, ncols,
false,
false);
419 for (
unsigned int i = 0; i < nrows; i++) {
420 memcpy(M[i], &(*
this)[i + r][c], ncols *
sizeof(
double));
449 for (
unsigned int i = 0; i <
rowNum; i++) {
450 for (
unsigned int j = 0; j <
colNum; j++) {
486 for (
unsigned int i = 0; i <
rowNum; i++) {
487 for (
unsigned int j = 0; j <
colNum; j++) {
488 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,
544 for (
unsigned int i = 0; i <
rowNum; i++) {
545 for (
unsigned int j = i; j <
rowNum; j++) {
551 for (
unsigned int k = 0; k <
colNum; k++)
552 ssum += *(pi++) * *(pj++);
579 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
580 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
585 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
586 const double alpha = 1.0;
587 const double beta = 0.0;
588 const char transa =
'n';
589 const char transb =
't';
591 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
595 for (
unsigned int i = 0; i <
colNum; i++) {
597 for (
unsigned int j = 0; j < i; j++) {
600 for (
unsigned int k = 0; k <
rowNum; k++) {
601 s += (*(ptr + i)) * (*(ptr + j));
609 for (
unsigned int k = 0; k <
rowNum; k++) {
610 s += (*(ptr + i)) * (*(ptr + i));
659 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
673 if (
this != &other) {
685 other.rowPtrs = NULL;
717 if (
dsize !=
static_cast<unsigned int>(list.size())) {
718 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
721 std::copy(list.begin(), list.end(),
data);
751 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
752 for (
auto &l : lists) {
753 if (
static_cast<unsigned int>(l.size()) > ncols) {
754 ncols =
static_cast<unsigned int>(l.size());
758 resize(nrows, ncols,
false,
false);
759 auto it = lists.begin();
760 for (
unsigned int i = 0; i <
rowNum; i++, ++it) {
761 std::copy(it->begin(), it->end(),
rowPtrs[i]);
782 for (
unsigned int i = 0; i <
rowNum; i++) {
783 for (
unsigned int j = 0; j <
colNum; j++) {
792 resize(1, 1,
false,
false);
841 unsigned int rows = A.
getRows();
845 for (
unsigned int i = 0; i < rows; i++)
846 (*
this)[i][i] = A[i];
883 for (
unsigned int i = 0; i < min_; i++)
900 unsigned int rows = A.
getRows();
901 DA.
resize(rows, rows,
true);
903 for (
unsigned int i = 0; i < rows; i++)
920 for (
unsigned int j = 0; j < 3; j++)
923 for (
unsigned int j = 0; j < 3; j++) {
925 for (
unsigned int i = 0; i < 3; i++) {
926 t_out[i] +=
rowPtrs[i][j] * tj;
962 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size);
963 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
968 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
974 vpMatrix::blas_dgemv(trans, A.
colNum, A.
rowNum, alpha, A.
data, A.
colNum, v.
data, incr, beta, w.
data, incr);
978 for (
unsigned int j = 0; j < A.
colNum; j++) {
980 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1011 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1012 B.
colNum > vpMatrix::m_lapack_min_size);
1013 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1018 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1019 const double alpha = 1.0;
1020 const double beta = 0.0;
1021 const char trans =
'n';
1022 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1027 const unsigned int BcolNum = B.
colNum;
1028 const unsigned int BrowNum = B.
rowNum;
1029 double **BrowPtrs = B.
rowPtrs;
1030 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1031 const double *rowptri = A.
rowPtrs[i];
1033 for (
unsigned int j = 0; j < BcolNum; j++) {
1035 for (
unsigned int k = 0; k < BrowNum; k++)
1036 s += rowptri[k] * BrowPtrs[k][j];
1060 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1065 const unsigned int BcolNum = B.
colNum;
1066 const unsigned int BrowNum = B.
rowNum;
1067 double **BrowPtrs = B.
rowPtrs;
1068 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1069 const double *rowptri = A.
rowPtrs[i];
1071 for (
unsigned int j = 0; j < BcolNum; j++) {
1073 for (
unsigned int k = 0; k < BrowNum; k++)
1074 s += rowptri[k] * BrowPtrs[k][j];
1097 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1106 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1107 B.
colNum > vpMatrix::m_lapack_min_size);
1108 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1113 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1114 const double alpha = 1.0;
1115 const double beta = 0.0;
1116 const char trans =
'n';
1117 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1122 const unsigned int BcolNum = B.
colNum;
1123 const unsigned int BrowNum = B.
rowNum;
1124 double **BrowPtrs = B.
rowPtrs;
1125 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1126 const double *rowptri = A.
rowPtrs[i];
1128 for (
unsigned int j = 0; j < BcolNum; j++) {
1130 for (
unsigned int k = 0; k < BrowNum; k++)
1131 s += rowptri[k] * BrowPtrs[k][j];
1181 unsigned int RcolNum = R.
getCols();
1182 unsigned int RrowNum = R.
getRows();
1183 for (
unsigned int i = 0; i <
rowNum; i++) {
1186 for (
unsigned int j = 0; j < RcolNum; j++) {
1188 for (
unsigned int k = 0; k < RrowNum; k++)
1189 s += rowptri[k] * R[k][j];
1210 const unsigned int McolNum = M.
getCols();
1211 const unsigned int MrowNum = M.
getRows();
1212 for (
unsigned int i = 0; i <
rowNum; i++) {
1213 const double *rowptri =
rowPtrs[i];
1215 for (
unsigned int j = 0; j < McolNum; j++) {
1217 for (
unsigned int k = 0; k < MrowNum; k++)
1218 s += rowptri[k] * M[k][j];
1244 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1245 V.
colNum > vpMatrix::m_lapack_min_size);
1246 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1251 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1252 const double alpha = 1.0;
1253 const double beta = 0.0;
1254 const char trans =
'n';
1255 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
1283 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1284 V.
getCols() > vpMatrix::m_lapack_min_size);
1285 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1290 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1291 const double alpha = 1.0;
1292 const double beta = 0.0;
1293 const char trans =
'n';
1294 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
1325 double **ArowPtrs = A.
rowPtrs;
1326 double **BrowPtrs = B.
rowPtrs;
1327 double **CrowPtrs = C.
rowPtrs;
1329 for (
unsigned int i = 0; i < A.
rowNum; i++)
1330 for (
unsigned int j = 0; j < A.
colNum; j++)
1331 CrowPtrs[i][j] = wB * BrowPtrs[i][j] + wA * ArowPtrs[i][j];
1353 double **ArowPtrs = A.
rowPtrs;
1354 double **BrowPtrs = B.
rowPtrs;
1355 double **CrowPtrs = C.
rowPtrs;
1357 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1358 for (
unsigned int j = 0; j < A.
colNum; j++) {
1359 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1386 double **ArowPtrs = A.
rowPtrs;
1387 double **BrowPtrs = B.
rowPtrs;
1388 double **CrowPtrs = C.
rowPtrs;
1390 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1391 for (
unsigned int j = 0; j < A.
colNum; j++) {
1392 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1433 double **ArowPtrs = A.
rowPtrs;
1434 double **BrowPtrs = B.
rowPtrs;
1435 double **CrowPtrs = C.
rowPtrs;
1437 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1438 for (
unsigned int j = 0; j < A.
colNum; j++) {
1439 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1466 double **ArowPtrs = A.
rowPtrs;
1467 double **BrowPtrs = B.
rowPtrs;
1468 double **CrowPtrs = C.
rowPtrs;
1470 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1471 for (
unsigned int j = 0; j < A.
colNum; j++) {
1472 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1497 double **BrowPtrs = B.
rowPtrs;
1499 for (
unsigned int i = 0; i <
rowNum; i++)
1500 for (
unsigned int j = 0; j <
colNum; j++)
1501 rowPtrs[i][j] += BrowPtrs[i][j];
1514 double **BrowPtrs = B.
rowPtrs;
1515 for (
unsigned int i = 0; i <
rowNum; i++)
1516 for (
unsigned int j = 0; j <
colNum; j++)
1517 rowPtrs[i][j] -= BrowPtrs[i][j];
1536 double **ArowPtrs = A.
rowPtrs;
1537 double **CrowPtrs = C.
rowPtrs;
1540 for (
unsigned int i = 0; i < A.
rowNum; i++)
1541 for (
unsigned int j = 0; j < A.
colNum; j++)
1542 CrowPtrs[i][j] = -ArowPtrs[i][j];
1559 for (
unsigned int i = 0; i <
rowNum; i++) {
1560 for (
unsigned int j = 0; j <
colNum; j++) {
1582 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1586 unsigned int Brow = B.
getRows();
1587 unsigned int Bcol = B.
getCols();
1590 C.
resize(Brow, Bcol,
false,
false);
1592 for (
unsigned int i = 0; i < Brow; i++)
1593 for (
unsigned int j = 0; j < Bcol; j++)
1594 C[i][j] = B[i][j] * x;
1605 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1612 for (
unsigned int i = 0; i <
rowNum; i++)
1613 for (
unsigned int j = 0; j <
colNum; j++)
1622 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1626 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
1633 double xinv = 1 / x;
1635 for (
unsigned int i = 0; i <
rowNum; i++)
1636 for (
unsigned int j = 0; j <
colNum; j++)
1637 C[i][j] =
rowPtrs[i][j] * xinv;
1645 for (
unsigned int i = 0; i <
rowNum; i++)
1646 for (
unsigned int j = 0; j <
colNum; j++)
1655 for (
unsigned int i = 0; i <
rowNum; i++)
1656 for (
unsigned int j = 0; j <
colNum; j++)
1668 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1672 for (
unsigned int i = 0; i <
rowNum; i++)
1673 for (
unsigned int j = 0; j <
colNum; j++)
1682 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1686 if (std::fabs(x) < std::numeric_limits<double>::epsilon())
1689 double xinv = 1 / x;
1691 for (
unsigned int i = 0; i <
rowNum; i++)
1692 for (
unsigned int j = 0; j <
colNum; j++)
1711 double *optr = out.
data;
1712 for (
unsigned int j = 0; j <
colNum; j++) {
1713 for (
unsigned int i = 0; i <
rowNum; i++) {
1780 unsigned int r1 = m1.
getRows();
1781 unsigned int c1 = m1.
getCols();
1782 unsigned int r2 = m2.
getRows();
1783 unsigned int c2 = m2.
getCols();
1785 out.
resize(r1 * r2, c1 * c2,
false,
false);
1787 for (
unsigned int r = 0; r < r1; r++) {
1788 for (
unsigned int c = 0; c < c1; c++) {
1789 double alpha = m1[r][c];
1790 double *m2ptr = m2[0];
1791 unsigned int roffset = r * r2;
1792 unsigned int coffset = c * c2;
1793 for (
unsigned int rr = 0; rr < r2; rr++) {
1794 for (
unsigned int cc = 0; cc < c2; cc++) {
1795 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
1818 unsigned int r1 = m1.
getRows();
1819 unsigned int c1 = m1.
getCols();
1820 unsigned int r2 = m2.
getRows();
1821 unsigned int c2 = m2.
getCols();
1824 out.
resize(r1 * r2, c1 * c2,
false,
false);
1826 for (
unsigned int r = 0; r < r1; r++) {
1827 for (
unsigned int c = 0; c < c1; c++) {
1828 double alpha = m1[r][c];
1829 double *m2ptr = m2[0];
1830 unsigned int roffset = r * r2;
1831 unsigned int coffset = c * c2;
1832 for (
unsigned int rr = 0; rr < r2; rr++) {
1833 for (
unsigned int cc = 0; cc < c2; cc++) {
1834 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
2023 #if defined(VISP_HAVE_LAPACK)
2025 #elif defined(VISP_HAVE_EIGEN3)
2027 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2092 #if defined(VISP_HAVE_LAPACK)
2094 #elif defined(VISP_HAVE_EIGEN3)
2096 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2102 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2168 #if defined(VISP_HAVE_LAPACK)
2170 #elif defined(VISP_HAVE_EIGEN3)
2172 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2178 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2234 #if defined(VISP_HAVE_LAPACK)
2236 #elif defined(VISP_HAVE_EIGEN3)
2238 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2243 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2299 #if defined(VISP_HAVE_LAPACK)
2301 #elif defined(VISP_HAVE_EIGEN3)
2303 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2308 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2312 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2313 #if defined(VISP_HAVE_LAPACK)
2352 unsigned int nrows =
getRows();
2353 unsigned int ncols =
getCols();
2359 Ap.
resize(ncols, nrows,
false,
false);
2361 if (nrows < ncols) {
2362 U.
resize(ncols, ncols,
true);
2365 U.
resize(nrows, ncols,
false);
2372 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2419 unsigned int nrows =
getRows();
2420 unsigned int ncols =
getCols();
2426 Ap.
resize(ncols, nrows,
false,
false);
2428 if (nrows < ncols) {
2429 U.
resize(ncols, ncols,
true);
2432 U.
resize(nrows, ncols,
false);
2439 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2441 return static_cast<unsigned int>(rank_out);
2492 unsigned int nrows =
getRows();
2493 unsigned int ncols =
getCols();
2499 Ap.
resize(ncols, nrows,
false,
false);
2501 if (nrows < ncols) {
2502 U.
resize(ncols, ncols,
true);
2505 U.
resize(nrows, ncols,
false);
2512 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2518 return static_cast<unsigned int>(rank_out);
2630 unsigned int nrows =
getRows();
2631 unsigned int ncols =
getCols();
2636 if (nrows < ncols) {
2637 U.
resize(ncols, ncols,
true);
2640 U.
resize(nrows, ncols,
false);
2647 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
2653 return static_cast<unsigned int>(rank_out);
2694 unsigned int nrows =
getRows();
2695 unsigned int ncols =
getCols();
2697 double svThreshold = 1e-26;
2702 Ap.
resize(ncols, nrows,
false,
false);
2704 if (nrows < ncols) {
2705 U.
resize(ncols, ncols,
true);
2708 U.
resize(nrows, ncols,
false);
2715 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2768 unsigned int nrows =
getRows();
2769 unsigned int ncols =
getCols();
2771 double svThreshold = 1e-26;
2776 Ap.
resize(ncols, nrows,
false,
false);
2778 if (nrows < ncols) {
2779 U.
resize(ncols, ncols,
true);
2782 U.
resize(nrows, ncols,
false);
2789 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2849 unsigned int nrows =
getRows();
2850 unsigned int ncols =
getCols();
2852 double svThreshold = 1e-26;
2857 Ap.
resize(ncols, nrows,
false,
false);
2859 if (nrows < ncols) {
2860 U.
resize(ncols, ncols,
true);
2863 U.
resize(nrows, ncols,
false);
2870 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2993 unsigned int nrows =
getRows();
2994 unsigned int ncols =
getCols();
2996 double svThreshold = 1e-26;
3000 if (nrows < ncols) {
3001 U.
resize(ncols, ncols,
true);
3004 U.
resize(nrows, ncols,
false);
3011 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3021 #if defined(VISP_HAVE_EIGEN3)
3060 unsigned int nrows =
getRows();
3061 unsigned int ncols =
getCols();
3067 Ap.
resize(ncols, nrows,
false,
false);
3069 if (nrows < ncols) {
3070 U.
resize(ncols, ncols,
true);
3073 U.
resize(nrows, ncols,
false);
3080 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3127 unsigned int nrows =
getRows();
3128 unsigned int ncols =
getCols();
3134 Ap.
resize(ncols, nrows,
false,
false);
3136 if (nrows < ncols) {
3137 U.
resize(ncols, ncols,
true);
3140 U.
resize(nrows, ncols,
false);
3147 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3149 return static_cast<unsigned int>(rank_out);
3200 unsigned int nrows =
getRows();
3201 unsigned int ncols =
getCols();
3207 Ap.
resize(ncols, nrows,
false,
false);
3209 if (nrows < ncols) {
3210 U.
resize(ncols, ncols,
true);
3213 U.
resize(nrows, ncols,
false);
3220 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3226 return static_cast<unsigned int>(rank_out);
3338 unsigned int nrows =
getRows();
3339 unsigned int ncols =
getCols();
3344 if (nrows < ncols) {
3345 U.
resize(ncols, ncols,
true);
3348 U.
resize(nrows, ncols,
false);
3355 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
3361 return static_cast<unsigned int>(rank_out);
3402 unsigned int nrows =
getRows();
3403 unsigned int ncols =
getCols();
3405 double svThreshold = 1e-26;
3410 Ap.
resize(ncols, nrows,
false,
false);
3412 if (nrows < ncols) {
3413 U.
resize(ncols, ncols,
true);
3416 U.
resize(nrows, ncols,
false);
3423 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3476 unsigned int nrows =
getRows();
3477 unsigned int ncols =
getCols();
3479 double svThreshold = 1e-26;
3484 Ap.
resize(ncols, nrows,
false,
false);
3486 if (nrows < ncols) {
3487 U.
resize(ncols, ncols,
true);
3490 U.
resize(nrows, ncols,
false);
3497 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3557 unsigned int nrows =
getRows();
3558 unsigned int ncols =
getCols();
3560 double svThreshold = 1e-26;
3565 Ap.
resize(ncols, nrows,
false,
false);
3567 if (nrows < ncols) {
3568 U.
resize(ncols, ncols,
true);
3571 U.
resize(nrows, ncols,
false);
3578 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3701 unsigned int nrows =
getRows();
3702 unsigned int ncols =
getCols();
3704 double svThreshold = 1e-26;
3708 if (nrows < ncols) {
3709 U.
resize(ncols, ncols,
true);
3712 U.
resize(nrows, ncols,
false);
3719 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3729 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
3768 unsigned int nrows =
getRows();
3769 unsigned int ncols =
getCols();
3775 Ap.
resize(ncols, nrows,
false,
false);
3777 if (nrows < ncols) {
3778 U.
resize(ncols, ncols,
true);
3781 U.
resize(nrows, ncols,
false);
3788 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3835 unsigned int nrows =
getRows();
3836 unsigned int ncols =
getCols();
3842 Ap.
resize(ncols, nrows,
false,
false);
3844 if (nrows < ncols) {
3845 U.
resize(ncols, ncols,
true);
3848 U.
resize(nrows, ncols,
false);
3855 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3857 return static_cast<unsigned int>(rank_out);
3908 unsigned int nrows =
getRows();
3909 unsigned int ncols =
getCols();
3915 Ap.
resize(ncols, nrows,
false,
false);
3917 if (nrows < ncols) {
3918 U.
resize(ncols, ncols,
true);
3921 U.
resize(nrows, ncols,
false);
3928 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3934 return static_cast<unsigned int>(rank_out);
4046 unsigned int nrows =
getRows();
4047 unsigned int ncols =
getCols();
4052 if (nrows < ncols) {
4053 U.
resize(ncols, ncols,
true);
4056 U.
resize(nrows, ncols,
false);
4063 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
4069 return static_cast<unsigned int>(rank_out);
4110 unsigned int nrows =
getRows();
4111 unsigned int ncols =
getCols();
4113 double svThreshold = 1e-26;
4118 Ap.
resize(ncols, nrows,
false,
false);
4120 if (nrows < ncols) {
4121 U.
resize(ncols, ncols,
true);
4124 U.
resize(nrows, ncols,
false);
4131 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4184 unsigned int nrows =
getRows();
4185 unsigned int ncols =
getCols();
4187 double svThreshold = 1e-26;
4192 Ap.
resize(ncols, nrows,
false,
false);
4194 if (nrows < ncols) {
4195 U.
resize(ncols, ncols,
true);
4198 U.
resize(nrows, ncols,
false);
4205 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4265 unsigned int nrows =
getRows();
4266 unsigned int ncols =
getCols();
4268 double svThreshold = 1e-26;
4273 Ap.
resize(ncols, nrows,
false,
false);
4275 if (nrows < ncols) {
4276 U.
resize(ncols, ncols,
true);
4279 U.
resize(nrows, ncols,
false);
4286 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4409 unsigned int nrows =
getRows();
4410 unsigned int ncols =
getCols();
4412 double svThreshold = 1e-26;
4416 if (nrows < ncols) {
4417 U.
resize(ncols, ncols,
true);
4420 U.
resize(nrows, ncols,
false);
4427 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
4502 #if defined(VISP_HAVE_LAPACK)
4504 #elif defined(VISP_HAVE_EIGEN3)
4506 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4513 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4585 #if defined(VISP_HAVE_LAPACK)
4587 #elif defined(VISP_HAVE_EIGEN3)
4589 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4596 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4677 return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt);
4901 #if defined(VISP_HAVE_LAPACK)
4903 #elif defined(VISP_HAVE_EIGEN3)
4905 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4915 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5061 #if defined(VISP_HAVE_LAPACK)
5063 #elif defined(VISP_HAVE_EIGEN3)
5065 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
5075 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5126 for (
unsigned int i = 0; i < column_size; i++)
5127 c[i] = (*
this)[i_begin + i][j];
5254 if (r.
data != NULL &&
data != NULL) {
5255 memcpy(r.
data, (*
this)[i] + j_begin, row_size *
sizeof(
double));
5302 diag.resize(min_size,
false);
5304 for (
unsigned int i = 0; i < min_size; i++) {
5305 diag[i] = (*this)[i][i];
5344 unsigned int nra = A.
getRows();
5345 unsigned int nrb = B.
getRows();
5355 std::cerr <<
"A and C must be two different objects!" << std::endl;
5360 std::cerr <<
"B and C must be two different objects!" << std::endl;
5366 if (C.
data != NULL && A.
data != NULL && A.
size() > 0) {
5371 if (C.
data != NULL && B.
data != NULL && B.
size() > 0) {
5408 std::cerr <<
"A and C must be two different objects!" << std::endl;
5447 std::cerr <<
"A and C must be two different objects!" << std::endl;
5494 for (
unsigned int i = 0; i < A.
getRows(); i++) {
5495 for (
unsigned int j = 0; j < A.
getCols(); j++) {
5496 if (i >= r && i < (r + B.
getRows()) && j >= c && j < (c + B.
getCols())) {
5497 C[i][j] = B[i - r][j - c];
5543 unsigned int nca = A.
getCols();
5544 unsigned int ncb = B.
getCols();
5553 if (B.
getRows() == 0 || nca + ncb == 0) {
5554 std::cerr <<
"B.getRows() == 0 || nca+ncb == 0" << std::endl;
5589 typedef std::string::size_type size_type;
5594 std::vector<std::string> values(m * n);
5595 std::ostringstream oss;
5596 std::ostringstream ossFixed;
5597 std::ios_base::fmtflags original_flags = oss.flags();
5599 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
5601 size_type maxBefore = 0;
5602 size_type maxAfter = 0;
5604 for (
unsigned int i = 0; i < m; ++i) {
5605 for (
unsigned int j = 0; j < n; ++j) {
5607 oss << (*this)[i][j];
5608 if (oss.str().find(
"e") != std::string::npos) {
5610 ossFixed << (*this)[i][j];
5611 oss.str(ossFixed.str());
5614 values[i * n + j] = oss.str();
5615 size_type thislen = values[i * n + j].size();
5616 size_type p = values[i * n + j].find(
'.');
5618 if (p == std::string::npos) {
5628 size_type totalLength = length;
5632 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
5636 s <<
"[" << m <<
"," << n <<
"]=\n";
5638 for (
unsigned int i = 0; i < m; i++) {
5640 for (
unsigned int j = 0; j < n; j++) {
5641 size_type p = values[i * n + j].find(
'.');
5642 s.setf(std::ios::right, std::ios::adjustfield);
5643 s.width((std::streamsize)maxBefore);
5644 s << values[i * n + j].substr(0, p).c_str();
5647 s.setf(std::ios::left, std::ios::adjustfield);
5648 if (p != std::string::npos) {
5649 s.width((std::streamsize)maxAfter);
5650 s << values[i * n + j].substr(p, maxAfter).c_str();
5652 s.width((std::streamsize)maxAfter);
5662 s.flags(original_flags);
5664 return (
int)(maxBefore + maxAfter);
5706 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5707 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5708 os << (*this)[i][j] <<
", ";
5710 if (this->
getRows() != i + 1) {
5711 os <<
";" << std::endl;
5713 os <<
"]" << std::endl;
5749 os <<
"([ " << std::endl;
5750 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5752 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5753 os << (*this)[i][j] <<
", ";
5755 os <<
"]," << std::endl;
5757 os <<
"])" << std::endl;
5790 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5791 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5792 os << (*this)[i][j];
5793 if (!(j == (this->
getCols() - 1)))
5839 os <<
"vpMatrix " << matrixName <<
" (" << this->
getRows() <<
", " << this->
getCols() <<
"); " << std::endl;
5841 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5842 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5844 os << matrixName <<
"[" << i <<
"][" << j <<
"] = " << (*this)[i][j] <<
"; " << std::endl;
5846 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
5847 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"][" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
5848 << (
unsigned int)((
unsigned char *)&((*this)[i][j]))[k] <<
"; " << std::endl;
5871 unsigned int rowNumOld =
rowNum;
5902 if (r.
size() == 0) {
5906 unsigned int oldSize =
size();
5911 memcpy(
data + oldSize, r.
data,
sizeof(
double) * r.
size());
5942 if (c.
size() == 0) {
5947 unsigned int oldColNum =
colNum;
5952 for (
unsigned int i = 0; i <
rowNum; i++) {
5953 memcpy(
data + i *
colNum, tmp.
data + i * oldColNum,
sizeof(
double) * oldColNum);
5976 for (
unsigned int i = r; i < (r + A.
getRows()); i++) {
6033 for (
unsigned int i = 0; i <
rowNum; i++) {
6034 for (
unsigned int j = 0; j <
rowNum; j++) {
6036 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6042 #if defined(VISP_HAVE_LAPACK)
6043 #if defined(VISP_HAVE_GSL)
6045 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6048 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6051 unsigned int Atda = (
unsigned int)m->tda;
6052 for (
unsigned int i = 0; i <
rowNum; i++) {
6053 unsigned int k = i * Atda;
6054 for (
unsigned int j = 0; j <
colNum; j++)
6055 m->data[k + j] = (*
this)[i][j];
6057 gsl_eigen_symmv(m, eval, evec, w);
6059 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6061 for (
unsigned int i = 0; i <
rowNum; i++) {
6062 evalue[i] = gsl_vector_get(eval, i);
6065 gsl_eigen_symmv_free(w);
6066 gsl_vector_free(eval);
6068 gsl_matrix_free(evec);
6072 const char jobz =
'N';
6073 const char uplo =
'U';
6080 lwork =
static_cast<int>(wkopt);
6088 "You should install Lapack 3rd party"));
6152 for (
unsigned int i = 0; i <
rowNum; i++) {
6153 for (
unsigned int j = 0; j <
rowNum; j++) {
6155 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6165 #if defined(VISP_HAVE_LAPACK)
6166 #if defined(VISP_HAVE_GSL)
6168 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6171 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6174 unsigned int Atda = (
unsigned int)m->tda;
6175 for (
unsigned int i = 0; i <
rowNum; i++) {
6176 unsigned int k = i * Atda;
6177 for (
unsigned int j = 0; j <
colNum; j++)
6178 m->data[k + j] = (*
this)[i][j];
6180 gsl_eigen_symmv(m, eval, evec, w);
6182 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6184 for (
unsigned int i = 0; i <
rowNum; i++) {
6185 evalue[i] = gsl_vector_get(eval, i);
6187 Atda = (
unsigned int)evec->tda;
6188 for (
unsigned int i = 0; i <
rowNum; i++) {
6189 unsigned int k = i * Atda;
6190 for (
unsigned int j = 0; j <
rowNum; j++) {
6191 evector[i][j] = evec->
data[k + j];
6195 gsl_eigen_symmv_free(w);
6196 gsl_vector_free(eval);
6198 gsl_matrix_free(evec);
6202 const char jobz =
'V';
6203 const char uplo =
'U';
6210 lwork =
static_cast<int>(wkopt);
6219 "You should install Lapack 3rd party"));
6244 unsigned int nbline =
getRows();
6245 unsigned int nbcol =
getCols();
6250 V.
resize(nbcol, nbcol,
false);
6257 U.
resize(nbcol, nbcol,
true);
6259 U.
resize(nbline, nbcol,
false);
6267 for (
unsigned int i = 0; i < nbcol; i++) {
6268 if (sv[i] > maxsv) {
6273 unsigned int rank = 0;
6274 for (
unsigned int i = 0; i < nbcol; i++) {
6275 if (sv[i] > maxsv * svThreshold) {
6280 kerAt.
resize(nbcol - rank, nbcol);
6281 if (rank != nbcol) {
6282 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6284 if ((sv[j] <= maxsv * svThreshold) &&
6285 (std::fabs(V.
getCol(j).
sumSquare()) > std::numeric_limits<double>::epsilon())) {
6286 for (
unsigned int i = 0; i < V.
getRows(); i++) {
6287 kerAt[k][i] = V[i][j];
6315 unsigned int nbrow =
getRows();
6316 unsigned int nbcol =
getCols();
6321 V.
resize(nbcol, nbcol,
false);
6328 U.
resize(nbcol, nbcol,
true);
6330 U.
resize(nbrow, nbcol,
false);
6337 double maxsv = sv[0];
6339 unsigned int rank = 0;
6340 for (
unsigned int i = 0; i < nbcol; i++) {
6341 if (sv[i] > maxsv * svThreshold) {
6346 kerA.
resize(nbcol, nbcol - rank);
6347 if (rank != nbcol) {
6348 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6350 if (sv[j] <= maxsv * svThreshold) {
6351 for (
unsigned int i = 0; i < nbcol; i++) {
6352 kerA[i][k] = V[i][j];
6359 return (nbcol - rank);
6380 unsigned int nbrow =
getRows();
6381 unsigned int nbcol =
getCols();
6382 unsigned int dim_ =
static_cast<unsigned int>(dim);
6387 V.
resize(nbcol, nbcol,
false);
6394 U.
resize(nbcol, nbcol,
true);
6396 U.
resize(nbrow, nbcol,
false);
6402 kerA.
resize(nbcol, dim_);
6404 unsigned int rank = nbcol - dim_;
6405 for (
unsigned int k = 0; k < dim_; k++) {
6406 unsigned int j = k + rank;
6407 for (
unsigned int i = 0; i < nbcol; i++) {
6408 kerA[i][k] = V[i][j];
6413 double maxsv = sv[0];
6414 unsigned int rank = 0;
6415 for (
unsigned int i = 0; i < nbcol; i++) {
6416 if (sv[i] > maxsv * 1e-6) {
6420 return (nbcol - rank);
6478 #ifdef VISP_HAVE_GSL
6480 double *b =
new double[size_];
6481 for (
size_t i = 0; i < size_; i++)
6483 gsl_matrix_view m = gsl_matrix_view_array(this->
data,
rowNum, colNum);
6484 gsl_matrix_view em = gsl_matrix_view_array(b,
rowNum,
colNum);
6485 gsl_linalg_exponential_ss(&m.matrix, &em.matrix, 0);
6489 memcpy(expA.
data, b, size_ *
sizeof(
double));
6510 for (
unsigned int i = 0; i <
rowNum; i++) {
6512 for (
unsigned int j = 0; j <
colNum; j++) {
6513 sum += fabs((*
this)[i][j]);
6515 if (
sum > nA || i == 0) {
6524 double sca = 1.0 / pow(2.0, s);
6527 _expE = c * exp + _eye;
6528 _expD = -c * exp + _eye;
6529 for (
int k = 2; k <= q; k++) {
6530 c = c * ((double)(q - k + 1)) / ((
double)(k * (2 * q - k + 1)));
6531 _expcX = exp * _expX;
6534 _expE = _expE + _expcX;
6536 _expD = _expD + _expcX;
6538 _expD = _expD - _expcX;
6542 exp = _expX * _expE;
6543 for (
int k = 1; k <= s; k++) {
6576 for (
unsigned int i = 0; i < col; i++) {
6577 for (
unsigned int j = 0; j < row; j++)
6578 M_comp[i][j] = M[i][j];
6579 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6580 M_comp[i][j - 1] = M[i][j];
6582 for (
unsigned int i = col + 1; i < M.
getCols(); i++) {
6583 for (
unsigned int j = 0; j < row; j++)
6584 M_comp[i - 1][j] = M[i][j];
6585 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6586 M_comp[i - 1][j - 1] = M[i][j];
6602 unsigned int nbline =
getRows();
6603 unsigned int nbcol =
getCols();
6608 V.
resize(nbcol, nbcol,
false);
6615 U.
resize(nbcol, nbcol,
true);
6617 U.
resize(nbline, nbcol,
false);
6625 for (
unsigned int i = 0; i < nbcol; i++) {
6626 if (sv[i] > maxsv) {
6632 unsigned int rank = 0;
6633 for (
unsigned int i = 0; i < nbcol; i++) {
6634 if (sv[i] > maxsv * svThreshold) {
6640 double minsv = maxsv;
6641 for (
unsigned int i = 0; i < rank; i++) {
6642 if (sv[i] < minsv) {
6647 if (std::fabs(minsv) > std::numeric_limits<double>::epsilon()) {
6648 return maxsv / minsv;
6650 return std::numeric_limits<double>::infinity();
6668 for (
unsigned int i = 0; i < H.
getCols(); i++) {
6669 HLM[i][i] += alpha * H[i][i];
6683 for (
unsigned int i = 0; i <
dsize; i++) {
6684 double x = *(
data + i);
6701 if (this->
dsize != 0) {
6710 unsigned int maxRank = std::min(this->
getCols(), this->
getRows());
6713 unsigned int boundary = std::min(maxRank, w.
size());
6718 for (
unsigned int i = 0; i < boundary; i++) {
6742 for (
unsigned int i = 0; i <
rowNum; i++) {
6744 for (
unsigned int j = 0; j <
colNum; j++) {
6745 x += fabs(*(*(
rowPtrs + i) + j));
6762 double sum_square = 0.0;
6765 for (
unsigned int i = 0; i <
rowNum; i++) {
6766 for (
unsigned int j = 0; j <
colNum; j++) {
6768 sum_square += x * x;
6810 if (mode ==
"valid") {
6817 if (mode ==
"full" || mode ==
"same") {
6818 const unsigned int pad_x =
kernel.getCols() - 1;
6819 const unsigned int pad_y =
kernel.getRows() - 1;
6821 M_padded.
insert(M, pad_y, pad_x);
6823 if (mode ==
"same") {
6829 }
else if (mode ==
"valid") {
6836 if (mode ==
"same") {
6837 for (
unsigned int i = 0; i < res_same.
getRows(); i++) {
6838 for (
unsigned int j = 0; j < res_same.
getCols(); j++) {
6839 for (
unsigned int k = 0; k <
kernel.getRows(); k++) {
6840 for (
unsigned int l = 0; l <
kernel.getCols(); l++) {
6841 res_same[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
6847 const unsigned int start_i =
kernel.getRows() / 2;
6848 const unsigned int start_j =
kernel.getCols() / 2;
6849 for (
unsigned int i = 0; i < M.
getRows(); i++) {
6851 sizeof(
double) * M.
getCols());
6854 for (
unsigned int i = 0; i < res.
getRows(); i++) {
6855 for (
unsigned int j = 0; j < res.
getCols(); j++) {
6856 for (
unsigned int k = 0; k <
kernel.getRows(); k++) {
6857 for (
unsigned int l = 0; l <
kernel.getCols(); l++) {
6858 res[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
6866 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
6914 for (
unsigned int j = 0; j <
getCols(); j++)
6915 c[j] = (*
this)[i - 1][j];
6940 for (
unsigned int i = 0; i <
getRows(); i++)
6941 c[i] = (*
this)[i][j - 1];
6953 for (
unsigned int i = 0; i <
rowNum; i++)
6954 for (
unsigned int j = 0; j <
colNum; j++)
6956 (*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 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 emited 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)
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full")
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)
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
double euclideanNorm() 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.