49#include <visp3/core/vpCPUFeatures.h>
50#include <visp3/core/vpColVector.h>
51#include <visp3/core/vpException.h>
52#include <visp3/core/vpMath.h>
53#include <visp3/core/vpRotationVector.h>
55#if defined(VISP_HAVE_SIMDLIB)
56#include <Simd/SimdLib.h>
68 for (
unsigned int i = 0; i <
rowNum; ++i) {
69 r[i] = (*this)[i] + v[i];
76 const unsigned int val_3 = 3;
83 for (
unsigned int i = 0; i < val_3; ++i) {
84 s[i] = (*this)[i] +
t[i];
97 for (
unsigned int i = 0; i <
rowNum; ++i) {
110 for (
unsigned int i = 0; i <
rowNum; ++i) {
118 if (
getRows() != v.getRows()) {
123 for (
unsigned int i = 0; i <
rowNum; ++i) {
136 for (
unsigned int i = 0; i <
rowNum; ++i) {
144 if (
size() != v.size()) {
146 "Cannot compute the dot product between column vectors "
147 "with different dimensions (%d) and (%d)",
152 for (
unsigned int i = 0; i <
rowNum; ++i) {
153 r += (*this)[i] * v[i];
161 unsigned int v_cols = v.getCols();
162 for (
unsigned int i = 0; i <
rowNum; ++i) {
163 for (
unsigned int j = 0; j < v_cols; ++j) {
164 M[i][j] = (*this)[i] * v[j];
174 "Bad size during vpColVector (%dx1) and vpMatrix (%dx%d) multiplication",
178 unsigned int M_cols = M.
getCols();
179 for (
unsigned int i = 0; i <
rowNum; ++i) {
180 for (
unsigned int j = 0; j < M_cols; ++j) {
181 R[i][j] = (*this)[i] * M[0][j];
191 "Bad size during vpColVector (%dx1) and vpColVector "
192 "(%dx1) subtraction",
197 for (
unsigned int i = 0; i <
rowNum; ++i) {
198 v[i] = (*this)[i] - m[i];
210 unsigned int rnrows = r + nrows;
212 if (rnrows > v.getRows()) {
218 if (this->
rowPtrs ==
nullptr) {
221 for (
unsigned int i = r; i < rnrows; ++i) {
222 (*this)[i - r] = v[i];
228 unsigned int v_size = v.size();
229 for (
unsigned int i = 0; i < v_size; ++i) {
236 unsigned int p_size = p.size();
237 for (
unsigned int i = 0; i < p_size; ++i) {
244 unsigned int v_size = v.size();
245 for (
unsigned int i = 0; i < v_size; ++i) {
252 unsigned int m_cols = M.
getCols();
253 for (
unsigned int i = 0; i < m_cols; ++i) {
254 (*this)[i] = M[i][j];
261 throw(vpException(vpException::dimensionError,
"Cannot construct a (%dx1) row vector from a (%dx%d) matrix",
262 M.getRows(), M.getRows(), M.getCols()));
265 unsigned int m_rows = M.
getRows();
266 for (
unsigned int i = 0; i < m_rows; ++i) {
267 (*this)[i] = M[i][0];
273 unsigned int v_size =
static_cast<unsigned int>(v.size());
274 for (
unsigned int i = 0; i < v_size; ++i) {
281 unsigned int v_size =
static_cast<unsigned int>(v.size());
282 for (
unsigned int i = 0; i < v_size; ++i) {
283 (*this)[i] =
static_cast<double>(v[i]);
287#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
302 for (
unsigned int i = 0; i <
rowNum; ++i) {
319 for (
unsigned int i = 0; i <
rowNum; ++i) {
330 for (
unsigned int i = 0; i <
rowNum; ++i) {
338 for (
unsigned int i = 0; i <
rowNum; ++i) {
351 for (
unsigned int i = 0; i <
rowNum; ++i) {
375 unsigned int v_size =
static_cast<unsigned int>(v.size());
377 for (
unsigned int i = 0; i < v_size; ++i) {
385 unsigned int v_size =
static_cast<unsigned int>(v.size());
387 for (
unsigned int i = 0; i < v_size; ++i) {
388 (*this)[i] =
static_cast<double>(v[i]);
395 unsigned int k = v.rowNum;
400 memcpy(
data, v.data,
rowNum *
sizeof(
double));
428 unsigned int k = p.getRows();
433 memcpy(
data, p.data,
rowNum *
sizeof(
double));
445 for (
unsigned int i = 0; i <
rowNum; ++i) {
446 for (
unsigned int j = 0; j <
colNum; ++j) {
471 for (
unsigned int i = 0; i <
rowNum; ++i) {
479 std::vector<double> v(this->
size());
481 unsigned int v_this_size = this->
size();
482 for (
unsigned int i = 0; i < v_this_size; ++i) {
488#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
522 resize(
static_cast<unsigned int>(list.size()),
false);
523 std::copy(list.begin(), list.end(),
data);
534 for (
unsigned int i = 0; i <
rowNum; ++i) {
535 if (!
vpMath::equal(
data[i], v.data[i], std::numeric_limits<double>::epsilon())) {
545 for (
unsigned int i = 0; i <
rowNum; ++i) {
561 memcpy(v.data,
data,
rowNum *
sizeof(
double));
571 if (a.
data ==
nullptr) {
574 if (b.
data ==
nullptr) {
579 "Cannot compute the dot product between column vectors "
580 "with different dimensions (%d) and (%d)",
588 unsigned int a_rows_nbr = a.
getRows();
589 for (
unsigned int i = 0; i < a_rows_nbr; ++i) {
602 x /= sqrt(x.sumSquare());
611 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
612 *
this /= sqrt(sum_square);
621 if (v.data ==
nullptr) {
626 unsigned int nb_permutation = 1;
628 while (nb_permutation != 0) {
630 for (
unsigned int j = v.getRows() - 1; j >= (i + 1); --j) {
631 if (tab[j] > tab[j - 1]) {
646 if (v.data ==
nullptr) {
651 unsigned int nb_permutation = 1;
653 while (nb_permutation != 0) {
655 for (
unsigned int j = v.getRows() - 1; j >= (i + 1); --j) {
656 if (tab[j] < tab[j - 1]) {
686 unsigned int nrA = A.
getRows();
687 unsigned int nrB = B.
getRows();
689 if ((nrA == 0) && (nrB == 0)) {
705 C.
resize(nrA + nrB,
false);
707 for (
unsigned int i = 0; i < nrA; ++i) {
711 for (
unsigned int i = 0; i < nrB; ++i) {
718 if ((v.data ==
nullptr) || (v.size() == 0)) {
723 double mean = v.sum();
725 return mean / v.getRows();
730 if ((v.data ==
nullptr) || (v.size() == 0)) {
734 std::vector<double> vectorOfDoubles(v.data, v.data + v.rowNum);
741 if ((v.data ==
nullptr) || (v.size() == 0)) {
744#if defined(VISP_HAVE_SIMDLIB)
745 return SimdVectorStdev(v.data, v.rowNum, useBesselCorrection);
747 double mean_value = v.sum() / v.size();
748 double sum_squared_diff = 0.0;
749 unsigned int v_size = v.size();
750 for (
size_t i = 0; i < v_size; ++i) {
751 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
754 double divisor =
static_cast<double>(v.size());
755 if (useBesselCorrection) {
756 divisor = divisor - 1;
759 return std::sqrt(sum_squared_diff / divisor);
766 const unsigned int rows_size = 3;
767 if (v.getRows() != rows_size) {
772 M.
resize(rows_size, rows_size,
false,
false);
773 const unsigned int index_0 = 0;
774 const unsigned int index_1 = 1;
775 const unsigned int index_2 = 2;
776 M[index_0][index_0] = 0;
777 M[index_0][index_1] = -v[index_2];
778 M[index_0][index_2] = v[index_1];
779 M[index_1][index_0] = v[index_2];
780 M[index_1][index_1] = 0;
781 M[index_1][index_2] = -v[index_0];
782 M[index_2][index_0] = -v[index_1];
783 M[index_2][index_1] = v[index_0];
784 M[index_2][index_2] = 0;
791 const unsigned int val_3 = 3;
794 "Cannot compute the cross product between column "
795 "vector with dimension %d and %d",
811 if (
dsize != (nrows * ncols)) {
816 M.
resize(nrows, ncols,
false,
false);
819 for (
unsigned int j = 0; j < ncols; ++j) {
820 for (
unsigned int i = 0; i < nrows; ++i) {
821 M[i][j] =
data[(j * nrows) + i];
828 if ((i + v.size()) >(this->size())) {
832 if ((
data !=
nullptr) && (v.data !=
nullptr) && (v.rowNum > 0)) {
833 memcpy(
data + i, v.data,
sizeof(
double) * v.rowNum);
839 typedef std::string::size_type size_type;
844 std::vector<std::string> values(m * n);
845 std::ostringstream oss;
846 std::ostringstream ossFixed;
847 std::ios_base::fmtflags original_flags = oss.flags();
850 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
852 size_type maxBefore = 0;
853 size_type maxAfter = 0;
855 for (
unsigned int i = 0; i < m; ++i) {
858 if (oss.str().find(
"e") != std::string::npos) {
860 ossFixed << (*this)[i];
861 oss.str(ossFixed.str());
864 values[i] = oss.str();
865 size_type thislen = values[i].size();
866 size_type p = values[i].find(
'.');
868 if (p == std::string::npos) {
878 size_type totalLength = length;
882 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
893 s <<
"[" << m <<
"," << n <<
"]=\n";
895 for (
unsigned int i = 0; i < m; ++i) {
897 size_type p = values[i].find(
'.');
898 s.setf(std::ios::right, std::ios::adjustfield);
899 s.width(
static_cast<std::streamsize
>(maxBefore));
900 s << values[i].substr(0, p).c_str();
903 s.setf(std::ios::left, std::ios::adjustfield);
904 if (p != std::string::npos) {
905 s.width(
static_cast<std::streamsize
>(maxAfter));
906 s << values[i].substr(p, maxAfter).c_str();
909 assert(maxAfter > 1);
910 s.width(
static_cast<std::streamsize
>(maxAfter));
920 s.flags(original_flags);
922 return static_cast<int>(maxBefore + maxAfter);
927#if defined(VISP_HAVE_SIMDLIB)
931 for (
unsigned int i = 0; i <
rowNum; ++i) {
940#if defined(VISP_HAVE_SIMDLIB)
943 double sum_square = 0.0;
944 for (
unsigned int i = 0; i <
rowNum; ++i) {
945 sum_square += (*this)[i] * (*this)[i];
960 if ((v.getRows() !=
rowNum) || (v.getCols() !=
colNum)) {
966#if defined(VISP_HAVE_SIMDLIB)
969 for (
unsigned int i = 0; i <
dsize; ++i) {
979 for (
unsigned int i = 0; i <
rowNum; ++i) {
980 double x = fabs((*
this)[i]);
990 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
992 unsigned int rows_nbr = this->
getRows();
993 for (
unsigned int i = 0; i < rows_nbr; ++i) {
996 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
999 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1000 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
1001 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[i]))[k]) <<
"; " << std::endl;
1005 std::cout << std::endl;
1011 unsigned int rows_nbr = this->
getRows();
1012 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1022 unsigned int rows_nbr = this->
getRows();
1023 os <<
"([ " << std::endl;
1024 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1026 os << (*this)[i] <<
", ";
1027 os <<
"]," << std::endl;
1029 os <<
"])" << std::endl;
1035 unsigned int rows_nbr = this->
getRows();
1037 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1038 os << (*this)[i] <<
", ";
1039 if (this->
getRows() != (i + 1)) {
1040 os <<
";" << std::endl;
1043 os <<
"]" << std::endl;
1049#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
unsigned int getCols() const
Type * data
Address of the first element of the data array.
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)
static vpArray2D< Type > view(const vpArray2D< Type > &A)
Creates a view of the Matrix A. A view shares the same underlying memory as the original array....
unsigned int size() const
unsigned int getRows() const
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
vpColVector & operator+=(const vpColVector &v)
double operator*(const vpColVector &v) const
static double dotProd(const vpColVector &a, const vpColVector &b)
vpColVector operator-() const
vpColVector & operator*=(double x)
int print(std::ostream &s, unsigned int length, char const *intro=nullptr) const
vpColVector & operator-=(const vpColVector &v)
std::ostream & matlabPrint(std::ostream &os) const
VP_DEPRECATED double euclideanNorm() const
vpColVector & operator=(const vpColVector &v)
vpColVector operator/(double x) const
vpColVector & normalize()
static double median(const vpColVector &v)
vpColVector hadamard(const vpColVector &v) const
std::ostream & csvPrint(std::ostream &os) const
std::ostream & maplePrint(std::ostream &os) const
vpColVector & operator,(double val)
bool operator==(const vpColVector &v) const
vpColVector & operator/=(double x)
static vpColVector invSort(const vpColVector &v)
bool operator!=(const vpColVector &v) const
static vpMatrix skew(const vpColVector &v)
std::vector< double > toStdVector() const
static double mean(const vpColVector &v)
static vpColVector view(double *raw_data, unsigned int rows)
Create a column vector view of a raw data array. The view can modify the contents of the raw data arr...
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
double infinityNorm() const
vpColVector & operator<<(const vpColVector &v)
vpRowVector transpose() const
static double stdev(const vpColVector &v, bool useBesselCorrection=false)
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
double frobeniusNorm() const
VP_DEPRECATED vpColVector rows(unsigned int first_row, unsigned int last_row) const
vpColVector operator+(const vpColVector &v) const
static vpColVector sort(const vpColVector &v)
void insert(unsigned int i, const vpColVector &v)
VP_DEPRECATED void init()
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
static double getMedian(const std::vector< double > &v)
static Type maximum(const Type &a, const Type &b)
static bool equal(double x, double y, double threshold=0.001)
Implementation of a pose vector and operations on poses.
Implementation of a generic rotation vector.
Implementation of row vector and the associated operations.
Class that consider the case of a translation vector.