55 #include <visp3/core/vpCPUFeatures.h>
56 #include <visp3/core/vpColVector.h>
57 #include <visp3/core/vpConfig.h>
58 #include <visp3/core/vpDebug.h>
59 #include <visp3/core/vpException.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/core/vpMatrix.h>
62 #include <visp3/core/vpTranslationVector.h>
64 #include <Simd/SimdLib.hpp>
66 #ifdef VISP_HAVE_LAPACK
68 #include <gsl/gsl_eigen.h>
69 #include <gsl/gsl_linalg.h>
70 #include <gsl/gsl_math.h>
71 #elif defined(VISP_HAVE_MKL)
73 typedef MKL_INT integer;
75 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
76 double *work_data,
int lwork_,
int &info_)
78 MKL_INT n =
static_cast<MKL_INT
>(n_);
79 MKL_INT lda =
static_cast<MKL_INT
>(lda_);
80 MKL_INT lwork =
static_cast<MKL_INT
>(lwork_);
81 MKL_INT info =
static_cast<MKL_INT
>(info_);
83 dsyev(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
87 #if defined(VISP_HAVE_LAPACK_BUILT_IN)
88 typedef long int integer;
92 extern "C" integer dsyev_(
char *jobz,
char *uplo, integer *n,
double *a, integer *lda,
double *w,
double *WORK,
93 integer *lwork, integer *info);
95 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
96 double *work_data,
int lwork_,
int &info_)
98 integer n =
static_cast<integer
>(n_);
99 integer lda =
static_cast<integer
>(lda_);
100 integer lwork =
static_cast<integer
>(lwork_);
101 integer info =
static_cast<integer
>(info_);
103 dsyev_(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
105 lwork_ =
static_cast<int>(lwork);
106 info_ =
static_cast<int>(info);
111 #if !defined(VISP_USE_MSVC) || (defined(VISP_USE_MSVC) && !defined(VISP_BUILD_SHARED_LIBS))
112 const unsigned int vpMatrix::m_lapack_min_size_default = 0;
113 unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
120 unsigned int ncols,
double svThreshold,
vpMatrix &Ap,
int &rank_out,
int *rank_in,
123 Ap.
resize(ncols, nrows,
true,
false);
126 double maxsv = sv[0];
130 for (
unsigned int i = 0; i < ncols; i++) {
131 if (sv[i] > maxsv * svThreshold) {
136 unsigned int rank =
static_cast<unsigned int>(rank_out);
138 rank =
static_cast<unsigned int>(*rank_in);
141 for (
unsigned int i = 0; i < ncols; i++) {
142 for (
unsigned int j = 0; j < nrows; j++) {
143 for (
unsigned int k = 0; k < rank; k++) {
144 Ap[i][j] += V[i][k] * U[j][k] / sv[k];
153 for (
unsigned int i = 0; i < nrows; i++) {
154 for (
unsigned int j = 0; j < rank; j++) {
155 (*imA)[i][j] = U[i][j];
162 imAt->
resize(ncols, rank);
163 for (
unsigned int i = 0; i < ncols; i++) {
164 for (
unsigned int j = 0; j < rank; j++) {
165 (*imAt)[i][j] = V[i][j];
172 kerAt->
resize(ncols - rank, ncols);
174 for (
unsigned int k = 0; k < (ncols - rank); k++) {
175 unsigned j = k + rank;
176 for (
unsigned int i = 0; i < V.
getRows(); i++) {
177 (*kerAt)[k][i] = V[i][j];
192 if (((r + nrows) > M.
rowNum) || ((c + ncols) > M.
colNum)) {
194 "Cannot construct a sub matrix (%dx%d) starting at "
195 "position (%d,%d) that is not contained in the "
196 "original matrix (%dx%d)",
200 init(M, r, c, nrows, ncols);
203 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
270 vpMatrix::vpMatrix(
unsigned int nrows,
unsigned int ncols,
const std::initializer_list<double> &list)
349 unsigned int rnrows = r + nrows;
350 unsigned int cncols = c + ncols;
358 resize(nrows, ncols,
false,
false);
362 for (
unsigned int i = 0; i < nrows; i++) {
363 memcpy((*
this)[i], &M[i + r][c], ncols *
sizeof(
double));
410 unsigned int rnrows = r + nrows;
411 unsigned int cncols = c + ncols;
421 M.
resize(nrows, ncols,
false,
false);
422 for (
unsigned int i = 0; i < nrows; i++) {
423 memcpy(M[i], &(*
this)[i + r][c], ncols *
sizeof(
double));
452 for (
unsigned int i = 0; i <
rowNum; i++) {
453 for (
unsigned int j = 0; j <
colNum; j++) {
489 for (
unsigned int i = 0; i <
rowNum; i++) {
490 for (
unsigned int j = 0; j <
colNum; j++) {
491 At[j][i] = (*this)[i][j];
530 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
531 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
536 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
537 const double alpha = 1.0;
538 const double beta = 0.0;
539 const char transa =
't';
540 const char transb =
'n';
542 vpMatrix::blas_dgemm(transa, transb,
rowNum,
rowNum,
colNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
547 for (
unsigned int i = 0; i <
rowNum; i++) {
548 for (
unsigned int j = i; j <
rowNum; j++) {
554 for (
unsigned int k = 0; k <
colNum; k++)
555 ssum += *(pi++) * *(pj++);
582 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
583 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
588 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
589 const double alpha = 1.0;
590 const double beta = 0.0;
591 const char transa =
'n';
592 const char transb =
't';
594 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
598 for (
unsigned int i = 0; i <
colNum; i++) {
600 for (
unsigned int j = 0; j < i; j++) {
603 for (
unsigned int k = 0; k <
rowNum; k++) {
604 s += (*(ptr + i)) * (*(ptr + j));
612 for (
unsigned int k = 0; k <
rowNum; k++) {
613 s += (*(ptr + i)) * (*(ptr + i));
662 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
676 if (
this != &other) {
688 other.rowPtrs = NULL;
720 if (
dsize !=
static_cast<unsigned int>(list.size())) {
721 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
724 std::copy(list.begin(), list.end(),
data);
754 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
755 for (
auto &l : lists) {
756 if (
static_cast<unsigned int>(l.size()) > ncols) {
757 ncols =
static_cast<unsigned int>(l.size());
761 resize(nrows, ncols,
false,
false);
762 auto it = lists.begin();
763 for (
unsigned int i = 0; i <
rowNum; i++, ++it) {
764 std::copy(it->begin(), it->end(),
rowPtrs[i]);
785 for (
unsigned int i = 0; i <
rowNum; i++) {
786 for (
unsigned int j = 0; j <
colNum; j++) {
795 resize(1, 1,
false,
false);
844 unsigned int rows = A.
getRows();
848 for (
unsigned int i = 0; i < rows; i++)
849 (*
this)[i][i] = A[i];
886 for (
unsigned int i = 0; i < min_; i++)
903 unsigned int rows = A.
getRows();
904 DA.
resize(rows, rows,
true);
906 for (
unsigned int i = 0; i < rows; i++)
923 for (
unsigned int j = 0; j < 3; j++)
926 for (
unsigned int j = 0; j < 3; j++) {
928 for (
unsigned int i = 0; i < 3; i++) {
929 t_out[i] +=
rowPtrs[i][j] * tj;
965 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size);
966 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
971 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
977 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,
1030 const unsigned int BcolNum = B.
colNum;
1031 const unsigned int BrowNum = B.
rowNum;
1032 double **BrowPtrs = B.
rowPtrs;
1033 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1034 const double *rowptri = A.
rowPtrs[i];
1036 for (
unsigned int j = 0; j < BcolNum; j++) {
1038 for (
unsigned int k = 0; k < BrowNum; k++)
1039 s += rowptri[k] * BrowPtrs[k][j];
1063 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1068 const unsigned int BcolNum = B.
colNum;
1069 const unsigned int BrowNum = B.
rowNum;
1070 double **BrowPtrs = B.
rowPtrs;
1071 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1072 const double *rowptri = A.
rowPtrs[i];
1074 for (
unsigned int j = 0; j < BcolNum; j++) {
1076 for (
unsigned int k = 0; k < BrowNum; k++)
1077 s += rowptri[k] * BrowPtrs[k][j];
1100 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1109 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1110 B.
colNum > vpMatrix::m_lapack_min_size);
1111 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1116 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1117 const double alpha = 1.0;
1118 const double beta = 0.0;
1119 const char trans =
'n';
1120 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1125 const unsigned int BcolNum = B.
colNum;
1126 const unsigned int BrowNum = B.
rowNum;
1127 double **BrowPtrs = B.
rowPtrs;
1128 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1129 const double *rowptri = A.
rowPtrs[i];
1131 for (
unsigned int j = 0; j < BcolNum; j++) {
1133 for (
unsigned int k = 0; k < BrowNum; k++)
1134 s += rowptri[k] * BrowPtrs[k][j];
1184 unsigned int RcolNum = R.
getCols();
1185 unsigned int RrowNum = R.
getRows();
1186 for (
unsigned int i = 0; i <
rowNum; i++) {
1189 for (
unsigned int j = 0; j < RcolNum; j++) {
1191 for (
unsigned int k = 0; k < RrowNum; k++)
1192 s += rowptri[k] * R[k][j];
1213 const unsigned int McolNum = M.
getCols();
1214 const unsigned int MrowNum = M.
getRows();
1215 for (
unsigned int i = 0; i <
rowNum; i++) {
1216 const double *rowptri =
rowPtrs[i];
1218 for (
unsigned int j = 0; j < McolNum; j++) {
1220 for (
unsigned int k = 0; k < MrowNum; k++)
1221 s += rowptri[k] * M[k][j];
1247 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1248 V.
colNum > vpMatrix::m_lapack_min_size);
1249 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1254 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1255 const double alpha = 1.0;
1256 const double beta = 0.0;
1257 const char trans =
'n';
1258 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
1286 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1287 V.
getCols() > vpMatrix::m_lapack_min_size);
1288 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1293 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1294 const double alpha = 1.0;
1295 const double beta = 0.0;
1296 const char trans =
'n';
1297 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
1328 double **ArowPtrs = A.
rowPtrs;
1329 double **BrowPtrs = B.
rowPtrs;
1330 double **CrowPtrs = C.
rowPtrs;
1332 for (
unsigned int i = 0; i < A.
rowNum; i++)
1333 for (
unsigned int j = 0; j < A.
colNum; j++)
1334 CrowPtrs[i][j] = wB * BrowPtrs[i][j] + wA * ArowPtrs[i][j];
1356 double **ArowPtrs = A.
rowPtrs;
1357 double **BrowPtrs = B.
rowPtrs;
1358 double **CrowPtrs = C.
rowPtrs;
1360 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1361 for (
unsigned int j = 0; j < A.
colNum; j++) {
1362 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1389 double **ArowPtrs = A.
rowPtrs;
1390 double **BrowPtrs = B.
rowPtrs;
1391 double **CrowPtrs = C.
rowPtrs;
1393 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1394 for (
unsigned int j = 0; j < A.
colNum; j++) {
1395 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1436 double **ArowPtrs = A.
rowPtrs;
1437 double **BrowPtrs = B.
rowPtrs;
1438 double **CrowPtrs = C.
rowPtrs;
1440 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1441 for (
unsigned int j = 0; j < A.
colNum; j++) {
1442 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1469 double **ArowPtrs = A.
rowPtrs;
1470 double **BrowPtrs = B.
rowPtrs;
1471 double **CrowPtrs = C.
rowPtrs;
1473 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1474 for (
unsigned int j = 0; j < A.
colNum; j++) {
1475 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1500 double **BrowPtrs = B.
rowPtrs;
1502 for (
unsigned int i = 0; i <
rowNum; i++)
1503 for (
unsigned int j = 0; j <
colNum; j++)
1504 rowPtrs[i][j] += BrowPtrs[i][j];
1517 double **BrowPtrs = B.
rowPtrs;
1518 for (
unsigned int i = 0; i <
rowNum; i++)
1519 for (
unsigned int j = 0; j <
colNum; j++)
1520 rowPtrs[i][j] -= BrowPtrs[i][j];
1539 double **ArowPtrs = A.
rowPtrs;
1540 double **CrowPtrs = C.
rowPtrs;
1543 for (
unsigned int i = 0; i < A.
rowNum; i++)
1544 for (
unsigned int j = 0; j < A.
colNum; j++)
1545 CrowPtrs[i][j] = -ArowPtrs[i][j];
1562 for (
unsigned int i = 0; i <
rowNum; i++) {
1563 for (
unsigned int j = 0; j <
colNum; j++) {
1585 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1589 unsigned int Brow = B.
getRows();
1590 unsigned int Bcol = B.
getCols();
1593 C.
resize(Brow, Bcol,
false,
false);
1595 for (
unsigned int i = 0; i < Brow; i++)
1596 for (
unsigned int j = 0; j < Bcol; j++)
1597 C[i][j] = B[i][j] * x;
1608 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1615 for (
unsigned int i = 0; i <
rowNum; i++)
1616 for (
unsigned int j = 0; j <
colNum; j++)
1625 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1629 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
1636 double xinv = 1 / x;
1638 for (
unsigned int i = 0; i <
rowNum; i++)
1639 for (
unsigned int j = 0; j <
colNum; j++)
1640 C[i][j] =
rowPtrs[i][j] * xinv;
1648 for (
unsigned int i = 0; i <
rowNum; i++)
1649 for (
unsigned int j = 0; j <
colNum; j++)
1658 for (
unsigned int i = 0; i <
rowNum; i++)
1659 for (
unsigned int j = 0; j <
colNum; j++)
1671 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1675 for (
unsigned int i = 0; i <
rowNum; i++)
1676 for (
unsigned int j = 0; j <
colNum; j++)
1685 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1689 if (std::fabs(x) < std::numeric_limits<double>::epsilon())
1692 double xinv = 1 / x;
1694 for (
unsigned int i = 0; i <
rowNum; i++)
1695 for (
unsigned int j = 0; j <
colNum; j++)
1714 double *optr = out.
data;
1715 for (
unsigned int j = 0; j <
colNum; j++) {
1716 for (
unsigned int i = 0; i <
rowNum; i++) {
1783 unsigned int r1 = m1.
getRows();
1784 unsigned int c1 = m1.
getCols();
1785 unsigned int r2 = m2.
getRows();
1786 unsigned int c2 = m2.
getCols();
1788 out.
resize(r1 * r2, c1 * c2,
false,
false);
1790 for (
unsigned int r = 0; r < r1; r++) {
1791 for (
unsigned int c = 0; c < c1; c++) {
1792 double alpha = m1[r][c];
1793 double *m2ptr = m2[0];
1794 unsigned int roffset = r * r2;
1795 unsigned int coffset = c * c2;
1796 for (
unsigned int rr = 0; rr < r2; rr++) {
1797 for (
unsigned int cc = 0; cc < c2; cc++) {
1798 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
1821 unsigned int r1 = m1.
getRows();
1822 unsigned int c1 = m1.
getCols();
1823 unsigned int r2 = m2.
getRows();
1824 unsigned int c2 = m2.
getCols();
1827 out.
resize(r1 * r2, c1 * c2,
false,
false);
1829 for (
unsigned int r = 0; r < r1; r++) {
1830 for (
unsigned int c = 0; c < c1; c++) {
1831 double alpha = m1[r][c];
1832 double *m2ptr = m2[0];
1833 unsigned int roffset = r * r2;
1834 unsigned int coffset = c * c2;
1835 for (
unsigned int rr = 0; rr < r2; rr++) {
1836 for (
unsigned int cc = 0; cc < c2; cc++) {
1837 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
2026 #if defined(VISP_HAVE_LAPACK)
2028 #elif defined(VISP_HAVE_EIGEN3)
2030 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2095 #if defined(VISP_HAVE_LAPACK)
2097 #elif defined(VISP_HAVE_EIGEN3)
2099 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2105 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2171 #if defined(VISP_HAVE_LAPACK)
2173 #elif defined(VISP_HAVE_EIGEN3)
2175 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2181 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2237 #if defined(VISP_HAVE_LAPACK)
2239 #elif defined(VISP_HAVE_EIGEN3)
2241 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2246 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2302 #if defined(VISP_HAVE_LAPACK)
2304 #elif defined(VISP_HAVE_EIGEN3)
2306 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
2311 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2315 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2316 #if defined(VISP_HAVE_LAPACK)
2355 unsigned int nrows =
getRows();
2356 unsigned int ncols =
getCols();
2362 Ap.
resize(ncols, nrows,
false,
false);
2364 if (nrows < ncols) {
2365 U.
resize(ncols, ncols,
true);
2368 U.
resize(nrows, ncols,
false);
2375 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2422 unsigned int nrows =
getRows();
2423 unsigned int ncols =
getCols();
2429 Ap.
resize(ncols, nrows,
false,
false);
2431 if (nrows < ncols) {
2432 U.
resize(ncols, ncols,
true);
2435 U.
resize(nrows, ncols,
false);
2442 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2444 return static_cast<unsigned int>(rank_out);
2495 unsigned int nrows =
getRows();
2496 unsigned int ncols =
getCols();
2502 Ap.
resize(ncols, nrows,
false,
false);
2504 if (nrows < ncols) {
2505 U.
resize(ncols, ncols,
true);
2508 U.
resize(nrows, ncols,
false);
2515 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2521 return static_cast<unsigned int>(rank_out);
2633 unsigned int nrows =
getRows();
2634 unsigned int ncols =
getCols();
2639 if (nrows < ncols) {
2640 U.
resize(ncols, ncols,
true);
2643 U.
resize(nrows, ncols,
false);
2650 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
2656 return static_cast<unsigned int>(rank_out);
2697 unsigned int nrows =
getRows();
2698 unsigned int ncols =
getCols();
2700 double svThreshold = 1e-26;
2705 Ap.
resize(ncols, nrows,
false,
false);
2707 if (nrows < ncols) {
2708 U.
resize(ncols, ncols,
true);
2711 U.
resize(nrows, ncols,
false);
2718 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2771 unsigned int nrows =
getRows();
2772 unsigned int ncols =
getCols();
2774 double svThreshold = 1e-26;
2779 Ap.
resize(ncols, nrows,
false,
false);
2781 if (nrows < ncols) {
2782 U.
resize(ncols, ncols,
true);
2785 U.
resize(nrows, ncols,
false);
2792 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2852 unsigned int nrows =
getRows();
2853 unsigned int ncols =
getCols();
2855 double svThreshold = 1e-26;
2860 Ap.
resize(ncols, nrows,
false,
false);
2862 if (nrows < ncols) {
2863 U.
resize(ncols, ncols,
true);
2866 U.
resize(nrows, ncols,
false);
2873 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2996 unsigned int nrows =
getRows();
2997 unsigned int ncols =
getCols();
2999 double svThreshold = 1e-26;
3003 if (nrows < ncols) {
3004 U.
resize(ncols, ncols,
true);
3007 U.
resize(nrows, ncols,
false);
3014 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3024 #if defined(VISP_HAVE_EIGEN3)
3063 unsigned int nrows =
getRows();
3064 unsigned int ncols =
getCols();
3070 Ap.
resize(ncols, nrows,
false,
false);
3072 if (nrows < ncols) {
3073 U.
resize(ncols, ncols,
true);
3076 U.
resize(nrows, ncols,
false);
3083 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3130 unsigned int nrows =
getRows();
3131 unsigned int ncols =
getCols();
3137 Ap.
resize(ncols, nrows,
false,
false);
3139 if (nrows < ncols) {
3140 U.
resize(ncols, ncols,
true);
3143 U.
resize(nrows, ncols,
false);
3150 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3152 return static_cast<unsigned int>(rank_out);
3203 unsigned int nrows =
getRows();
3204 unsigned int ncols =
getCols();
3210 Ap.
resize(ncols, nrows,
false,
false);
3212 if (nrows < ncols) {
3213 U.
resize(ncols, ncols,
true);
3216 U.
resize(nrows, ncols,
false);
3223 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3229 return static_cast<unsigned int>(rank_out);
3341 unsigned int nrows =
getRows();
3342 unsigned int ncols =
getCols();
3347 if (nrows < ncols) {
3348 U.
resize(ncols, ncols,
true);
3351 U.
resize(nrows, ncols,
false);
3358 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
3364 return static_cast<unsigned int>(rank_out);
3405 unsigned int nrows =
getRows();
3406 unsigned int ncols =
getCols();
3408 double svThreshold = 1e-26;
3413 Ap.
resize(ncols, nrows,
false,
false);
3415 if (nrows < ncols) {
3416 U.
resize(ncols, ncols,
true);
3419 U.
resize(nrows, ncols,
false);
3426 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3479 unsigned int nrows =
getRows();
3480 unsigned int ncols =
getCols();
3482 double svThreshold = 1e-26;
3487 Ap.
resize(ncols, nrows,
false,
false);
3489 if (nrows < ncols) {
3490 U.
resize(ncols, ncols,
true);
3493 U.
resize(nrows, ncols,
false);
3500 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3560 unsigned int nrows =
getRows();
3561 unsigned int ncols =
getCols();
3563 double svThreshold = 1e-26;
3568 Ap.
resize(ncols, nrows,
false,
false);
3570 if (nrows < ncols) {
3571 U.
resize(ncols, ncols,
true);
3574 U.
resize(nrows, ncols,
false);
3581 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3704 unsigned int nrows =
getRows();
3705 unsigned int ncols =
getCols();
3707 double svThreshold = 1e-26;
3711 if (nrows < ncols) {
3712 U.
resize(ncols, ncols,
true);
3715 U.
resize(nrows, ncols,
false);
3722 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3732 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101)
3771 unsigned int nrows =
getRows();
3772 unsigned int ncols =
getCols();
3778 Ap.
resize(ncols, nrows,
false,
false);
3780 if (nrows < ncols) {
3781 U.
resize(ncols, ncols,
true);
3784 U.
resize(nrows, ncols,
false);
3791 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3838 unsigned int nrows =
getRows();
3839 unsigned int ncols =
getCols();
3845 Ap.
resize(ncols, nrows,
false,
false);
3847 if (nrows < ncols) {
3848 U.
resize(ncols, ncols,
true);
3851 U.
resize(nrows, ncols,
false);
3858 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3860 return static_cast<unsigned int>(rank_out);
3911 unsigned int nrows =
getRows();
3912 unsigned int ncols =
getCols();
3918 Ap.
resize(ncols, nrows,
false,
false);
3920 if (nrows < ncols) {
3921 U.
resize(ncols, ncols,
true);
3924 U.
resize(nrows, ncols,
false);
3931 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3937 return static_cast<unsigned int>(rank_out);
4049 unsigned int nrows =
getRows();
4050 unsigned int ncols =
getCols();
4055 if (nrows < ncols) {
4056 U.
resize(ncols, ncols,
true);
4059 U.
resize(nrows, ncols,
false);
4066 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerAt);
4072 return static_cast<unsigned int>(rank_out);
4113 unsigned int nrows =
getRows();
4114 unsigned int ncols =
getCols();
4116 double svThreshold = 1e-26;
4121 Ap.
resize(ncols, nrows,
false,
false);
4123 if (nrows < ncols) {
4124 U.
resize(ncols, ncols,
true);
4127 U.
resize(nrows, ncols,
false);
4134 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4187 unsigned int nrows =
getRows();
4188 unsigned int ncols =
getCols();
4190 double svThreshold = 1e-26;
4195 Ap.
resize(ncols, nrows,
false,
false);
4197 if (nrows < ncols) {
4198 U.
resize(ncols, ncols,
true);
4201 U.
resize(nrows, ncols,
false);
4208 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4268 unsigned int nrows =
getRows();
4269 unsigned int ncols =
getCols();
4271 double svThreshold = 1e-26;
4276 Ap.
resize(ncols, nrows,
false,
false);
4278 if (nrows < ncols) {
4279 U.
resize(ncols, ncols,
true);
4282 U.
resize(nrows, ncols,
false);
4289 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4412 unsigned int nrows =
getRows();
4413 unsigned int ncols =
getCols();
4415 double svThreshold = 1e-26;
4419 if (nrows < ncols) {
4420 U.
resize(ncols, ncols,
true);
4423 U.
resize(nrows, ncols,
false);
4430 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
4505 #if defined(VISP_HAVE_LAPACK)
4507 #elif defined(VISP_HAVE_EIGEN3)
4509 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4516 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4588 #if defined(VISP_HAVE_LAPACK)
4590 #elif defined(VISP_HAVE_EIGEN3)
4592 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4599 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4680 return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt);
4904 #if defined(VISP_HAVE_LAPACK)
4906 #elif defined(VISP_HAVE_EIGEN3)
4908 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
4918 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5064 #if defined(VISP_HAVE_LAPACK)
5066 #elif defined(VISP_HAVE_EIGEN3)
5068 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101)
5078 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5129 for (
unsigned int i = 0; i < column_size; i++)
5130 c[i] = (*
this)[i_begin + i][j];
5257 if (r.
data != NULL &&
data != NULL) {
5258 memcpy(r.
data, (*
this)[i] + j_begin, row_size *
sizeof(
double));
5305 diag.resize(min_size,
false);
5307 for (
unsigned int i = 0; i < min_size; i++) {
5308 diag[i] = (*this)[i][i];
5347 unsigned int nra = A.
getRows();
5348 unsigned int nrb = B.
getRows();
5358 std::cerr <<
"A and C must be two different objects!" << std::endl;
5363 std::cerr <<
"B and C must be two different objects!" << std::endl;
5369 if (C.
data != NULL && A.
data != NULL && A.
size() > 0) {
5374 if (C.
data != NULL && B.
data != NULL && B.
size() > 0) {
5411 std::cerr <<
"A and C must be two different objects!" << std::endl;
5450 std::cerr <<
"A and C must be two different objects!" << std::endl;
5497 for (
unsigned int i = 0; i < A.
getRows(); i++) {
5498 for (
unsigned int j = 0; j < A.
getCols(); j++) {
5499 if (i >= r && i < (r + B.
getRows()) && j >= c && j < (c + B.
getCols())) {
5500 C[i][j] = B[i - r][j - c];
5546 unsigned int nca = A.
getCols();
5547 unsigned int ncb = B.
getCols();
5556 if (B.
getRows() == 0 || nca + ncb == 0) {
5557 std::cerr <<
"B.getRows() == 0 || nca+ncb == 0" << std::endl;
5592 typedef std::string::size_type size_type;
5597 std::vector<std::string> values(m * n);
5598 std::ostringstream oss;
5599 std::ostringstream ossFixed;
5600 std::ios_base::fmtflags original_flags = oss.flags();
5603 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
5605 size_type maxBefore = 0;
5606 size_type maxAfter = 0;
5608 for (
unsigned int i = 0; i < m; ++i) {
5609 for (
unsigned int j = 0; j < n; ++j) {
5611 oss << (*this)[i][j];
5612 if (oss.str().find(
"e") != std::string::npos) {
5614 ossFixed << (*this)[i][j];
5615 oss.str(ossFixed.str());
5618 values[i * n + j] = oss.str();
5619 size_type thislen = values[i * n + j].size();
5620 size_type p = values[i * n + j].find(
'.');
5622 if (p == std::string::npos) {
5632 size_type totalLength = length;
5636 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
5645 s <<
"[" << m <<
"," << n <<
"]=\n";
5647 for (
unsigned int i = 0; i < m; i++) {
5649 for (
unsigned int j = 0; j < n; j++) {
5650 size_type p = values[i * n + j].find(
'.');
5651 s.setf(std::ios::right, std::ios::adjustfield);
5652 s.width((std::streamsize)maxBefore);
5653 s << values[i * n + j].substr(0, p).c_str();
5656 s.setf(std::ios::left, std::ios::adjustfield);
5657 if (p != std::string::npos) {
5658 s.width((std::streamsize)maxAfter);
5659 s << values[i * n + j].substr(p, maxAfter).c_str();
5661 assert(maxAfter > 1);
5662 s.width((std::streamsize)maxAfter);
5672 s.flags(original_flags);
5674 return (
int)(maxBefore + maxAfter);
5716 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5717 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5718 os << (*this)[i][j] <<
", ";
5720 if (this->
getRows() != i + 1) {
5721 os <<
";" << std::endl;
5723 os <<
"]" << std::endl;
5759 os <<
"([ " << std::endl;
5760 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5762 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5763 os << (*this)[i][j] <<
", ";
5765 os <<
"]," << std::endl;
5767 os <<
"])" << std::endl;
5800 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5801 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5802 os << (*this)[i][j];
5803 if (!(j == (this->
getCols() - 1)))
5849 os <<
"vpMatrix " << matrixName <<
" (" << this->
getRows() <<
", " << this->
getCols() <<
"); " << std::endl;
5851 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5852 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5854 os << matrixName <<
"[" << i <<
"][" << j <<
"] = " << (*this)[i][j] <<
"; " << std::endl;
5856 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
5857 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"][" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
5858 << (
unsigned int)((
unsigned char *)&((*this)[i][j]))[k] <<
"; " << std::endl;
5881 unsigned int rowNumOld =
rowNum;
5912 if (r.
size() == 0) {
5916 unsigned int oldSize =
size();
5921 memcpy(
data + oldSize, r.
data,
sizeof(
double) * r.
size());
5952 if (c.
size() == 0) {
5957 unsigned int oldColNum =
colNum;
5962 for (
unsigned int i = 0; i <
rowNum; i++) {
5963 memcpy(
data + i *
colNum, tmp.
data + i * oldColNum,
sizeof(
double) * oldColNum);
5986 for (
unsigned int i = r; i < (r + A.
getRows()); i++) {
6043 for (
unsigned int i = 0; i <
rowNum; i++) {
6044 for (
unsigned int j = 0; j <
rowNum; j++) {
6046 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6052 #if defined(VISP_HAVE_LAPACK)
6053 #if defined(VISP_HAVE_GSL)
6055 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6058 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6061 unsigned int Atda = (
unsigned int)m->tda;
6062 for (
unsigned int i = 0; i <
rowNum; i++) {
6063 unsigned int k = i * Atda;
6064 for (
unsigned int j = 0; j <
colNum; j++)
6065 m->data[k + j] = (*
this)[i][j];
6067 gsl_eigen_symmv(m, eval, evec, w);
6069 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6071 for (
unsigned int i = 0; i <
rowNum; i++) {
6072 evalue[i] = gsl_vector_get(eval, i);
6075 gsl_eigen_symmv_free(w);
6076 gsl_vector_free(eval);
6078 gsl_matrix_free(evec);
6082 const char jobz =
'N';
6083 const char uplo =
'U';
6090 lwork =
static_cast<int>(wkopt);
6098 "You should install Lapack 3rd party"));
6162 for (
unsigned int i = 0; i <
rowNum; i++) {
6163 for (
unsigned int j = 0; j <
rowNum; j++) {
6165 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6175 #if defined(VISP_HAVE_LAPACK)
6176 #if defined(VISP_HAVE_GSL)
6178 gsl_vector *eval = gsl_vector_alloc(
rowNum);
6181 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
6184 unsigned int Atda = (
unsigned int)m->tda;
6185 for (
unsigned int i = 0; i <
rowNum; i++) {
6186 unsigned int k = i * Atda;
6187 for (
unsigned int j = 0; j <
colNum; j++)
6188 m->data[k + j] = (*
this)[i][j];
6190 gsl_eigen_symmv(m, eval, evec, w);
6192 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6194 for (
unsigned int i = 0; i <
rowNum; i++) {
6195 evalue[i] = gsl_vector_get(eval, i);
6197 Atda = (
unsigned int)evec->tda;
6198 for (
unsigned int i = 0; i <
rowNum; i++) {
6199 unsigned int k = i * Atda;
6200 for (
unsigned int j = 0; j <
rowNum; j++) {
6201 evector[i][j] = evec->
data[k + j];
6205 gsl_eigen_symmv_free(w);
6206 gsl_vector_free(eval);
6208 gsl_matrix_free(evec);
6212 const char jobz =
'V';
6213 const char uplo =
'U';
6220 lwork =
static_cast<int>(wkopt);
6229 "You should install Lapack 3rd party"));
6254 unsigned int nbline =
getRows();
6255 unsigned int nbcol =
getCols();
6260 V.
resize(nbcol, nbcol,
false);
6267 U.
resize(nbcol, nbcol,
true);
6269 U.
resize(nbline, nbcol,
false);
6277 for (
unsigned int i = 0; i < nbcol; i++) {
6278 if (sv[i] > maxsv) {
6283 unsigned int rank = 0;
6284 for (
unsigned int i = 0; i < nbcol; i++) {
6285 if (sv[i] > maxsv * svThreshold) {
6290 kerAt.
resize(nbcol - rank, nbcol);
6291 if (rank != nbcol) {
6292 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6294 if ((sv[j] <= maxsv * svThreshold) &&
6295 (std::fabs(V.
getCol(j).
sumSquare()) > std::numeric_limits<double>::epsilon())) {
6296 for (
unsigned int i = 0; i < V.
getRows(); i++) {
6297 kerAt[k][i] = V[i][j];
6325 unsigned int nbrow =
getRows();
6326 unsigned int nbcol =
getCols();
6331 V.
resize(nbcol, nbcol,
false);
6338 U.
resize(nbcol, nbcol,
true);
6340 U.
resize(nbrow, nbcol,
false);
6347 double maxsv = sv[0];
6349 unsigned int rank = 0;
6350 for (
unsigned int i = 0; i < nbcol; i++) {
6351 if (sv[i] > maxsv * svThreshold) {
6356 kerA.
resize(nbcol, nbcol - rank);
6357 if (rank != nbcol) {
6358 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6360 if (sv[j] <= maxsv * svThreshold) {
6361 for (
unsigned int i = 0; i < nbcol; i++) {
6362 kerA[i][k] = V[i][j];
6369 return (nbcol - rank);
6390 unsigned int nbrow =
getRows();
6391 unsigned int nbcol =
getCols();
6392 unsigned int dim_ =
static_cast<unsigned int>(dim);
6397 V.
resize(nbcol, nbcol,
false);
6404 U.
resize(nbcol, nbcol,
true);
6406 U.
resize(nbrow, nbcol,
false);
6412 kerA.
resize(nbcol, dim_);
6414 unsigned int rank = nbcol - dim_;
6415 for (
unsigned int k = 0; k < dim_; k++) {
6416 unsigned int j = k + rank;
6417 for (
unsigned int i = 0; i < nbcol; i++) {
6418 kerA[i][k] = V[i][j];
6423 double maxsv = sv[0];
6424 unsigned int rank = 0;
6425 for (
unsigned int i = 0; i < nbcol; i++) {
6426 if (sv[i] > maxsv * 1e-6) {
6430 return (nbcol - rank);
6488 #ifdef VISP_HAVE_GSL
6490 double *b =
new double[size_];
6491 for (
size_t i = 0; i < size_; i++)
6493 gsl_matrix_view m = gsl_matrix_view_array(this->
data,
rowNum, colNum);
6494 gsl_matrix_view em = gsl_matrix_view_array(b,
rowNum,
colNum);
6495 gsl_linalg_exponential_ss(&m.matrix, &em.matrix, 0);
6499 memcpy(expA.
data, b, size_ *
sizeof(
double));
6520 for (
unsigned int i = 0; i <
rowNum; i++) {
6522 for (
unsigned int j = 0; j <
colNum; j++) {
6523 sum += fabs((*
this)[i][j]);
6525 if (
sum > nA || i == 0) {
6534 double sca = 1.0 / pow(2.0, s);
6537 _expE = c * exp + _eye;
6538 _expD = -c * exp + _eye;
6539 for (
int k = 2; k <= q; k++) {
6540 c = c * ((double)(q - k + 1)) / ((
double)(k * (2 * q - k + 1)));
6541 _expcX = exp * _expX;
6544 _expE = _expE + _expcX;
6546 _expD = _expD + _expcX;
6548 _expD = _expD - _expcX;
6552 exp = _expX * _expE;
6553 for (
int k = 1; k <= s; k++) {
6586 for (
unsigned int i = 0; i < col; i++) {
6587 for (
unsigned int j = 0; j < row; j++)
6588 M_comp[i][j] = M[i][j];
6589 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6590 M_comp[i][j - 1] = M[i][j];
6592 for (
unsigned int i = col + 1; i < M.
getCols(); i++) {
6593 for (
unsigned int j = 0; j < row; j++)
6594 M_comp[i - 1][j] = M[i][j];
6595 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6596 M_comp[i - 1][j - 1] = M[i][j];
6612 unsigned int nbline =
getRows();
6613 unsigned int nbcol =
getCols();
6618 V.
resize(nbcol, nbcol,
false);
6625 U.
resize(nbcol, nbcol,
true);
6627 U.
resize(nbline, nbcol,
false);
6635 for (
unsigned int i = 0; i < nbcol; i++) {
6636 if (sv[i] > maxsv) {
6642 unsigned int rank = 0;
6643 for (
unsigned int i = 0; i < nbcol; i++) {
6644 if (sv[i] > maxsv * svThreshold) {
6650 double minsv = maxsv;
6651 for (
unsigned int i = 0; i < rank; i++) {
6652 if (sv[i] < minsv) {
6657 if (std::fabs(minsv) > std::numeric_limits<double>::epsilon()) {
6658 return maxsv / minsv;
6660 return std::numeric_limits<double>::infinity();
6678 for (
unsigned int i = 0; i < H.
getCols(); i++) {
6679 HLM[i][i] += alpha * H[i][i];
6693 for (
unsigned int i = 0; i <
dsize; i++) {
6694 double x = *(
data + i);
6711 if (this->
dsize != 0) {
6720 unsigned int maxRank = std::min(this->
getCols(), this->
getRows());
6723 unsigned int boundary = std::min(maxRank, w.
size());
6728 for (
unsigned int i = 0; i < boundary; i++) {
6752 for (
unsigned int i = 0; i <
rowNum; i++) {
6754 for (
unsigned int j = 0; j <
colNum; j++) {
6755 x += fabs(*(*(
rowPtrs + i) + j));
6772 double sum_square = 0.0;
6775 for (
unsigned int i = 0; i <
rowNum; i++) {
6776 for (
unsigned int j = 0; j <
colNum; j++) {
6778 sum_square += x * x;
6820 if (mode ==
"valid") {
6827 if (mode ==
"full" || mode ==
"same") {
6828 const unsigned int pad_x =
kernel.getCols() - 1;
6829 const unsigned int pad_y =
kernel.getRows() - 1;
6831 M_padded.
insert(M, pad_y, pad_x);
6833 if (mode ==
"same") {
6839 }
else if (mode ==
"valid") {
6846 if (mode ==
"same") {
6847 for (
unsigned int i = 0; i < res_same.
getRows(); i++) {
6848 for (
unsigned int j = 0; j < res_same.
getCols(); j++) {
6849 for (
unsigned int k = 0; k <
kernel.getRows(); k++) {
6850 for (
unsigned int l = 0; l <
kernel.getCols(); l++) {
6851 res_same[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
6857 const unsigned int start_i =
kernel.getRows() / 2;
6858 const unsigned int start_j =
kernel.getCols() / 2;
6859 for (
unsigned int i = 0; i < M.
getRows(); i++) {
6861 sizeof(
double) * M.
getCols());
6864 for (
unsigned int i = 0; i < res.
getRows(); i++) {
6865 for (
unsigned int j = 0; j < res.
getCols(); j++) {
6866 for (
unsigned int k = 0; k <
kernel.getRows(); k++) {
6867 for (
unsigned int l = 0; l <
kernel.getCols(); l++) {
6868 res[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
6876 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
6924 for (
unsigned int j = 0; j <
getCols(); j++)
6925 c[j] = (*
this)[i - 1][j];
6950 for (
unsigned int i = 0; i <
getRows(); i++)
6951 c[i] = (*
this)[i][j - 1];
6963 for (
unsigned int i = 0; i <
rowNum; i++)
6964 for (
unsigned int j = 0; j <
colNum; j++)
6966 (*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.