55 #include <visp3/core/vpConfig.h> 56 #include <visp3/core/vpCPUFeatures.h> 57 #include <visp3/core/vpColVector.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_math.h> 70 # include <gsl/gsl_linalg.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_,
76 double *w_data,
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,
93 double *w,
double *WORK, integer *lwork, integer *info);
95 void vpMatrix::blas_dsyev(
char jobz,
char uplo,
unsigned int n_,
double *a_data,
unsigned int lda_,
96 double *w_data,
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,
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) 271 vpMatrix::vpMatrix(
unsigned int nrows,
unsigned int ncols,
const std::initializer_list<double> &list)
272 :
vpArray2D<double>(nrows, ncols, list) {}
348 unsigned int rnrows = r + nrows;
349 unsigned int cncols = c + ncols;
357 resize(nrows, ncols,
false,
false);
361 for (
unsigned int i = 0; i < nrows; i++) {
362 memcpy((*
this)[i], &M[i + r][c], ncols *
sizeof(
double));
409 unsigned int rnrows = r + nrows;
410 unsigned int cncols = c + ncols;
420 M.
resize(nrows, ncols,
false,
false);
421 for (
unsigned int i = 0; i < nrows; i++) {
422 memcpy(M[i], &(*
this)[i + r][c], ncols *
sizeof(
double));
451 for (
unsigned int i = 0; i <
rowNum; i++) {
452 for (
unsigned int j = 0; j <
colNum; j++) {
491 for (
unsigned int i = 0; i <
rowNum; i++) {
492 for (
unsigned int j = 0; j <
colNum; j++) {
493 At[j][i] = (*this)[i][j];
533 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
534 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 539 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 540 const double alpha = 1.0;
541 const double beta = 0.0;
542 const char transa =
't';
543 const char transb =
'n';
545 vpMatrix::blas_dgemm(transa, transb,
rowNum,
rowNum,
colNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
rowNum);
550 for (
unsigned int i = 0; i <
rowNum; i++) {
551 for (
unsigned int j = i; j <
rowNum; j++) {
557 for (
unsigned int k = 0; k <
colNum; k++)
558 ssum += *(pi++) * *(pj++);
585 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size);
586 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 591 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 592 const double alpha = 1.0;
593 const double beta = 0.0;
594 const char transa =
'n';
595 const char transb =
't';
597 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
colNum);
601 for (
unsigned int i = 0; i <
colNum; i++) {
603 for (
unsigned int j = 0; j < i; j++) {
606 for (
unsigned int k = 0; k <
rowNum; k++) {
607 s += (*(ptr + i)) * (*(ptr + j));
615 for (
unsigned int k = 0; k <
rowNum; k++) {
616 s += (*(ptr + i)) * (*(ptr + i));
665 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 679 if (
this != &other) {
691 other.rowPtrs = NULL;
725 if (
dsize != static_cast<unsigned int>(list.size())) {
726 resize(1, static_cast<unsigned int>(list.size()),
false,
false);
729 std::copy(list.begin(), list.end(),
data);
759 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
760 for (
auto& l : lists) {
761 if (static_cast<unsigned int>(l.size()) > ncols) {
762 ncols =
static_cast<unsigned int>(l.size());
766 resize(nrows, ncols,
false,
false);
767 auto it = lists.begin();
768 for (
unsigned int i = 0; i <
rowNum; i++, ++it) {
769 std::copy(it->begin(), it->end(),
rowPtrs[i]);
790 for (
unsigned int i = 0; i <
rowNum; i++) {
791 for (
unsigned int j = 0; j <
colNum; j++) {
800 resize(1, 1,
false,
false);
849 unsigned int rows = A.
getRows();
853 for (
unsigned int i = 0; i < rows; i++)
854 (*
this)[i][i] = A[i];
891 for (
unsigned int i = 0; i < min_; i++)
908 unsigned int rows = A.
getRows();
909 DA.
resize(rows, rows,
true);
911 for (
unsigned int i = 0; i < rows; i++)
928 for (
unsigned int j = 0; j < 3; j++)
931 for (
unsigned int j = 0; j < 3; j++) {
933 for (
unsigned int i = 0; i < 3; i++) {
934 t_out[i] +=
rowPtrs[i][j] * tj;
970 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size);
971 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 976 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 982 vpMatrix::blas_dgemv(trans, A.
colNum, A.
rowNum, alpha, A.
data, A.
colNum, v.
data, incr, beta, w.
data, incr);
987 for (
unsigned int j = 0; j < A.
colNum; j++) {
989 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1020 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size || B.
colNum > vpMatrix::m_lapack_min_size);
1021 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 1026 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 1027 const double alpha = 1.0;
1028 const double beta = 0.0;
1029 const char trans =
'n';
1030 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1036 const unsigned int BcolNum = B.
colNum;
1037 const unsigned int BrowNum = B.
rowNum;
1038 double **BrowPtrs = B.
rowPtrs;
1039 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1040 const double *rowptri = A.
rowPtrs[i];
1042 for (
unsigned int j = 0; j < BcolNum; j++) {
1044 for (
unsigned int k = 0; k < BrowNum; k++)
1045 s += rowptri[k] * BrowPtrs[k][j];
1069 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " 1074 const unsigned int BcolNum = B.
colNum;
1075 const unsigned int BrowNum = B.
rowNum;
1076 double **BrowPtrs = B.
rowPtrs;
1077 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1078 const double *rowptri = A.
rowPtrs[i];
1080 for (
unsigned int j = 0; j < BcolNum; j++) {
1082 for (
unsigned int k = 0; k < BrowNum; k++)
1083 s += rowptri[k] * BrowPtrs[k][j];
1106 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " 1115 bool useLapack = (A.
rowNum > vpMatrix::m_lapack_min_size || A.
colNum > vpMatrix::m_lapack_min_size || B.
colNum > vpMatrix::m_lapack_min_size);
1116 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 1121 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 1122 const double alpha = 1.0;
1123 const double beta = 0.0;
1124 const char trans =
'n';
1125 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
1131 const unsigned int BcolNum = B.
colNum;
1132 const unsigned int BrowNum = B.
rowNum;
1133 double **BrowPtrs = B.
rowPtrs;
1134 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1135 const double *rowptri = A.
rowPtrs[i];
1137 for (
unsigned int j = 0; j < BcolNum; j++) {
1139 for (
unsigned int k = 0; k < BrowNum; k++)
1140 s += rowptri[k] * BrowPtrs[k][j];
1190 unsigned int RcolNum = R.
getCols();
1191 unsigned int RrowNum = R.
getRows();
1192 for (
unsigned int i = 0; i <
rowNum; i++) {
1195 for (
unsigned int j = 0; j < RcolNum; j++) {
1197 for (
unsigned int k = 0; k < RrowNum; k++)
1198 s += rowptri[k] * R[k][j];
1219 const unsigned int McolNum = M.
getCols();
1220 const unsigned int MrowNum = M.
getRows();
1221 for (
unsigned int i = 0; i <
rowNum; i++) {
1222 const double *rowptri =
rowPtrs[i];
1224 for (
unsigned int j = 0; j < McolNum; j++) {
1226 for (
unsigned int k = 0; k < MrowNum; k++)
1227 s += rowptri[k] * M[k][j];
1253 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size || V.
colNum > vpMatrix::m_lapack_min_size);
1254 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 1259 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 1260 const double alpha = 1.0;
1261 const double beta = 0.0;
1262 const char trans =
'n';
1263 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta,
1292 bool useLapack = (
rowNum > vpMatrix::m_lapack_min_size ||
colNum > vpMatrix::m_lapack_min_size || V.
getCols() > vpMatrix::m_lapack_min_size);
1293 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)) 1298 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL) 1299 const double alpha = 1.0;
1300 const double beta = 0.0;
1301 const char trans =
'n';
1302 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
1334 double **ArowPtrs = A.
rowPtrs;
1335 double **BrowPtrs = B.
rowPtrs;
1336 double **CrowPtrs = C.
rowPtrs;
1338 for (
unsigned int i = 0; i < A.
rowNum; i++)
1339 for (
unsigned int j = 0; j < A.
colNum; j++)
1340 CrowPtrs[i][j] = wB * BrowPtrs[i][j] + wA * ArowPtrs[i][j];
1362 double **ArowPtrs = A.
rowPtrs;
1363 double **BrowPtrs = B.
rowPtrs;
1364 double **CrowPtrs = C.
rowPtrs;
1366 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1367 for (
unsigned int j = 0; j < A.
colNum; j++) {
1368 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1395 double **ArowPtrs = A.
rowPtrs;
1396 double **BrowPtrs = B.
rowPtrs;
1397 double **CrowPtrs = C.
rowPtrs;
1399 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1400 for (
unsigned int j = 0; j < A.
colNum; j++) {
1401 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
1442 double **ArowPtrs = A.
rowPtrs;
1443 double **BrowPtrs = B.
rowPtrs;
1444 double **CrowPtrs = C.
rowPtrs;
1446 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1447 for (
unsigned int j = 0; j < A.
colNum; j++) {
1448 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1475 double **ArowPtrs = A.
rowPtrs;
1476 double **BrowPtrs = B.
rowPtrs;
1477 double **CrowPtrs = C.
rowPtrs;
1479 for (
unsigned int i = 0; i < A.
rowNum; i++) {
1480 for (
unsigned int j = 0; j < A.
colNum; j++) {
1481 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
1506 double **BrowPtrs = B.
rowPtrs;
1508 for (
unsigned int i = 0; i <
rowNum; i++)
1509 for (
unsigned int j = 0; j <
colNum; j++)
1510 rowPtrs[i][j] += BrowPtrs[i][j];
1523 double **BrowPtrs = B.
rowPtrs;
1524 for (
unsigned int i = 0; i <
rowNum; i++)
1525 for (
unsigned int j = 0; j <
colNum; j++)
1526 rowPtrs[i][j] -= BrowPtrs[i][j];
1545 double **ArowPtrs = A.
rowPtrs;
1546 double **CrowPtrs = C.
rowPtrs;
1549 for (
unsigned int i = 0; i < A.
rowNum; i++)
1550 for (
unsigned int j = 0; j < A.
colNum; j++)
1551 CrowPtrs[i][j] = -ArowPtrs[i][j];
1568 for (
unsigned int i = 0; i <
rowNum; i++) {
1569 for (
unsigned int j = 0; j <
colNum; j++) {
1591 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1595 unsigned int Brow = B.
getRows();
1596 unsigned int Bcol = B.
getCols();
1599 C.
resize(Brow, Bcol,
false,
false);
1601 for (
unsigned int i = 0; i < Brow; i++)
1602 for (
unsigned int j = 0; j < Bcol; j++)
1603 C[i][j] = B[i][j] * x;
1614 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1621 for (
unsigned int i = 0; i <
rowNum; i++)
1622 for (
unsigned int j = 0; j <
colNum; j++)
1631 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1635 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
1642 double xinv = 1 / x;
1644 for (
unsigned int i = 0; i <
rowNum; i++)
1645 for (
unsigned int j = 0; j <
colNum; j++)
1646 C[i][j] =
rowPtrs[i][j] * xinv;
1654 for (
unsigned int i = 0; i <
rowNum; i++)
1655 for (
unsigned int j = 0; j <
colNum; j++)
1664 for (
unsigned int i = 0; i <
rowNum; i++)
1665 for (
unsigned int j = 0; j <
colNum; j++)
1677 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1681 for (
unsigned int i = 0; i <
rowNum; i++)
1682 for (
unsigned int j = 0; j <
colNum; j++)
1691 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
1695 if (std::fabs(x) < std::numeric_limits<double>::epsilon())
1698 double xinv = 1 / x;
1700 for (
unsigned int i = 0; i <
rowNum; i++)
1701 for (
unsigned int j = 0; j <
colNum; j++)
1720 double *optr = out.
data;
1721 for (
unsigned int j = 0; j <
colNum; j++) {
1722 for (
unsigned int i = 0; i <
rowNum; i++) {
1789 unsigned int r1 = m1.
getRows();
1790 unsigned int c1 = m1.
getCols();
1791 unsigned int r2 = m2.
getRows();
1792 unsigned int c2 = m2.
getCols();
1794 out.
resize(r1*r2, c1*c2,
false,
false);
1796 for (
unsigned int r = 0; r < r1; r++) {
1797 for (
unsigned int c = 0; c < c1; c++) {
1798 double alpha = m1[r][c];
1799 double *m2ptr = m2[0];
1800 unsigned int roffset = r * r2;
1801 unsigned int coffset = c * c2;
1802 for (
unsigned int rr = 0; rr < r2; rr++) {
1803 for (
unsigned int cc = 0; cc < c2; cc++) {
1804 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
1827 unsigned int r1 = m1.
getRows();
1828 unsigned int c1 = m1.
getCols();
1829 unsigned int r2 = m2.
getRows();
1830 unsigned int c2 = m2.
getCols();
1833 out.
resize(r1 * r2, c1 * c2,
false,
false);
1835 for (
unsigned int r = 0; r < r1; r++) {
1836 for (
unsigned int c = 0; c < c1; c++) {
1837 double alpha = m1[r][c];
1838 double *m2ptr = m2[0];
1839 unsigned int roffset = r * r2;
1840 unsigned int coffset = c * c2;
1841 for (
unsigned int rr = 0; rr < r2; rr++) {
1842 for (
unsigned int cc = 0; cc < c2; cc++) {
1843 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
2032 #if defined(VISP_HAVE_LAPACK) 2034 #elif defined(VISP_HAVE_EIGEN3) 2036 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 2101 #if defined(VISP_HAVE_LAPACK) 2103 #elif defined(VISP_HAVE_EIGEN3) 2105 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 2111 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2177 #if defined(VISP_HAVE_LAPACK) 2179 #elif defined(VISP_HAVE_EIGEN3) 2181 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 2187 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2243 #if defined(VISP_HAVE_LAPACK) 2245 #elif defined(VISP_HAVE_EIGEN3) 2247 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 2252 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2308 #if defined(VISP_HAVE_LAPACK) 2310 #elif defined(VISP_HAVE_EIGEN3) 2312 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 2317 "Install Lapack, Eigen3 or OpenCV 3rd party"));
2321 #ifndef DOXYGEN_SHOULD_SKIP_THIS 2322 #if defined(VISP_HAVE_LAPACK) 2361 unsigned int nrows =
getRows();
2362 unsigned int ncols =
getCols();
2368 Ap.
resize(ncols, nrows,
false,
false);
2370 if (nrows < ncols) {
2371 U.
resize(ncols, ncols,
true);
2374 U.
resize(nrows, ncols,
false);
2381 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2428 unsigned int nrows =
getRows();
2429 unsigned int ncols =
getCols();
2435 Ap.
resize(ncols, nrows,
false,
false);
2437 if (nrows < ncols) {
2438 U.
resize(ncols, ncols,
true);
2441 U.
resize(nrows, ncols,
false);
2448 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2450 return static_cast<unsigned int>(rank_out);
2501 unsigned int nrows =
getRows();
2502 unsigned int ncols =
getCols();
2508 Ap.
resize(ncols, nrows,
false,
false);
2510 if (nrows < ncols) {
2511 U.
resize(ncols, ncols,
true);
2514 U.
resize(nrows, ncols,
false);
2521 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
2527 return static_cast<unsigned int>(rank_out);
2639 unsigned int nrows =
getRows();
2640 unsigned int ncols =
getCols();
2645 if (nrows < ncols) {
2646 U.
resize(ncols, ncols,
true);
2649 U.
resize(nrows, ncols,
false);
2656 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerA);
2662 return static_cast<unsigned int>(rank_out);
2707 unsigned int nrows =
getRows();
2708 unsigned int ncols =
getCols();
2710 double svThreshold = 1e-26;
2715 Ap.
resize(ncols, nrows,
false,
false);
2717 if (nrows < ncols) {
2718 U.
resize(ncols, ncols,
true);
2721 U.
resize(nrows, ncols,
false);
2728 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2781 unsigned int nrows =
getRows();
2782 unsigned int ncols =
getCols();
2784 double svThreshold = 1e-26;
2789 Ap.
resize(ncols, nrows,
false,
false);
2791 if (nrows < ncols) {
2792 U.
resize(ncols, ncols,
true);
2795 U.
resize(nrows, ncols,
false);
2802 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
2862 unsigned int nrows =
getRows();
2863 unsigned int ncols =
getCols();
2865 double svThreshold = 1e-26;
2870 Ap.
resize(ncols, nrows,
false,
false);
2872 if (nrows < ncols) {
2873 U.
resize(ncols, ncols,
true);
2876 U.
resize(nrows, ncols,
false);
2883 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3006 unsigned int nrows =
getRows();
3007 unsigned int ncols =
getCols();
3009 double svThreshold = 1e-26;
3013 if (nrows < ncols) {
3014 U.
resize(ncols, ncols,
true);
3017 U.
resize(nrows, ncols,
false);
3024 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerA);
3034 #if defined(VISP_HAVE_EIGEN3) 3073 unsigned int nrows =
getRows();
3074 unsigned int ncols =
getCols();
3080 Ap.
resize(ncols, nrows,
false,
false);
3082 if (nrows < ncols) {
3083 U.
resize(ncols, ncols,
true);
3086 U.
resize(nrows, ncols,
false);
3093 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3140 unsigned int nrows =
getRows();
3141 unsigned int ncols =
getCols();
3147 Ap.
resize(ncols, nrows,
false,
false);
3149 if (nrows < ncols) {
3150 U.
resize(ncols, ncols,
true);
3153 U.
resize(nrows, ncols,
false);
3160 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3162 return static_cast<unsigned int>(rank_out);
3213 unsigned int nrows =
getRows();
3214 unsigned int ncols =
getCols();
3220 Ap.
resize(ncols, nrows,
false,
false);
3222 if (nrows < ncols) {
3223 U.
resize(ncols, ncols,
true);
3226 U.
resize(nrows, ncols,
false);
3233 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3239 return static_cast<unsigned int>(rank_out);
3351 unsigned int nrows =
getRows();
3352 unsigned int ncols =
getCols();
3357 if (nrows < ncols) {
3358 U.
resize(ncols, ncols,
true);
3361 U.
resize(nrows, ncols,
false);
3368 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerA);
3374 return static_cast<unsigned int>(rank_out);
3419 unsigned int nrows =
getRows();
3420 unsigned int ncols =
getCols();
3422 double svThreshold = 1e-26;
3427 Ap.
resize(ncols, nrows,
false,
false);
3429 if (nrows < ncols) {
3430 U.
resize(ncols, ncols,
true);
3433 U.
resize(nrows, ncols,
false);
3440 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3493 unsigned int nrows =
getRows();
3494 unsigned int ncols =
getCols();
3496 double svThreshold = 1e-26;
3501 Ap.
resize(ncols, nrows,
false,
false);
3503 if (nrows < ncols) {
3504 U.
resize(ncols, ncols,
true);
3507 U.
resize(nrows, ncols,
false);
3514 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3574 unsigned int nrows =
getRows();
3575 unsigned int ncols =
getCols();
3577 double svThreshold = 1e-26;
3582 Ap.
resize(ncols, nrows,
false,
false);
3584 if (nrows < ncols) {
3585 U.
resize(ncols, ncols,
true);
3588 U.
resize(nrows, ncols,
false);
3595 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
3718 unsigned int nrows =
getRows();
3719 unsigned int ncols =
getCols();
3721 double svThreshold = 1e-26;
3725 if (nrows < ncols) {
3726 U.
resize(ncols, ncols,
true);
3729 U.
resize(nrows, ncols,
false);
3736 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerA);
3746 #if (VISP_HAVE_OPENCV_VERSION >= 0x020101) 3785 unsigned int nrows =
getRows();
3786 unsigned int ncols =
getCols();
3792 Ap.
resize(ncols, nrows,
false,
false);
3794 if (nrows < ncols) {
3795 U.
resize(ncols, ncols,
true);
3798 U.
resize(nrows, ncols,
false);
3805 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3852 unsigned int nrows =
getRows();
3853 unsigned int ncols =
getCols();
3859 Ap.
resize(ncols, nrows,
false,
false);
3861 if (nrows < ncols) {
3862 U.
resize(ncols, ncols,
true);
3865 U.
resize(nrows, ncols,
false);
3872 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3874 return static_cast<unsigned int>(rank_out);
3925 unsigned int nrows =
getRows();
3926 unsigned int ncols =
getCols();
3932 Ap.
resize(ncols, nrows,
false,
false);
3934 if (nrows < ncols) {
3935 U.
resize(ncols, ncols,
true);
3938 U.
resize(nrows, ncols,
false);
3945 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, NULL, NULL, NULL);
3951 return static_cast<unsigned int>(rank_out);
4063 unsigned int nrows =
getRows();
4064 unsigned int ncols =
getCols();
4069 if (nrows < ncols) {
4070 U.
resize(ncols, ncols,
true);
4073 U.
resize(nrows, ncols,
false);
4080 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, NULL, &imA, &imAt, &kerA);
4086 return static_cast<unsigned int>(rank_out);
4131 unsigned int nrows =
getRows();
4132 unsigned int ncols =
getCols();
4134 double svThreshold = 1e-26;
4139 Ap.
resize(ncols, nrows,
false,
false);
4141 if (nrows < ncols) {
4142 U.
resize(ncols, ncols,
true);
4145 U.
resize(nrows, ncols,
false);
4152 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4205 unsigned int nrows =
getRows();
4206 unsigned int ncols =
getCols();
4208 double svThreshold = 1e-26;
4213 Ap.
resize(ncols, nrows,
false,
false);
4215 if (nrows < ncols) {
4216 U.
resize(ncols, ncols,
true);
4219 U.
resize(nrows, ncols,
false);
4226 compute_pseudo_inverse(U, sv, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4286 unsigned int nrows =
getRows();
4287 unsigned int ncols =
getCols();
4289 double svThreshold = 1e-26;
4294 Ap.
resize(ncols, nrows,
false,
false);
4296 if (nrows < ncols) {
4297 U.
resize(ncols, ncols,
true);
4300 U.
resize(nrows, ncols,
false);
4307 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, NULL, NULL, NULL);
4430 unsigned int nrows =
getRows();
4431 unsigned int ncols =
getCols();
4433 double svThreshold = 1e-26;
4437 if (nrows < ncols) {
4438 U.
resize(ncols, ncols,
true);
4441 U.
resize(nrows, ncols,
false);
4448 compute_pseudo_inverse(U, sv_, V, nrows, ncols, svThreshold, Ap, rank_out, &rank_in, &imA, &imAt, &kerA);
4458 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 4523 #if defined(VISP_HAVE_LAPACK) 4525 #elif defined(VISP_HAVE_EIGEN3) 4527 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 4534 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4606 #if defined(VISP_HAVE_LAPACK) 4608 #elif defined(VISP_HAVE_EIGEN3) 4610 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 4617 "Install Lapack, Eigen3 or OpenCV 3rd party"));
4697 return pseudoInverse(Ap, sv, svThreshold, imA, imAt, kerAt);
4920 #if defined(VISP_HAVE_LAPACK) 4922 #elif defined(VISP_HAVE_EIGEN3) 4924 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 4934 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5079 #if defined(VISP_HAVE_LAPACK) 5081 #elif defined(VISP_HAVE_EIGEN3) 5083 #elif (VISP_HAVE_OPENCV_VERSION >= 0x020101) // Require opencv >= 2.1.1 5093 "Install Lapack, Eigen3 or OpenCV 3rd party"));
5143 for (
unsigned int i = 0; i < column_size; i++)
5144 c[i] = (*
this)[i_begin + i][j];
5277 if (r.
data != NULL &&
data != NULL) {
5278 memcpy(r.
data, (*
this)[i] + j_begin, row_size*
sizeof(
double));
5325 diag.
resize(min_size,
false);
5327 for (
unsigned int i = 0; i < min_size; i++) {
5328 diag[i] = (*this)[i][i];
5367 unsigned int nra = A.
getRows();
5368 unsigned int nrb = B.
getRows();
5378 std::cerr <<
"A and C must be two different objects!" << std::endl;
5383 std::cerr <<
"B and C must be two different objects!" << std::endl;
5389 if (C.
data != NULL && A.
data != NULL && A.
size() > 0) {
5394 if (C.
data != NULL && B.
data != NULL && B.
size() > 0) {
5431 std::cerr <<
"A and C must be two different objects!" << std::endl;
5470 std::cerr <<
"A and C must be two different objects!" << std::endl;
5517 for (
unsigned int i = 0; i < A.
getRows(); i++) {
5518 for (
unsigned int j = 0; j < A.
getCols(); j++) {
5519 if (i >= r && i < (r + B.
getRows()) && j >= c && j < (c + B.
getCols())) {
5520 C[i][j] = B[i - r][j - c];
5566 unsigned int nca = A.
getCols();
5567 unsigned int ncb = B.
getCols();
5576 if (B.
getRows() == 0 || nca + ncb == 0) {
5577 std::cerr <<
"B.getRows() == 0 || nca+ncb == 0" << std::endl;
5612 typedef std::string::size_type size_type;
5617 std::vector<std::string> values(m * n);
5618 std::ostringstream oss;
5619 std::ostringstream ossFixed;
5620 std::ios_base::fmtflags original_flags = oss.flags();
5623 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
5625 size_type maxBefore = 0;
5626 size_type maxAfter = 0;
5628 for (
unsigned int i = 0; i < m; ++i) {
5629 for (
unsigned int j = 0; j < n; ++j) {
5631 oss << (*this)[i][j];
5632 if (oss.str().find(
"e") != std::string::npos) {
5634 ossFixed << (*this)[i][j];
5635 oss.str(ossFixed.str());
5638 values[i * n + j] = oss.str();
5639 size_type thislen = values[i * n + j].size();
5640 size_type p = values[i * n + j].find(
'.');
5642 if (p == std::string::npos) {
5652 size_type totalLength = length;
5656 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
5663 if (! intro.empty())
5665 s <<
"[" << m <<
"," << n <<
"]=\n";
5667 for (
unsigned int i = 0; i < m; i++) {
5669 for (
unsigned int j = 0; j < n; j++) {
5670 size_type p = values[i * n + j].find(
'.');
5671 s.setf(std::ios::right, std::ios::adjustfield);
5672 s.width((std::streamsize)maxBefore);
5673 s << values[i * n + j].substr(0, p).c_str();
5676 s.setf(std::ios::left, std::ios::adjustfield);
5677 if (p != std::string::npos) {
5678 s.width((std::streamsize)maxAfter);
5679 s << values[i * n + j].substr(p, maxAfter).c_str();
5681 assert(maxAfter > 1);
5682 s.width((std::streamsize)maxAfter);
5692 s.flags(original_flags);
5694 return (
int)(maxBefore + maxAfter);
5736 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5737 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5738 os << (*this)[i][j] <<
", ";
5740 if (this->
getRows() != i + 1) {
5741 os <<
";" << std::endl;
5743 os <<
"]" << std::endl;
5779 os <<
"([ " << std::endl;
5780 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5782 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5783 os << (*this)[i][j] <<
", ";
5785 os <<
"]," << std::endl;
5787 os <<
"])" << std::endl;
5820 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5821 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5822 os << (*this)[i][j];
5823 if (!(j == (this->
getCols() - 1)))
5869 os <<
"vpMatrix " << matrixName <<
" (" << this->
getRows() <<
", " << this->
getCols() <<
"); " << std::endl;
5871 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
5872 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
5874 os << matrixName <<
"[" << i <<
"][" << j <<
"] = " << (*this)[i][j] <<
"; " << std::endl;
5876 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
5877 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"][" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
5878 << (
unsigned int)((
unsigned char *)&((*this)[i][j]))[k] <<
"; " << std::endl;
5901 unsigned int rowNumOld =
rowNum;
5932 if (r.
size() == 0) {
5936 unsigned int oldSize =
size();
5941 memcpy(
data + oldSize, r.
data,
sizeof(
double) * r.
size());
5972 if (c.
size() == 0) {
5977 unsigned int oldColNum =
colNum;
5982 for (
unsigned int i = 0; i <
rowNum; i++) {
5983 memcpy(
data + i*
colNum, tmp.
data + i*oldColNum,
sizeof(
double) * oldColNum);
6006 for (
unsigned int i = r; i < (r + A.
getRows()); i++) {
6058 "Cannot compute eigen values on a non square matrix (%dx%d)",
6064 for (
unsigned int i = 0; i <
rowNum; i++) {
6065 for (
unsigned int j = 0; j <
rowNum; j++) {
6067 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6073 #if defined(VISP_HAVE_LAPACK) 6074 #if defined(VISP_HAVE_GSL) 6076 gsl_vector *eval = gsl_vector_alloc(rowNum);
6077 gsl_matrix *evec = gsl_matrix_alloc(rowNum,
colNum);
6079 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(rowNum);
6080 gsl_matrix *m = gsl_matrix_alloc(rowNum,
colNum);
6082 unsigned int Atda = (
unsigned int)m->tda;
6083 for (
unsigned int i = 0; i <
rowNum; i++) {
6084 unsigned int k = i * Atda;
6085 for (
unsigned int j = 0; j <
colNum; j++)
6086 m->data[k + j] = (*
this)[i][j];
6088 gsl_eigen_symmv(m, eval, evec, w);
6090 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6092 for (
unsigned int i = 0; i <
rowNum; i++) {
6093 evalue[i] = gsl_vector_get(eval, i);
6096 gsl_eigen_symmv_free(w);
6097 gsl_vector_free(eval);
6099 gsl_matrix_free(evec);
6103 const char jobz =
'N';
6104 const char uplo =
'U';
6110 vpMatrix::blas_dsyev(jobz, uplo, rowNum, A.
data,
colNum, evalue.
data, &wkopt, lwork, info);
6111 lwork =
static_cast<int>(wkopt);
6113 vpMatrix::blas_dsyev(jobz, uplo, rowNum, A.
data,
colNum, evalue.
data, WORK.
data, lwork, info);
6119 "Eigen values computation is not implemented. " 6120 "You should install Lapack 3rd party"));
6180 "Cannot compute eigen values on a non square matrix (%dx%d)",
6186 for (
unsigned int i = 0; i <
rowNum; i++) {
6187 for (
unsigned int j = 0; j <
rowNum; j++) {
6189 if (std::fabs(At_A[i][j]) > std::numeric_limits<double>::epsilon()) {
6199 #if defined(VISP_HAVE_LAPACK) 6200 #if defined(VISP_HAVE_GSL) 6202 gsl_vector *eval = gsl_vector_alloc(rowNum);
6203 gsl_matrix *evec = gsl_matrix_alloc(rowNum,
colNum);
6205 gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(rowNum);
6206 gsl_matrix *m = gsl_matrix_alloc(rowNum,
colNum);
6208 unsigned int Atda = (
unsigned int)m->tda;
6209 for (
unsigned int i = 0; i <
rowNum; i++) {
6210 unsigned int k = i * Atda;
6211 for (
unsigned int j = 0; j <
colNum; j++)
6212 m->data[k + j] = (*
this)[i][j];
6214 gsl_eigen_symmv(m, eval, evec, w);
6216 gsl_eigen_symmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_ASC);
6218 for (
unsigned int i = 0; i <
rowNum; i++) {
6219 evalue[i] = gsl_vector_get(eval, i);
6221 Atda = (
unsigned int)evec->tda;
6222 for (
unsigned int i = 0; i <
rowNum; i++) {
6223 unsigned int k = i * Atda;
6224 for (
unsigned int j = 0; j <
rowNum; j++) {
6225 evector[i][j] = evec->
data[k + j];
6229 gsl_eigen_symmv_free(w);
6230 gsl_vector_free(eval);
6232 gsl_matrix_free(evec);
6234 #else // defined(VISP_HAVE_GSL) 6236 const char jobz =
'V';
6237 const char uplo =
'U';
6243 vpMatrix::blas_dsyev(jobz, uplo, rowNum, A.
data,
colNum, evalue.
data, &wkopt, lwork, info);
6244 lwork =
static_cast<int>(wkopt);
6246 vpMatrix::blas_dsyev(jobz, uplo, rowNum, A.
data,
colNum, evalue.
data, WORK.
data, lwork, info);
6249 #endif // defined(VISP_HAVE_GSL) 6253 "Eigen values computation is not implemented. " 6254 "You should install Lapack 3rd party"));
6280 unsigned int nbline =
getRows();
6281 unsigned int nbcol =
getCols();
6286 V.
resize(nbcol, nbcol,
false);
6293 U.
resize(nbcol, nbcol,
true);
6295 U.
resize(nbline, nbcol,
false);
6303 for (
unsigned int i = 0; i < nbcol; i++) {
6304 if (sv[i] > maxsv) {
6309 unsigned int rank = 0;
6310 for (
unsigned int i = 0; i < nbcol; i++) {
6311 if (sv[i] > maxsv * svThreshold) {
6316 kerAt.
resize(nbcol - rank, nbcol);
6317 if (rank != nbcol) {
6318 for (
unsigned int j = 0, k = 0; j < nbcol; j++) {
6320 if ((sv[j] <= maxsv * svThreshold) &&
6321 (std::fabs(V.
getCol(j).
sumSquare()) > std::numeric_limits<double>::epsilon())) {
6322 for (
unsigned int i = 0; i < V.
getRows(); i++) {
6323 kerAt[k][i] = V[i][j];
6388 #ifdef VISP_HAVE_GSL 6390 double *b =
new double[size_];
6391 for (
size_t i = 0; i < size_; i++)
6393 gsl_matrix_view m = gsl_matrix_view_array(this->
data,
rowNum, colNum);
6394 gsl_matrix_view em = gsl_matrix_view_array(b,
rowNum, colNum);
6395 gsl_linalg_exponential_ss(&m.matrix, &em.matrix, 0);
6399 memcpy(expA.
data, b, size_ *
sizeof(
double));
6420 for (
unsigned int i = 0; i <
rowNum; i++) {
6422 for (
unsigned int j = 0; j <
colNum; j++) {
6423 sum += fabs((*
this)[i][j]);
6425 if (sum > nA || i == 0) {
6434 double sca = 1.0 / pow(2.0, s);
6437 _expE = c * exp + _eye;
6438 _expD = -c * exp + _eye;
6439 for (
int k = 2; k <= q; k++) {
6440 c = c * ((double)(q - k + 1)) / ((
double)(k * (2 * q - k + 1)));
6441 _expcX = exp * _expX;
6444 _expE = _expE + _expcX;
6446 _expD = _expD + _expcX;
6448 _expD = _expD - _expcX;
6452 exp = _expX * _expE;
6453 for (
int k = 1; k <= s; k++) {
6486 for (
unsigned int i = 0; i < col; i++) {
6487 for (
unsigned int j = 0; j <
row; j++)
6488 M_comp[i][j] = M[i][j];
6489 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6490 M_comp[i][j - 1] = M[i][j];
6492 for (
unsigned int i = col + 1; i < M.
getCols(); i++) {
6493 for (
unsigned int j = 0; j <
row; j++)
6494 M_comp[i - 1][j] = M[i][j];
6495 for (
unsigned int j = row + 1; j < M.
getRows(); j++)
6496 M_comp[i - 1][j - 1] = M[i][j];
6512 unsigned int nbline =
getRows();
6513 unsigned int nbcol =
getCols();
6518 V.
resize(nbcol, nbcol,
false);
6525 U.
resize(nbcol, nbcol,
true);
6527 U.
resize(nbline, nbcol,
false);
6535 for (
unsigned int i = 0; i < nbcol; i++) {
6536 if (sv[i] > maxsv) {
6542 unsigned int rank = 0;
6543 for (
unsigned int i = 0; i < nbcol; i++) {
6544 if (sv[i] > maxsv * svThreshold) {
6550 double minsv = maxsv;
6551 for (
unsigned int i = 0; i < rank; i++) {
6552 if (sv[i] < minsv) {
6557 if (std::fabs(minsv) > std::numeric_limits<double>::epsilon()) {
6558 return maxsv / minsv;
6561 return std::numeric_limits<double>::infinity();
6579 for (
unsigned int i = 0; i < H.
getCols(); i++) {
6580 HLM[i][i] += alpha * H[i][i];
6608 for (
unsigned int i = 0; i <
dsize; i++) {
6609 double x = *(
data + i);
6626 if(this->
dsize != 0){
6635 unsigned int maxRank = std::min(this->
getCols(), this->
getRows());
6638 unsigned int boundary = std::min(maxRank, w.
size());
6643 for (
unsigned int i = 0; i < boundary; i++) {
6668 for (
unsigned int i = 0; i <
rowNum; i++) {
6670 for (
unsigned int j = 0; j <
colNum; j++) {
6671 x += fabs(*(*(
rowPtrs + i) + j));
6688 double sum_square = 0.0;
6691 for (
unsigned int i = 0; i <
rowNum; i++) {
6692 for (
unsigned int j = 0; j <
colNum; j++) {
6694 sum_square += x * x;
6715 conv2(M, kernel, res, mode);
6736 if (mode ==
"valid") {
6743 if (mode ==
"full" || mode ==
"same") {
6744 const unsigned int pad_x = kernel.
getCols()-1;
6745 const unsigned int pad_y = kernel.
getRows()-1;
6747 M_padded.
insert(M, pad_y, pad_x);
6749 if (mode ==
"same") {
6755 }
else if (mode ==
"valid") {
6762 if (mode ==
"same") {
6763 for (
unsigned int i = 0; i < res_same.
getRows(); i++) {
6764 for (
unsigned int j = 0; j < res_same.
getCols(); j++) {
6765 for (
unsigned int k = 0; k < kernel.
getRows(); k++) {
6766 for (
unsigned int l = 0; l < kernel.
getCols(); l++) {
6767 res_same[i][j] += M_padded[i+k][j+l] * kernel[kernel.
getRows()-k-1][kernel.
getCols()-l-1];
6773 const unsigned int start_i = kernel.
getRows()/2;
6774 const unsigned int start_j = kernel.
getCols()/2;
6775 for (
unsigned int i = 0; i < M.
getRows(); i++) {
6779 for (
unsigned int i = 0; i < res.
getRows(); i++) {
6780 for (
unsigned int j = 0; j < res.
getCols(); j++) {
6781 for (
unsigned int k = 0; k < kernel.
getRows(); k++) {
6782 for (
unsigned int l = 0; l < kernel.
getCols(); l++) {
6783 res[i][j] += M_padded[i+k][j+l] * kernel[kernel.
getRows()-k-1][kernel.
getCols()-l-1];
6791 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 6828 for (
unsigned int j = 0; j <
getCols(); j++)
6829 c[j] = (*
this)[i - 1][j];
6854 for (
unsigned int i = 0; i <
getRows(); i++)
6855 c[i] = (*
this)[i][j - 1];
6867 for (
unsigned int i = 0; i <
rowNum; i++)
6868 for (
unsigned int j = 0; j <
colNum; j++)
6870 (*this)[i][j] = val;
6875 #endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) void solveBySVD(const vpColVector &B, vpColVector &x) const
void svd(vpColVector &w, vpMatrix &V)
vpMatrix operator*(const double &x, const vpMatrix &B)
vpMatrix extract(unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols) const
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
static vpMatrix juxtaposeMatrices(const vpMatrix &A, const vpMatrix &B)
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
vpColVector getDiag() const
double det(vpDetMethod method=LU_DECOMPOSITION) const
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full")
void kron(const vpMatrix &m1, vpMatrix &out) const
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpMatrix operator-() const
Implementation of row vector and the associated operations.
std::ostream & csvPrint(std::ostream &os) const
static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
void stack(const vpMatrix &A)
vp_deprecated vpColVector column(unsigned int j)
vpMatrix inverseByLU() const
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
error that can be emited by ViSP classes.
unsigned int getRows() const
double * data
Address of the first element of the data array.
vp_deprecated void stackMatrices(const vpMatrix &A)
Implementation of a generic 2D array used as base class for matrices and vectors. ...
static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
unsigned int size() const
Return the number of elements of the 2D array.
vpMatrix pseudoInverseLapack(double svThreshold=1e-6) const
vpMatrix & operator+=(const vpMatrix &B)
Operation A = A + B.
vpMatrix operator/(double x) const
Cij = Aij / x (A is unchanged)
double infinityNorm() const
void svdLapack(vpColVector &w, vpMatrix &V)
double cond(double svThreshold=1e-6) const
vpMatrix & operator-=(const vpMatrix &B)
Operation A = A - B.
vpMatrix operator+(const vpMatrix &B) const
vpMatrix pseudoInverseEigen3(double svThreshold=1e-6) const
static Type maximum(const Type &a, const Type &b)
Implementation of a rotation matrix and operations on such kind of matrices.
vpMatrix & operator*=(double x)
Multiply all the element of the matrix by x : Aij = Aij * x.
unsigned int getCols() const
std::ostream & maplePrint(std::ostream &os) const
unsigned int rowNum
Number of rows in the array.
vpMatrix hadamard(const vpMatrix &m) const
vp_deprecated void setIdentity(const double &val=1.0)
std::ostream & matlabPrint(std::ostream &os) const
unsigned int kernel(vpMatrix &kerAt, double svThreshold=1e-6) const
void diag(const double &val=1.0)
vp_deprecated void init()
static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, vpMatrix &C)
vpMatrix pseudoInverseOpenCV(double svThreshold=1e-6) const
vpRowVector getRow(unsigned int i) const
static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w)
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpColVector eigenValues() const
double euclideanNorm() const
void svdOpenCV(vpColVector &w, vpMatrix &V)
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
vpColVector getCol(unsigned int j) const
vpMatrix transpose() const
unsigned int colNum
Number of columns in the array.
double inducedL2Norm() const
vpMatrix operator*(const vpMatrix &B) const
vp_deprecated vpRowVector row(unsigned int i)
void resize(unsigned int i, bool flagNullify=true)
Implementation of column vector and the associated operations.
static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA)
vpColVector stackColumns()
unsigned int dsize
Current array size (rowNum * colNum)
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
static void negateMatrix(const vpMatrix &A, vpMatrix &C)
static void computeHLM(const vpMatrix &H, const double &alpha, vpMatrix &HLM)
vpMatrix & operator,(double val)
double frobeniusNorm() const
Function not implemented.
void resize(unsigned int i, bool flagNullify=true)
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
void svdEigen3(vpColVector &w, vpMatrix &V)
vpMatrix & operator=(const vpArray2D< double > &A)
vpMatrix & operator<<(double *)