34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpMatrix.h>
37 #if defined(VISP_HAVE_SIMDLIB)
38 #include <Simd/SimdLib.h>
70 for (
unsigned int i = 0; i <
rowNum; ++i) {
71 for (
unsigned int j = 0; j <
colNum; ++j) {
72 At[j][i] = (*this)[i][j];
77 #if defined(VISP_HAVE_SIMDLIB)
81 const int tileSize = 32;
82 for (
unsigned int i = 0; i <
rowNum; i += tileSize) {
83 for (
unsigned int j = 0; j <
colNum; ++j) {
84 for (
unsigned int b = 0; ((b < static_cast<unsigned int>(tileSize)) && ((i + b) <
rowNum)); ++b) {
85 At[j][i + b] = (*this)[i + b][j];
113 bool useLapack = ((A.
rowNum > vpMatrix::m_lapack_min_size) || (A.
colNum > vpMatrix::m_lapack_min_size));
114 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
119 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
125 vpMatrix::blas_dgemv(trans, A.
colNum, A.
rowNum, alpha, A.
data, A.
colNum, v.
data, incr, beta, w.
data, incr);
130 for (
unsigned int j = 0; j < A.
colNum; ++j) {
132 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
164 bool useLapack = ((A.
rowNum > vpMatrix::m_lapack_min_size) || (A.
colNum > vpMatrix::m_lapack_min_size) ||
165 (B.
colNum > vpMatrix::m_lapack_min_size));
166 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
171 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
172 const double alpha = 1.0;
173 const double beta = 0.0;
174 const char trans =
'n';
175 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
181 const unsigned int BcolNum = B.
colNum;
182 const unsigned int BrowNum = B.
rowNum;
184 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
185 const double *rowptri = A.
rowPtrs[i];
187 for (
unsigned int j = 0; j < BcolNum; ++j) {
189 for (
unsigned int k = 0; k < BrowNum; ++k) {
190 s += rowptri[k] * BrowPtrs[k][j];
214 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
219 const unsigned int BcolNum = B.
colNum;
220 const unsigned int BrowNum = B.
rowNum;
222 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
223 const double *rowptri = A.
rowPtrs[i];
225 for (
unsigned int j = 0; j < BcolNum; ++j) {
227 for (
unsigned int k = 0; k < BrowNum; ++k) {
228 s += rowptri[k] * BrowPtrs[k][j];
251 "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a "
260 bool useLapack = ((A.
rowNum > vpMatrix::m_lapack_min_size) || (A.
colNum > vpMatrix::m_lapack_min_size) ||
261 (B.
colNum > vpMatrix::m_lapack_min_size));
262 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
267 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
268 const double alpha = 1.0;
269 const double beta = 0.0;
270 const char trans =
'n';
271 vpMatrix::blas_dgemm(trans, trans, B.
colNum, A.
rowNum, A.
colNum, alpha, B.
data, B.
colNum, A.
data, A.
colNum, beta,
277 const unsigned int BcolNum = B.
colNum;
278 const unsigned int BrowNum = B.
rowNum;
280 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
281 const double *rowptri = A.
rowPtrs[i];
283 for (
unsigned int j = 0; j < BcolNum; ++j) {
285 for (
unsigned int k = 0; k < BrowNum; ++k) {
286 s += rowptri[k] * BrowPtrs[k][j];
337 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
338 for (
unsigned int j = 0; j < A.
colNum; ++j) {
339 CrowPtrs[i][j] = (wB * BrowPtrs[i][j]) + (wA * ArowPtrs[i][j]);
368 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
369 for (
unsigned int j = 0; j < A.
colNum; ++j) {
370 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
402 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
403 for (
unsigned int j = 0; j < A.
colNum; ++j) {
404 CrowPtrs[i][j] = BrowPtrs[i][j] + ArowPtrs[i][j];
439 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
440 for (
unsigned int j = 0; j < A.
colNum; ++j) {
441 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
473 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
474 for (
unsigned int j = 0; j < A.
colNum; ++j) {
475 CrowPtrs[i][j] = ArowPtrs[i][j] - BrowPtrs[i][j];
498 for (
unsigned int i = 0; i < A.
rowNum; ++i) {
499 for (
unsigned int j = 0; j < A.
colNum; ++j) {
500 CrowPtrs[i][j] = -ArowPtrs[i][j];
537 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size));
538 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
543 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
544 const double alpha = 1.0;
545 const double beta = 0.0;
546 const char transa =
't';
547 const char transb =
'n';
549 vpMatrix::blas_dgemm(transa, transb,
rowNum,
rowNum,
colNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
555 for (
unsigned int i = 0; i <
rowNum; ++i) {
556 for (
unsigned int j = i; j <
rowNum; ++j) {
562 for (
unsigned int k = 0; k <
colNum; ++k) {
563 ssum += *(pi++) * *(pj++);
593 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size));
594 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
599 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
600 const double alpha = 1.0;
601 const double beta = 0.0;
602 const char transa =
'n';
603 const char transb =
't';
605 vpMatrix::blas_dgemm(transa, transb,
colNum,
colNum,
rowNum, alpha,
data,
colNum,
data,
colNum, beta, B.
data,
610 for (
unsigned int i = 0; i <
colNum; ++i) {
612 for (
unsigned int j = 0; j < i; ++j) {
615 for (
unsigned int k = 0; k <
rowNum; ++k) {
616 s += (*(ptr + i)) * (*(ptr + j));
624 for (
unsigned int k = 0; k <
rowNum; ++k) {
625 s += (*(ptr + i)) * (*(ptr + i));
688 unsigned int rows = A.
getRows();
692 for (
unsigned int i = 0; i < rows; ++i) {
693 (*this)[i][i] = A[i];
735 for (
unsigned int i = 0; i < min_; ++i) {
752 unsigned int rows = A.
getRows();
753 DA.
resize(rows, rows,
true);
755 for (
unsigned int i = 0; i < rows; ++i) {
783 for (
unsigned int i = 0; i <
rowNum; ++i) {
784 for (
unsigned int j = 0; j <
colNum; ++j) {
810 #if defined(VISP_HAVE_SIMDLIB)
813 for (
unsigned int i = 0; i <
dsize; ++i) {
829 unsigned int r1 = m1.
getRows();
830 unsigned int c1 = m1.
getCols();
831 unsigned int r2 = m2.
getRows();
832 unsigned int c2 = m2.
getCols();
834 out.
resize(r1 * r2, c1 * c2,
false,
false);
836 for (
unsigned int r = 0; r < r1; ++r) {
837 for (
unsigned int c = 0; c < c1; ++c) {
838 double alpha = m1[r][c];
839 double *m2ptr = m2[0];
840 unsigned int roffset = r * r2;
841 unsigned int coffset = c * c2;
842 for (
unsigned int rr = 0; rr < r2; ++rr) {
843 for (
unsigned int cc = 0; cc < c2; ++cc) {
844 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
867 unsigned int r1 = m1.
getRows();
868 unsigned int c1 = m1.
getCols();
869 unsigned int r2 = m2.
getRows();
870 unsigned int c2 = m2.
getCols();
873 out.
resize(r1 * r2, c1 * c2,
false,
false);
875 for (
unsigned int r = 0; r < r1; ++r) {
876 for (
unsigned int c = 0; c < c1; ++c) {
877 double alpha = m1[r][c];
878 double *m2ptr = m2[0];
879 unsigned int roffset = r * r2;
880 unsigned int coffset = c * c2;
881 for (
unsigned int rr = 0; rr < r2; ++rr) {
882 for (
unsigned int cc = 0; cc < c2; ++cc) {
883 out[roffset + rr][coffset + cc] = alpha * *(m2ptr++);
911 if (mode ==
"valid") {
919 if ((mode ==
"full") || (mode ==
"same")) {
920 const unsigned int pad_x =
kernel.getCols() - 1;
921 const unsigned int pad_y =
kernel.getRows() - 1;
922 const unsigned int pad = 2;
924 M_padded.
insert(M, pad_y, pad_x);
926 if (mode ==
"same") {
934 else if (mode ==
"valid") {
942 if (mode ==
"same") {
943 unsigned int res_same_rows = res_same.
getRows();
944 unsigned int res_same_cols = res_same.
getCols();
945 unsigned int kernel_rows =
kernel.getRows();
946 unsigned int kernel_cols =
kernel.getCols();
947 for (
unsigned int i = 0; i < res_same_rows; ++i) {
948 for (
unsigned int j = 0; j < res_same_cols; ++j) {
949 for (
unsigned int k = 0; k < kernel_rows; ++k) {
950 for (
unsigned int l = 0; l < kernel_cols; ++l) {
951 res_same[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
957 const unsigned int start_i =
kernel.getRows() / 2;
958 const unsigned int start_j =
kernel.getCols() / 2;
959 unsigned int m_rows = M.
getRows();
960 for (
unsigned int i = 0; i < m_rows; ++i) {
966 unsigned int res_rows = res.
getRows();
967 unsigned int res_cols = res.
getCols();
968 unsigned int kernel_rows =
kernel.getRows();
969 unsigned int kernel_cols =
kernel.getCols();
970 for (
unsigned int i = 0; i < res_rows; ++i) {
971 for (
unsigned int j = 0; j < res_cols; ++j) {
972 for (
unsigned int k = 0; k < kernel_rows; ++k) {
973 for (
unsigned int l = 0; l < kernel_cols; ++l) {
974 res[i][j] += M_padded[i + k][j + l] *
kernel[
kernel.getRows() - k - 1][
kernel.getCols() - l - 1];
unsigned int getCols() const
double * data
Address of the first element of the data array.
Type ** 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 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.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
vpMatrix hadamard(const vpMatrix &m) const
unsigned int kernel(vpMatrix &kerAt, double svThreshold=1e-6) const
static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
void diag(const double &val=1.0)
static void add2WeightedMatrices(const vpMatrix &A, const double &wA, const vpMatrix &B, const double &wB, vpMatrix &C)
static void createDiagonalMatrix(const vpColVector &A, vpMatrix &DA)
static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w)
static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
void kron(const vpMatrix &m1, vpMatrix &out) const
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode)
vpMatrix transpose() const
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
static void negateMatrix(const vpMatrix &A, vpMatrix &C)
Implementation of a rotation matrix and operations on such kind of matrices.