34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpMatrix.h>
37 #if defined(VISP_HAVE_SIMDLIB)
38 #include <Simd/SimdLib.h>
242 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
245 if (
this != &other) {
261 other.rowPtrs =
nullptr;
263 other.data =
nullptr;
301 if (
dsize !=
static_cast<unsigned int>(list.size())) {
302 resize(1,
static_cast<unsigned int>(list.size()),
false,
false);
305 std::copy(list.begin(), list.end(),
data);
339 unsigned int nrows =
static_cast<unsigned int>(lists.size()), ncols = 0;
340 for (
auto &l : lists) {
341 if (
static_cast<unsigned int>(l.size()) > ncols) {
342 ncols =
static_cast<unsigned int>(l.size());
346 resize(nrows, ncols,
false,
false);
347 auto it = lists.begin();
348 for (
unsigned int i = 0; i <
rowNum; ++i, ++it) {
349 std::copy(it->begin(), it->end(),
rowPtrs[i]);
370 for (
unsigned int i = 0; i <
rowNum; ++i) {
371 for (
unsigned int j = 0; j <
colNum; ++j) {
380 resize(1, 1,
false,
false);
400 const unsigned int val_3 = 3;
406 for (
unsigned int j = 0; j < val_3; ++j) {
410 for (
unsigned int j = 0; j < val_3; ++j) {
412 for (
unsigned int i = 0; i < val_3; ++i) {
413 t_out[i] +=
rowPtrs[i][j] * tj;
454 const unsigned int val_3 = 3;
457 unsigned int RcolNum = R.
getCols();
458 unsigned int RrowNum = R.
getRows();
459 for (
unsigned int i = 0; i <
rowNum; ++i) {
462 for (
unsigned int j = 0; j < RcolNum; ++j) {
464 for (
unsigned int k = 0; k < RrowNum; ++k) {
465 s += rowptri[k] * R[k][j];
485 const unsigned int val_4 = 4;
488 const unsigned int McolNum = M.
getCols();
489 const unsigned int MrowNum = M.
getRows();
490 for (
unsigned int i = 0; i <
rowNum; ++i) {
491 const double *rowptri =
rowPtrs[i];
493 for (
unsigned int j = 0; j < McolNum; ++j) {
495 for (
unsigned int k = 0; k < MrowNum; ++k) {
496 s += rowptri[k] * M[k][j];
517 const unsigned int val_6 = 6;
525 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size) ||
526 (V.
colNum > vpMatrix::m_lapack_min_size));
527 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
532 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
533 const double alpha = 1.0;
534 const double beta = 0.0;
535 const char trans =
'n';
536 vpMatrix::blas_dgemm(trans, trans, V.
colNum,
rowNum,
colNum, alpha, V.
data, V.
colNum,
data,
colNum, beta, M.
data,
541 #if defined(VISP_HAVE_SIMDLIB)
544 unsigned int VcolNum = V.
getCols();
545 unsigned int VrowNum = V.
getRows();
546 for (
unsigned int i = 0; i <
rowNum; ++i) {
549 for (
unsigned int j = 0; j < VcolNum; ++j) {
551 for (
unsigned int k = 0; k < VrowNum; ++k) {
552 s += rowptri[k] * V[k][j];
574 const unsigned int val_6 = 6;
582 bool useLapack = ((
rowNum > vpMatrix::m_lapack_min_size) || (
colNum > vpMatrix::m_lapack_min_size) ||
583 (V.
getCols() > vpMatrix::m_lapack_min_size));
584 #if !(defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL))
589 #if defined(VISP_HAVE_LAPACK) && !defined(VISP_HAVE_LAPACK_BUILT_IN) && !defined(VISP_HAVE_GSL)
590 const double alpha = 1.0;
591 const double beta = 0.0;
592 const char trans =
'n';
593 vpMatrix::blas_dgemm(trans, trans, V.
getCols(),
rowNum,
colNum, alpha, V.
data, V.
getCols(),
data,
colNum, beta,
598 #if defined(VISP_HAVE_SIMDLIB)
601 unsigned int VcolNum = V.
getCols();
602 unsigned int VrowNum = V.
getRows();
603 for (
unsigned int i = 0; i <
rowNum; ++i) {
606 for (
unsigned int j = 0; j < VcolNum; ++j) {
608 for (
unsigned int k = 0; k < VrowNum; ++k) {
609 s += rowptri[k] * V[k][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];
671 for (
unsigned int i = 0; i <
rowNum; ++i) {
672 for (
unsigned int j = 0; j <
colNum; ++j) {
673 rowPtrs[i][j] -= BrowPtrs[i][j];
694 for (
unsigned int i = 0; i <
rowNum; ++i) {
695 for (
unsigned int j = 0; j <
colNum; ++j) {
709 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
716 for (
unsigned int i = 0; i <
rowNum; ++i) {
717 for (
unsigned int j = 0; j <
colNum; ++j) {
729 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
733 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
742 for (
unsigned int i = 0; i <
rowNum; ++i) {
743 for (
unsigned int j = 0; j <
colNum; ++j) {
744 C[i][j] =
rowPtrs[i][j] * xinv;
754 for (
unsigned int i = 0; i <
rowNum; ++i) {
755 for (
unsigned int j = 0; j <
colNum; ++j) {
766 for (
unsigned int i = 0; i <
rowNum; ++i) {
767 for (
unsigned int j = 0; j <
colNum; ++j) {
781 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
785 for (
unsigned int i = 0; i <
rowNum; ++i) {
786 for (
unsigned int j = 0; j <
colNum; ++j) {
797 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
801 if (std::fabs(x) < std::numeric_limits<double>::epsilon()) {
807 for (
unsigned int i = 0; i <
rowNum; ++i) {
808 for (
unsigned int j = 0; j <
colNum; ++j) {
822 if (std::fabs(x - 1.) < std::numeric_limits<double>::epsilon()) {
826 unsigned int Brow = B.
getRows();
827 unsigned int Bcol = B.
getCols();
829 VISP_NAMESPACE_ADDRESSING
vpMatrix C;
830 C.
resize(Brow, Bcol,
false,
false);
832 for (
unsigned int i = 0; i < Brow; ++i) {
833 for (
unsigned int j = 0; j < Bcol; ++j) {
834 C[i][j] = B[i][j] * x;
unsigned int getCols() const
double * data
Address of the first element of the data array.
double ** rowPtrs
Address of the first element of each rows.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int rowNum
Number of rows in the array.
unsigned int dsize
Current array size (rowNum * colNum)
unsigned int getRows() const
unsigned int colNum
Number of columns in the array.
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.
Implementation of a matrix and operations on 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.