34#include <visp3/core/vpConfig.h>
35#include <visp3/core/vpMatrix.h>
37#if defined(VISP_HAVE_SIMDLIB)
38#include <Simd/SimdLib.h>
107 resize(R.getRows(), R.getCols(),
false,
false);
109 if ((
data !=
nullptr) && (R.data !=
nullptr) && (
data != R.data)) {
110 memcpy(
data, R.data,
dsize *
sizeof(
double));
176 resize(v.getRows(), v.getCols(),
false,
false);
178 if ((
data !=
nullptr) && (v.data !=
nullptr) && (
data != v.data)) {
179 memcpy(
data, v.data,
dsize *
sizeof(
double));
199 resize(v.getRows(), v.getCols(),
false,
false);
201 if ((
data !=
nullptr) && (v.data !=
nullptr) && (
data != v.data)) {
202 memcpy(
data, v.data,
dsize *
sizeof(
double));
222 resize(
t.getRows(),
t.getCols(),
false,
false);
224 if ((
data !=
nullptr) && (
t.data !=
nullptr) && (
data !=
t.data)) {
242#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
281 if (
dsize !=
static_cast<unsigned int>(list.size())) {
282 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
285 std::copy(list.begin(), list.end(),
data);
319 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
320 for (
auto &l : lists) {
321 if (
static_cast<unsigned int>(l.size()) > ncols) {
322 ncols =
static_cast<unsigned int>(l.size());
326 resize(nrows, ncols,
false,
false);
327 auto it = lists.begin();
328 for (
unsigned int i = 0; i <
rowNum; ++i, ++it) {
329 std::copy(it->begin(), it->end(),
rowPtrs[i]);
350 for (
unsigned int i = 0; i <
rowNum; ++i) {
351 for (
unsigned int j = 0; j <
colNum; ++j) {
360 resize(1, 1,
false,
false);
380 const unsigned int val_3 = 3;
386 for (
unsigned int j = 0; j < val_3; ++j) {
390 for (
unsigned int j = 0; j < val_3; ++j) {
392 for (
unsigned int i = 0; i < val_3; ++i) {
393 t_out[i] +=
rowPtrs[i][j] * tj;
429 if (
colNum != R.getRows()) {
434 const unsigned int val_3 = 3;
437 unsigned int RcolNum = R.getCols();
438 unsigned int RrowNum = R.getRows();
439 for (
unsigned int i = 0; i <
rowNum; ++i) {
442 for (
unsigned int j = 0; j < RcolNum; ++j) {
444 for (
unsigned int k = 0; k < RrowNum; ++k) {
445 s += rowptri[k] * R[k][j];
465 const unsigned int val_4 = 4;
468 const unsigned int McolNum = M.
getCols();
469 const unsigned int MrowNum = M.
getRows();
470 for (
unsigned int i = 0; i <
rowNum; ++i) {
471 const double *rowptri =
rowPtrs[i];
473 for (
unsigned int j = 0; j < McolNum; ++j) {
475 for (
unsigned int k = 0; k < MrowNum; ++k) {
476 s += rowptri[k] * M[k][j];
497 const unsigned int val_6 = 6;
501 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size) ||
502 (V.
colNum > vpMatrix::m_lapack_min_size));
503#if !defined(VISP_HAVE_LAPACK)
508#if defined(VISP_HAVE_LAPACK)
509 const double alpha = 1.0;
510 const double beta = 0.0;
511 const char trans =
'n';
512#if defined(VISP_HAVE_GSL)
513 vpMatrix::blas_dgemm(trans, trans,
rowNum, V.
colNum,
colNum, alpha,
data,
colNum, V.
data, V.
colNum, beta, M.
data,
516 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
522#if defined(VISP_HAVE_SIMDLIB)
525 unsigned int VcolNum = V.
getCols();
526 unsigned int VrowNum = V.
getRows();
527 for (
unsigned int i = 0; i <
rowNum; ++i) {
530 for (
unsigned int j = 0; j < VcolNum; ++j) {
532 for (
unsigned int k = 0; k < VrowNum; ++k) {
533 s += rowptri[k] * V[k][j];
555 const unsigned int val_6 = 6;
559 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size) ||
560 (V.
getCols() > vpMatrix::m_lapack_min_size));
561#if !defined(VISP_HAVE_LAPACK)
566#if defined(VISP_HAVE_LAPACK)
567 const double alpha = 1.0;
568 const double beta = 0.0;
569 const char trans =
'n';
570#if defined(VISP_HAVE_GSL)
571 vpMatrix::blas_dgemm(trans, trans,
rowNum, V.
getCols(),
colNum, alpha,
data,
colNum, V.
data, V.
getCols(), beta, M.
data,
574 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta, M.
data,
580#if defined(VISP_HAVE_SIMDLIB)
583 unsigned int VcolNum = V.
getCols();
584 unsigned int VrowNum = V.
getRows();
585 for (
unsigned int i = 0; i <
rowNum; ++i) {
588 for (
unsigned int j = 0; j < VcolNum; ++j) {
590 for (
unsigned int k = 0; k < VrowNum; ++k) {
591 s += rowptri[k] * V[k][j];
635 for (
unsigned int i = 0; i <
rowNum; ++i) {
636 for (
unsigned int j = 0; j <
colNum; ++j) {
637 rowPtrs[i][j] += BrowPtrs[i][j];
653 for (
unsigned int i = 0; i <
rowNum; ++i) {
654 for (
unsigned int j = 0; j <
colNum; ++j) {
655 rowPtrs[i][j] -= BrowPtrs[i][j];
676 for (
unsigned int i = 0; i <
rowNum; ++i) {
677 for (
unsigned int j = 0; j <
colNum; ++j) {
691 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
698 for (
unsigned int i = 0; i <
rowNum; ++i) {
699 for (
unsigned int j = 0; j <
colNum; ++j) {
711 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
715 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
724 for (
unsigned int i = 0; i <
rowNum; ++i) {
725 for (
unsigned int j = 0; j <
colNum; ++j) {
726 C[i][j] =
rowPtrs[i][j] * xinv;
736 for (
unsigned int i = 0; i <
rowNum; ++i) {
737 for (
unsigned int j = 0; j <
colNum; ++j) {
748 for (
unsigned int i = 0; i <
rowNum; ++i) {
749 for (
unsigned int j = 0; j <
colNum; ++j) {
763 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
767 for (
unsigned int i = 0; i <
rowNum; ++i) {
768 for (
unsigned int j = 0; j <
colNum; ++j) {
779 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
783 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
789 for (
unsigned int i = 0; i <
rowNum; ++i) {
790 for (
unsigned int j = 0; j <
colNum; ++j) {
804 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
808 unsigned int Brow = B.
getRows();
809 unsigned int Bcol = B.
getCols();
811 VISP_NAMESPACE_ADDRESSING
vpMatrix C;
812 C.resize(Brow, Bcol,
false,
false);
814 for (
unsigned int i = 0; i < Brow; ++i) {
815 for (
unsigned int j = 0; j < Bcol; ++j) {
816 C[i][j] = B[i][j] * x;
unsigned int getCols() const
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
@ divideByZeroError
Division by zero.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpMatrix operator-() const
vpMatrix & operator/=(double x)
Divide all the element of the matrix by x : Aij = Aij / x.
vpMatrix operator*(const vpMatrix &B) const
vpMatrix operator/(double x) const
Cij = Aij / x (A is unchanged).
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)
vpMatrix & operator<<(double *p)
static void sub2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
vpMatrix operator+(const vpMatrix &B) const
vpMatrix & operator+=(const vpMatrix &B)
Operation A = A + B.
vpMatrix & operator,(double val)
static void multMatrixVector(const vpMatrix &A, const vpColVector &v, vpColVector &w)
vpMatrix & operator=(const vpArray2D< double > &A)
static void add2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
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.
Implementation of row vector and the associated operations.
Class that consider the case of a translation vector.