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 #if defined(VISP_HAVE_SIMDLIB)
62 #include <Simd/SimdLib.h>
65 #ifdef VISP_HAVE_LAPACK
67 #include <gsl/gsl_eigen.h>
68 #include <gsl/gsl_linalg.h>
69 #include <gsl/gsl_math.h>
70 #elif defined(VISP_HAVE_MKL)
72 typedef MKL_INT integer;
74 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
75 double *work_data,
int lwork_,
int &info_)
77 MKL_INT n =
static_cast<MKL_INT
>(n_);
78 MKL_INT lda =
static_cast<MKL_INT
>(lda_);
79 MKL_INT lwork =
static_cast<MKL_INT
>(lwork_);
80 MKL_INT info =
static_cast<MKL_INT
>(info_);
82 dsyev(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
86 #if defined(VISP_HAVE_LAPACK_BUILT_IN)
87 typedef long int integer;
91 extern "C" integer dsyev_(
char *jobz,
char *uplo, integer *n,
double *a, integer *lda,
double *w,
double *WORK,
92 integer *lwork, integer *info);
94 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
double *w_data,
95 double *work_data,
int lwork_,
int &info_)
97 integer n =
static_cast<integer
>(n_);
98 integer lda =
static_cast<integer
>(lda_);
99 integer lwork =
static_cast<integer
>(lwork_);
100 integer info =
static_cast<integer
>(info_);
102 dsyev_(&jobz, &uplo, &n, a_data, &lda, w_data, work_data, &lwork, &info);
104 lwork_ =
static_cast<int>(lwork);
105 info_ =
static_cast<int>(info);
110 #if !defined(VISP_USE_MSVC) || (defined(VISP_USE_MSVC) && !defined(VISP_BUILD_SHARED_LIBS))
111 const unsigned int vpMatrix::m_lapack_min_size_default = 0;
112 unsigned int vpMatrix::m_lapack_min_size = vpMatrix::m_lapack_min_size_default;
119 unsigned int ncols,
double svThreshold,
vpMatrix &Ap,
int &rank_out,
int *rank_in,
122 Ap.
resize(ncols, nrows,
true,
false);
125 double maxsv = sv[0];
129 for (
unsigned int i = 0; i < sv.
size(); i++) {
130 if (sv[i] > maxsv * svThreshold) {
135 unsigned int rank =
static_cast<unsigned int>(rank_out);
137 rank =
static_cast<unsigned int>(*rank_in);
140 for (
unsigned int i = 0; i < ncols; i++) {
141 for (
unsigned int j = 0; j < nrows; j++) {
142 for (
unsigned int k = 0; k < rank; k++) {
143 Ap[i][j] += V[i][k] * U[j][k] / sv[k];
152 for (
unsigned int i = 0; i < nrows; i++) {
153 for (
unsigned int j = 0; j < rank; j++) {
154 (*imA)[i][j] = U[i][j];
161 imAt->
resize(ncols, rank);
162 for (
unsigned int i = 0; i < ncols; i++) {
163 for (
unsigned int j = 0; j < rank; j++) {
164 (*imAt)[i][j] = V[i][j];
171 kerAt->
resize(ncols - rank, ncols);
173 for (
unsigned int k = 0; k < (ncols - rank); k++) {
174 unsigned j = k + rank;
175 for (
unsigned int i = 0; i < V.
getRows(); i++) {
176 (*kerAt)[k][i] = V[i][j];
191 if (((r + nrows) > M.
rowNum) || ((c + ncols) > M.
colNum)) {
193 "Cannot construct a sub matrix (%dx%d) starting at "
194 "position (%d,%d) that is not contained in the "
195 "original matrix (%dx%d)",
199 init(M, r, c, nrows, ncols);
202 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
265 vpMatrix::vpMatrix(
unsigned int nrows,
unsigned int ncols,
const std::initializer_list<double> &list)
340 unsigned int rnrows = r + nrows;
341 unsigned int cncols = c + ncols;
349 resize(nrows, ncols,
false,
false);
351 if (this->
rowPtrs ==
nullptr) {
354 for (
unsigned int i = 0; i < nrows; i++) {
355 memcpy((*
this)[i], &M[i + r][c], ncols *
sizeof(
double));
402 unsigned int rnrows = r + nrows;
403 unsigned int cncols = c + ncols;
413 M.
resize(nrows, ncols,
false,
false);
414 for (
unsigned int i = 0; i < nrows; i++) {
415 memcpy(M[i], &(*
this)[i + r][c], ncols *
sizeof(
double));
444 for (
unsigned int i = 0; i <
rowNum; i++) {
445 for (
unsigned int j = 0; j <
colNum; j++) {
481 for (
unsigned int i = 0; i <
rowNum; i++) {
482 for (
unsigned int j = 0; j <
colNum; j++) {
483 At[j][i] = (*this)[i][j];
488 #if defined(VISP_HAVE_SIMDLIB)
492 const int tileSize = 32;
493 for (
unsigned int i = 0; i <
rowNum; i += tileSize) {
494 for (
unsigned int j = 0; j <
colNum; j++) {
495 for (
unsigned int b = 0; b < static_cast<unsigned int>(tileSize) && i + b <
rowNum; b++) {
496 At[j][i + b] = (*this)[i + b][j];
535 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
536 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
541 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
542 const double alpha = 1.0;
543 const double beta = 0.0;
544 const char transa =
't';
545 const char transb =
'n';
547 vpMatrix::blas_dgemm(transa, transb,
rowNum,
rowNum,
colNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
553 for (
unsigned int i = 0; i <
rowNum; i++) {
554 for (
unsigned int j = i; j <
rowNum; j++) {
560 for (
unsigned int k = 0; k <
colNum; k++)
561 ssum += *(pi++) * *(pj++);
588 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
589 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
594 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
595 const double alpha = 1.0;
596 const double beta = 0.0;
597 const char transa =
'n';
598 const char transb =
't';
600 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
605 for (
unsigned int i = 0; i <
colNum; i++) {
607 for (
unsigned int j = 0; j < i; j++) {
610 for (
unsigned int k = 0; k <
rowNum; k++) {
611 s += (*(ptr + i)) * (*(ptr + j));
619 for (
unsigned int k = 0; k <
rowNum; k++) {
620 s += (*(ptr + i)) * (*(ptr + i));
680 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
683 if (
this != &other) {
699 other.rowPtrs =
nullptr;
701 other.data =
nullptr;
735 if (
dsize !=
static_cast<unsigned int>(list.size())) {
736 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
739 std::copy(list.begin(), list.end(),
data);
769 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
770 for (
auto &l : lists) {
771 if (
static_cast<unsigned int>(l.size()) > ncols) {
772 ncols =
static_cast<unsigned int>(l.size());
776 resize(nrows, ncols,
false,
false);
777 auto it = lists.begin();
778 for (
unsigned int i = 0; i <
rowNum; i++, ++it) {
779 std::copy(it->begin(), it->end(),
rowPtrs[i]);
800 for (
unsigned int i = 0; i <
rowNum; i++) {
801 for (
unsigned int j = 0; j <
colNum; j++) {
810 resize(1, 1,
false,
false);
859 unsigned int rows = A.
getRows();
863 for (
unsigned int i = 0; i < rows; i++)
864 (*
this)[i][i] = A[i];
901 for (
unsigned int i = 0; i < min_; i++)
917 unsigned int rows = A.
getRows();
918 DA.
resize(rows, rows,
true);
920 for (
unsigned int i = 0; i < rows; i++)
937 for (
unsigned int j = 0; j < 3; j++)
940 for (
unsigned int j = 0; j < 3; j++) {
942 for (
unsigned int i = 0; i < 3; i++) {
943 t_out[i] +=
rowPtrs[i][j] * tj;
979 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size);
980 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
985 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
991 vpMatrix::blas_dgemv(trans, A.
colNum, A.
rowNum, alpha, A.
data, A.
colNum, v.
data, incr, beta, w.
data, incr);
996 for (
unsigned int j = 0; j < A.
colNum; j++) {
998 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1029 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1030 B.
colNum > vpMatrix::m_lapack_min_size);
1031 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1036 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1037 const double alpha = 1.0;
1038 const double beta = 0.0;
1039 const char trans =
'n';
1040 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1046 const unsigned int BcolNum = B.
colNum;
1047 const unsigned int BrowNum = B.
rowNum;
1048 double **BrowPtrs = B.
rowPtrs;
1049 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1050 const double *rowptri = A.
rowPtrs[i];
1052 for (
unsigned int j = 0; j < BcolNum; j++) {
1054 for (
unsigned int k = 0; k < BrowNum; k++)
1055 s += rowptri[k] * BrowPtrs[k][j];
1078 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1083 const unsigned int BcolNum = B.
colNum;
1084 const unsigned int BrowNum = B.
rowNum;
1085 double **BrowPtrs = B.
rowPtrs;
1086 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1087 const double *rowptri = A.
rowPtrs[i];
1089 for (
unsigned int j = 0; j < BcolNum; j++) {
1091 for (
unsigned int k = 0; k < BrowNum; k++)
1092 s += rowptri[k] * BrowPtrs[k][j];
1114 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
1123 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size ||
1124 B.
colNum > vpMatrix::m_lapack_min_size);
1125 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1130 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1131 const double alpha = 1.0;
1132 const double beta = 0.0;
1133 const char trans =
'n';
1134 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1140 const unsigned int BcolNum = B.
colNum;
1141 const unsigned int BrowNum = B.
rowNum;
1142 double **BrowPtrs = B.
rowPtrs;
1143 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1144 const double *rowptri = A.
rowPtrs[i];
1146 for (
unsigned int j = 0; j < BcolNum; j++) {
1148 for (
unsigned int k = 0; k < BrowNum; k++)
1149 s += rowptri[k] * BrowPtrs[k][j];
1199 unsigned int RcolNum = R.
getCols();
1200 unsigned int RrowNum = R.
getRows();
1201 for (
unsigned int i = 0; i <
rowNum; i++) {
1204 for (
unsigned int j = 0; j < RcolNum; j++) {
1206 for (
unsigned int k = 0; k < RrowNum; k++)
1207 s += rowptri[k] * R[k][j];
1228 const unsigned int McolNum = M.
getCols();
1229 const unsigned int MrowNum = M.
getRows();
1230 for (
unsigned int i = 0; i <
rowNum; i++) {
1231 const double *rowptri =
rowPtrs[i];
1233 for (
unsigned int j = 0; j < McolNum; j++) {
1235 for (
unsigned int k = 0; k < MrowNum; k++)
1236 s += rowptri[k] * M[k][j];
1262 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1263 V.
colNum > vpMatrix::m_lapack_min_size);
1264 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1269 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1270 const double alpha = 1.0;
1271 const double beta = 0.0;
1272 const char trans =
'n';
1273 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
1278 #if defined(VISP_HAVE_SIMDLIB)
1281 unsigned int VcolNum = V.
getCols();
1282 unsigned int VrowNum = V.
getRows();
1283 for (
unsigned int i = 0; i <
rowNum; i++) {
1286 for (
unsigned int j = 0; j < VcolNum; j++) {
1288 for (
unsigned int k = 0; k < VrowNum; k++)
1289 s += rowptri[k] * V[k][j];
1317 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size ||
1318 V.
getCols() > vpMatrix::m_lapack_min_size);
1319 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
1324 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
1325 const double alpha = 1.0;
1326 const double beta = 0.0;
1327 const char trans =
'n';
1328 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
1333 #if defined(VISP_HAVE_SIMDLIB)
1336 unsigned int VcolNum = V.
getCols();
1337 unsigned int VrowNum = V.
getRows();
1338 for (
unsigned int i = 0; i <
rowNum; i++) {
1341 for (
unsigned int j = 0; j < VcolNum; j++) {
1343 for (
unsigned int k = 0; k < VrowNum; k++)
1344 s += rowptri[k] * V[k][j];
1375 double **ArowPtrs = A.
rowPtrs;
1376 double **BrowPtrs = B.
rowPtrs;
1377 double **CrowPtrs = C.
rowPtrs;
1379 for (
unsigned int i = 0; i < A.
rowNum; i++)
1380 for (
unsigned int j = 0; j < A.
colNum; j++)
1381 CrowPtrs[i][j] = wB * BrowPtrs[i][j] + wA * ArowPtrs[i][j];
1403 double **ArowPtrs = A.
rowPtrs;
1404 double **BrowPtrs = B.
rowPtrs;
1405 double **CrowPtrs = C.
rowPtrs;
1407 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1408 for (
unsigned int j = 0; j < A.
colNum; j++) {
1409 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] = BrowPtrs[i][j] + ArowPtrs[i][j];
1483 double **ArowPtrs = A.
rowPtrs;
1484 double **BrowPtrs = B.
rowPtrs;
1485 double **CrowPtrs = C.
rowPtrs;
1487 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1488 for (
unsigned int j = 0; j < A.
colNum; j++) {
1489 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1516 double **ArowPtrs = A.
rowPtrs;
1517 double **BrowPtrs = B.
rowPtrs;
1518 double **CrowPtrs = C.
rowPtrs;
1520 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1521 for (
unsigned int j = 0; j < A.
colNum; j++) {
1522 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1547 double **BrowPtrs = B.
rowPtrs;
1549 for (
unsigned int i = 0; i <
rowNum; i++)
1550 for (
unsigned int j = 0; j <
colNum; j++)
1551 rowPtrs[i][j] += BrowPtrs[i][j];
1564 double **BrowPtrs = B.
rowPtrs;
1565 for (
unsigned int i = 0; i <
rowNum; i++)
1566 for (
unsigned int j = 0; j <
colNum; j++)
1567 rowPtrs[i][j] -= BrowPtrs[i][j];
1586 double **ArowPtrs = A.
rowPtrs;
1587 double **CrowPtrs = C.
rowPtrs;
1589 for (
unsigned int i = 0; i < A.
rowNum; i++)
1590 for (
unsigned int j = 0; j < A.
colNum; j++)
1591 CrowPtrs[i][j] = -ArowPtrs[i][j];
1608 for (
unsigned int i = 0; i <
rowNum; i++) {
1609 for (
unsigned int j = 0; j <
colNum; j++) {
1631 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1635 unsigned int Brow = B.
getRows();
1636 unsigned int Bcol = B.
getCols();
1639 C.
resize(Brow, Bcol,
false,
false);
1641 for (
unsigned int i = 0; i < Brow; i++)
1642 for (
unsigned int j = 0; j < Bcol; j++)
1643 C[i][j] = B[i][j] * x;
1654 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1661 for (
unsigned int i = 0; i <
rowNum; i++)
1662 for (
unsigned int j = 0; j <
colNum; j++)
1671 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1675 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
1682 double xinv = 1 / x;
1684 for (
unsigned int i = 0; i <
rowNum; i++)
1685 for (
unsigned int j = 0; j <
colNum; j++)
1686 C[i][j] =
rowPtrs[i][j] * xinv;
1694 for (
unsigned int i = 0; i <
rowNum; i++)
1695 for (
unsigned int j = 0; j <
colNum; j++)
1704 for (
unsigned int i = 0; i <
rowNum; i++)
1705 for (
unsigned int j = 0; j <
colNum; j++)
1717 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1721 for (
unsigned int i = 0; i <
rowNum; i++)
1722 for (
unsigned int j = 0; j <
colNum; j++)
1731 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1735 if (std::fabs(x) < std::numeric_limits<double>::epsilon())
1738 double xinv = 1 / x;
1740 for (
unsigned int i = 0; i <
rowNum; i++)
1741 for (
unsigned int j = 0; j <
colNum; j++)
1760 double *optr = out.
data;
1761 for (
unsigned int j = 0; j <
colNum; j++) {
1762 for (
unsigned int i = 0; i <
rowNum; i++) {
1816 #if defined(VISP_HAVE_SIMDLIB)
1819 for (
unsigned int i = 0; i <
dsize; ++i) {
1835 unsigned int r1 = m1.
getRows();
1836 unsigned int c1 = m1.
getCols();
1837 unsigned int r2 = m2.
getRows();
1838 unsigned int c2 = m2.
getCols();
1840 out.
resize(r1 * r2, c1 * c2,
false,
false);
1842 for (
unsigned int r = 0; r < r1; r++) {
1843 for (
unsigned int c = 0; c < c1; c++) {
1844 double alpha = m1[r][c];
1845 double *m2ptr = m2[0];
1846 unsigned int roffset = r * r2;
1847 unsigned int coffset = c * c2;
1848 for (
unsigned int rr = 0; rr < r2; rr++) {
1849 for (
unsigned int cc = 0; cc < c2; cc++) {
1850 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
1873 unsigned int r1 = m1.
getRows();
1874 unsigned int c1 = m1.
getCols();
1875 unsigned int r2 = m2.
getRows();
1876 unsigned int c2 = m2.
getCols();
1879 out.
resize(r1 * r2, c1 * c2,
false,
false);
1881 for (
unsigned int r = 0; r < r1; r++) {
1882 for (
unsigned int c = 0; c < c1; c++) {
1883 double alpha = m1[r][c];
1884 double *m2ptr = m2[0];
1885 unsigned int roffset = r * r2;
1886 unsigned int coffset = c * c2;
1887 for (
unsigned int rr = 0; rr < r2; rr++) {
1888 for (
unsigned int cc = 0; cc < c2; cc++) {
1889 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
2078 #if defined(VISP_HAVE_LAPACK)
2080 #elif defined(VISP_HAVE_EIGEN3)
2082 #elif defined(VISP_HAVE_OPENCV)
2147 #if defined(VISP_HAVE_LAPACK)
2149 #elif defined(VISP_HAVE_EIGEN3)
2151 #elif defined(VISP_HAVE_OPENCV)
2157 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2223 #if defined(VISP_HAVE_LAPACK)
2225 #elif defined(VISP_HAVE_EIGEN3)
2227 #elif defined(VISP_HAVE_OPENCV)
2233 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2289 #if defined(VISP_HAVE_LAPACK)
2291 #elif defined(VISP_HAVE_EIGEN3)
2293 #elif defined(VISP_HAVE_OPENCV)
2298 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2354 #if defined(VISP_HAVE_LAPACK)
2356 #elif defined(VISP_HAVE_EIGEN3)
2358 #elif defined(VISP_HAVE_OPENCV)
2363 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2367 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2368 #if defined(VISP_HAVE_LAPACK)
2407 unsigned int nrows =
getRows();
2408 unsigned int ncols =
getCols();
2417 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
2464 unsigned int nrows =
getRows();
2465 unsigned int ncols =
getCols();
2474 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
2476 return static_cast<unsigned int>(rank_out);
2527 unsigned int nrows =
getRows();
2528 unsigned int ncols =
getCols();
2533 Ap.
resize(ncols, nrows,
false,
false);
2538 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
2540 return static_cast<unsigned int>(rank_out);
2652 unsigned int nrows =
getRows();
2653 unsigned int ncols =
getCols();
2657 if (nrows < ncols) {
2658 U.
resize(ncols, ncols,
true);
2667 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr, &imA, &imAt, &kerAt);
2669 return static_cast<unsigned int>(rank_out);
2710 unsigned int nrows =
getRows();
2711 unsigned int ncols =
getCols();
2713 double svThreshold = 1e-26;
2721 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
2774 unsigned int nrows =
getRows();
2775 unsigned int ncols =
getCols();
2777 double svThreshold = 1e-26;
2785 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
2845 unsigned int nrows =
getRows();
2846 unsigned int ncols =
getCols();
2848 double svThreshold = 1e-26;
2851 Ap.
resize(ncols, nrows,
false,
false);
2856 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
2975 unsigned int nrows =
getRows();
2976 unsigned int ncols =
getCols();
2978 double svThreshold = 1e-26;
2981 if (nrows < ncols) {
2982 U.
resize(ncols, ncols,
true);
2991 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
2997 #if defined(VISP_HAVE_EIGEN3)
3036 unsigned int nrows =
getRows();
3037 unsigned int ncols =
getCols();
3045 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3092 unsigned int nrows =
getRows();
3093 unsigned int ncols =
getCols();
3101 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3103 return static_cast<unsigned int>(rank_out);
3155 unsigned int nrows =
getRows();
3156 unsigned int ncols =
getCols();
3160 Ap.
resize(ncols, nrows,
false,
false);
3165 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3167 return static_cast<unsigned int>(rank_out);
3279 unsigned int nrows =
getRows();
3280 unsigned int ncols =
getCols();
3284 if (nrows < ncols) {
3285 U.
resize(ncols, ncols,
true);
3294 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr, &imA, &imAt, &kerAt);
3296 return static_cast<unsigned int>(rank_out);
3337 unsigned int nrows =
getRows();
3338 unsigned int ncols =
getCols();
3340 double svThreshold = 1e-26;
3347 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
3400 unsigned int nrows =
getRows();
3401 unsigned int ncols =
getCols();
3403 double svThreshold = 1e-26;
3407 Ap.
resize(ncols, nrows,
false,
false);
3412 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
3472 unsigned int nrows =
getRows();
3473 unsigned int ncols =
getCols();
3475 double svThreshold = 1e-26;
3478 Ap.
resize(ncols, nrows,
false,
false);
3483 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
3602 unsigned int nrows =
getRows();
3603 unsigned int ncols =
getCols();
3605 double svThreshold = 1e-26;
3608 if (nrows < ncols) {
3609 U.
resize(ncols, ncols,
true);
3617 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
3623 #if defined(VISP_HAVE_OPENCV)
3662 unsigned int nrows =
getRows();
3663 unsigned int ncols =
getCols();
3671 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3718 unsigned int nrows =
getRows();
3719 unsigned int ncols =
getCols();
3724 Ap.
resize(ncols, nrows,
false,
false);
3729 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3731 return static_cast<unsigned int>(rank_out);
3782 unsigned int nrows =
getRows();
3783 unsigned int ncols =
getCols();
3787 Ap.
resize(ncols, nrows,
false,
false);
3792 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr,
nullptr,
nullptr,
nullptr);
3794 return static_cast<unsigned int>(rank_out);
3906 unsigned int nrows =
getRows();
3907 unsigned int ncols =
getCols();
3911 if (nrows < ncols) {
3912 U.
resize(ncols, ncols,
true);
3921 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out,
nullptr, &imA, &imAt, &kerAt);
3923 return static_cast<unsigned int>(rank_out);
3964 unsigned int nrows =
getRows();
3965 unsigned int ncols =
getCols();
3967 double svThreshold = 1e-26;
3974 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
4027 unsigned int nrows =
getRows();
4028 unsigned int ncols =
getCols();
4030 double svThreshold = 1e-26;
4034 Ap.
resize(ncols, nrows,
false,
false);
4039 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
4099 unsigned int nrows =
getRows();
4100 unsigned int ncols =
getCols();
4102 double svThreshold = 1e-26;
4105 Ap.
resize(ncols, nrows,
false,
false);
4110 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in,
nullptr,
nullptr,
nullptr);
4229 unsigned int nrows =
getRows();
4230 unsigned int ncols =
getCols();
4232 double svThreshold = 1e-26;
4235 if (nrows < ncols) {
4236 U.
resize(ncols, ncols,
true);
4245 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerAt);
4316 #if defined(VISP_HAVE_LAPACK)
4318 #elif defined(VISP_HAVE_EIGEN3)
4320 #elif defined(VISP_HAVE_OPENCV)
4327 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4399 #if defined(VISP_HAVE_LAPACK)
4401 #elif defined(VISP_HAVE_EIGEN3)
4403 #elif defined(VISP_HAVE_OPENCV)
4410 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4490 return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt);
4681 #if defined(VISP_HAVE_LAPACK)
4683 #elif defined(VISP_HAVE_EIGEN3)
4685 #elif defined(VISP_HAVE_OPENCV)
4695 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4808 #if defined(VISP_HAVE_LAPACK)
4810 #elif defined(VISP_HAVE_EIGEN3)
4812 #elif defined(VISP_HAVE_OPENCV)
4822 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4873 for (
unsigned int i = 0; i < column_size; i++)
4874 c[i] = (*
this)[i_begin + i][j];
5002 if (r.
data !=
nullptr &&
data !=
nullptr) {
5003 memcpy(r.
data, (*
this)[i] + j_begin, row_size *
sizeof(
double));
5046 unsigned int min_size = std::min<unsigned int>(
rowNum,
colNum);
5050 diag.resize(min_size,
false);
5052 for (
unsigned int i = 0; i < min_size; i++) {
5053 diag[i] = (*this)[i][i];
5092 unsigned int nra = A.
getRows();
5093 unsigned int nrb = B.
getRows();
5103 std::cerr <<
"A and C must be two different objects!" << std::endl;
5108 std::cerr <<
"B and C must be two different objects!" << std::endl;
5114 if (C.
data !=
nullptr && A.
data !=
nullptr && A.
size() > 0) {
5119 if (C.
data !=
nullptr && B.
data !=
nullptr && B.
size() > 0) {
5156 std::cerr <<
"A and C must be two different objects!" << std::endl;
5195 std::cerr <<
"A and C must be two different objects!" << std::endl;
5280 unsigned int nca = A.
getCols();
5281 unsigned int ncb = B.
getCols();
5290 if (B.
getRows() == 0 || nca + ncb == 0) {
5291 std::cerr <<
"B.getRows() == 0 || nca+ncb == 0" << std::endl;
5326 typedef std::string::size_type size_type;
5331 std::vector<std::string> values(m * n);
5332 std::ostringstream oss;
5333 std::ostringstream ossFixed;
5334 std::ios_base::fmtflags original_flags = oss.flags();
5336 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
5338 size_type maxBefore = 0;
5339 size_type maxAfter = 0;
5341 for (
unsigned int i = 0; i < m; ++i) {
5342 for (
unsigned int j = 0; j < n; ++j) {
5344 oss << (*this)[i][j];
5345 if (oss.str().find(
"e") != std::string::npos) {
5347 ossFixed << (*this)[i][j];
5348 oss.str(ossFixed.str());
5351 values[i * n + j] = oss.str();
5352 size_type thislen = values[i * n + j].size();
5353 size_type p = values[i * n + j].find(
'.');
5355 if (p == std::string::npos) {
5366 size_type totalLength = length;
5370 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
5374 s <<
"[" << m <<
"," << n <<
"]=\n";
5376 for (
unsigned int i = 0; i < m; i++) {
5378 for (
unsigned int j = 0; j < n; j++) {
5379 size_type p = values[i * n + j].find(
'.');
5380 s.setf(std::ios::right, std::ios::adjustfield);
5381 s.width((std::streamsize)maxBefore);
5382 s << values[i * n + j].substr(0, p).c_str();
5385 s.setf(std::ios::left, std::ios::adjustfield);
5386 if (p != std::string::npos) {
5387 s.width((std::streamsize)maxAfter);
5388 s << values[i * n + j].substr(p, maxAfter).c_str();
5391 s.width((std::streamsize)maxAfter);
5401 s.flags(original_flags);
5403 return (
int)(maxBefore + maxAfter);
5445 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5446 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5447 os << (*this)[i][j] <<
", ";
5449 if (this->
getRows() != i + 1) {
5450 os <<
";" << std::endl;
5453 os <<
"]" << std::endl;
5489 os <<
"([ " << std::endl;
5490 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5492 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5493 os << (*this)[i][j] <<
", ";
5495 os <<
"]," << std::endl;
5497 os <<
"])" << std::endl;
5530 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5531 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5532 os << (*this)[i][j];
5533 if (!(j == (this->
getCols() - 1)))
5578 os <<
"vpMatrix " << matrixName <<
" (" << this->
getRows() <<
", " << this->
getCols() <<
"); " << std::endl;
5580 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5581 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5583 os << matrixName <<
"[" << i <<
"][" << j <<
"] = " << (*this)[i][j] <<
"; " << std::endl;
5586 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
5587 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"][" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
5588 << (
unsigned int)((
unsigned char *)&((*this)[i][j]))[k] <<
"; " << std::endl;
5612 unsigned int rowNumOld =
rowNum;
5644 if (r.
size() == 0) {
5648 unsigned int oldSize =
size();
5653 memcpy(
data + oldSize, r.
data,
sizeof(
double) * r.
size());
5685 if (c.
size() == 0) {
5690 unsigned int oldColNum =
colNum;
5695 for (
unsigned int i = 0; i <
rowNum; i++) {
5696 memcpy(
data + i *
colNum, tmp.
data + i * oldColNum,
sizeof(
double) * oldColNum);
5720 for (
unsigned int i = r; i < (r + A.
getRows()); i++) {
5778 for (
unsigned int i = 0; i <
rowNum; i++) {
5779 for (
unsigned int j = 0; j <
rowNum; j++) {
5781 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
5787 #if defined(VISP_HAVE_LAPACK)
5788 #if defined(VISP_HAVE_GSL)
5790 gsl_vector *eval = gsl_vector_alloc(
rowNum);
5793 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
5796 unsigned int Atda = (
unsigned int)m->tda;
5797 for (
unsigned int i = 0; i <
rowNum; i++) {
5798 unsigned int k = i * Atda;
5799 for (
unsigned int j = 0; j <
colNum; j++)
5800 m->data[k + j] = (*
this)[i][j];
5802 gsl_eigen_symmv(m, eval, evec, w);
5804 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
5806 for (
unsigned int i = 0; i <
rowNum; i++) {
5807 evalue[i] = gsl_vector_get(eval, i);
5810 gsl_eigen_symmv_free(w);
5811 gsl_vector_free(eval);
5813 gsl_matrix_free(evec);
5817 const char jobz =
'N';
5818 const char uplo =
'U';
5825 lwork =
static_cast<int>(wkopt);
5833 "You should install Lapack 3rd party"));
5897 for (
unsigned int i = 0; i <
rowNum; i++) {
5898 for (
unsigned int j = 0; j <
rowNum; j++) {
5900 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
5910 #if defined(VISP_HAVE_LAPACK)
5911 #if defined(VISP_HAVE_GSL)
5913 gsl_vector *eval = gsl_vector_alloc(
rowNum);
5916 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(
rowNum);
5919 unsigned int Atda = (
unsigned int)m->tda;
5920 for (
unsigned int i = 0; i <
rowNum; i++) {
5921 unsigned int k = i * Atda;
5922 for (
unsigned int j = 0; j <
colNum; j++)
5923 m->data[k + j] = (*
this)[i][j];
5925 gsl_eigen_symmv(m, eval, evec, w);
5927 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
5929 for (
unsigned int i = 0; i <
rowNum; i++) {
5930 evalue[i] = gsl_vector_get(eval, i);
5932 Atda = (
unsigned int)evec->tda;
5933 for (
unsigned int i = 0; i <
rowNum; i++) {
5934 unsigned int k = i * Atda;
5935 for (
unsigned int j = 0; j <
rowNum; j++) {
5936 evector[i][j] = evec->
data[k + j];
5940 gsl_eigen_symmv_free(w);
5941 gsl_vector_free(eval);
5943 gsl_matrix_free(evec);
5947 const char jobz =
'V';
5948 const char uplo =
'U';
5955 lwork =
static_cast<int>(wkopt);
5964 "You should install Lapack 3rd party"));
5989 unsigned int nbline =
getRows();
5990 unsigned int nbcol =
getCols();
5995 V.
resize(nbcol, nbcol,
false);
6002 U.
resize(nbcol, nbcol,
true);
6004 U.
resize(nbline, nbcol,
false);
6012 for (
unsigned int i = 0; i < nbcol; i++) {
6013 if (sv[i] > maxsv) {
6018 unsigned int rank = 0;
6019 for (
unsigned int i = 0; i < nbcol; i++) {
6020 if (sv[i] > maxsv * svThreshold) {
6025 kerAt.
resize(nbcol - rank, nbcol);
6026 if (rank != nbcol) {
6027 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6029 if ((sv[j] <= maxsv * svThreshold) &&
6030 (std::fabs(V.
getCol(j).
sumSquare()) > std::numeric_limits<double>::epsilon())) {
6031 for (
unsigned int i = 0; i < V.
getRows(); i++) {
6032 kerAt[k][i] = V[i][j];
6060 unsigned int nbrow =
getRows();
6061 unsigned int nbcol =
getCols();
6066 V.
resize(nbcol, nbcol,
false);
6073 U.
resize(nbcol, nbcol,
true);
6075 U.
resize(nbrow, nbcol,
false);
6082 double maxsv = sv[0];
6084 unsigned int rank = 0;
6085 for (
unsigned int i = 0; i < nbcol; i++) {
6086 if (sv[i] > maxsv * svThreshold) {
6091 kerA.
resize(nbcol, nbcol - rank);
6092 if (rank != nbcol) {
6093 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6095 if (sv[j] <= maxsv * svThreshold) {
6096 for (
unsigned int i = 0; i < nbcol; i++) {
6097 kerA[i][k] = V[i][j];
6104 return (nbcol - rank);
6125 unsigned int nbrow =
getRows();
6126 unsigned int nbcol =
getCols();
6127 unsigned int dim_ =
static_cast<unsigned int>(dim);
6132 V.
resize(nbcol, nbcol,
false);
6139 U.
resize(nbcol, nbcol,
true);
6141 U.
resize(nbrow, nbcol,
false);
6147 kerA.
resize(nbcol, dim_);
6149 unsigned int rank = nbcol - dim_;
6150 for (
unsigned int k = 0; k < dim_; k++) {
6151 unsigned int j = k + rank;
6152 for (
unsigned int i = 0; i < nbcol; i++) {
6153 kerA[i][k] = V[i][j];
6158 double maxsv = sv[0];
6159 unsigned int rank = 0;
6160 for (
unsigned int i = 0; i < nbcol; i++) {
6161 if (sv[i] > maxsv * 1e-6) {
6165 return (nbcol - rank);
6224 #ifdef VISP_HAVE_GSL
6226 double *b =
new double[size_];
6227 for (
size_t i = 0; i < size_; i++)
6229 gsl_matrix_view m = gsl_matrix_view_array(this->
data,
rowNum, colNum);
6230 gsl_matrix_view em = gsl_matrix_view_array(b,
rowNum,
colNum);
6231 gsl_linalg_exponential_ss(&m.matrix, &em.matrix, 0);
6235 memcpy(expA.
data, b, size_ *
sizeof(
double));
6256 for (
unsigned int i = 0; i <
rowNum; i++) {
6258 for (
unsigned int j = 0; j <
colNum; j++) {
6259 sum += fabs((*
this)[i][j]);
6261 if (
sum > nA || i == 0) {
6270 double sca = 1.0 / pow(2.0, s);
6273 _expE = c * exp + _eye;
6274 _expD = -c * exp + _eye;
6275 for (
int k = 2; k <= q; k++) {
6276 c = c * ((double)(q - k + 1)) / ((
double)(k * (2 * q - k + 1)));
6277 _expcX = exp * _expX;
6280 _expE = _expE + _expcX;
6282 _expD = _expD + _expcX;
6284 _expD = _expD - _expcX;
6288 exp = _expX * _expE;
6289 for (
int k = 1; k <= s; k++) {
6322 for (
unsigned int i = 0; i < col; i++) {
6323 for (
unsigned int j = 0; j < row; j++)
6324 M_comp[i][j] = M[i][j];
6325 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6326 M_comp[i][j - 1] = M[i][j];
6328 for (
unsigned int i = col + 1; i < M.
getCols(); i++) {
6329 for (
unsigned int j = 0; j < row; j++)
6330 M_comp[i - 1][j] = M[i][j];
6331 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6332 M_comp[i - 1][j - 1] = M[i][j];
6348 unsigned int nbline =
getRows();
6349 unsigned int nbcol =
getCols();
6354 V.
resize(nbcol, nbcol,
false);
6361 U.
resize(nbcol, nbcol,
true);
6363 U.
resize(nbline, nbcol,
false);
6371 for (
unsigned int i = 0; i < nbcol; i++) {
6372 if (sv[i] > maxsv) {
6378 unsigned int rank = 0;
6379 for (
unsigned int i = 0; i < nbcol; i++) {
6380 if (sv[i] > maxsv * svThreshold) {
6386 double minsv = maxsv;
6387 for (
unsigned int i = 0; i < rank; i++) {
6388 if (sv[i] < minsv) {
6393 if (std::fabs(minsv) > std::numeric_limits<double>::epsilon()) {
6394 return maxsv / minsv;
6397 return std::numeric_limits<double>::infinity();
6415 for (
unsigned int i = 0; i < H.
getCols(); i++) {
6416 HLM[i][i] += alpha * H[i][i];
6430 for (
unsigned int i = 0; i <
dsize; i++) {
6431 double x = *(
data + i);
6448 if (this->
dsize != 0) {
6457 unsigned int maxRank = std::min<unsigned int>(this->
getCols(), this->
getRows());
6460 unsigned int boundary = std::min<unsigned int>(maxRank, w.
size());
6465 for (
unsigned int i = 0; i < boundary; i++) {
6490 for (
unsigned int i = 0; i <
rowNum; i++) {
6492 for (
unsigned int j = 0; j <
colNum; j++) {
6493 x += fabs(*(*(
rowPtrs + i) + j));
6510 double sum_square = 0.0;
6513 for (
unsigned int i = 0; i <
rowNum; i++) {
6514 for (
unsigned int j = 0; j <
colNum; j++) {
6516 sum_square += x * x;
6522 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
6570 for (
unsigned int j = 0; j <
getCols(); j++)
6571 c[j] = (*
this)[i - 1][j];
6596 for (
unsigned int i = 0; i <
getRows(); i++)
6597 c[i] = (*
this)[i][j - 1];
6609 for (
unsigned int i = 0; i <
rowNum; i++)
6610 for (
unsigned int j = 0; j <
colNum; j++)
6612 (*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.