54 #include <visp3/core/vpCPUFeatures.h>
55 #include <visp3/core/vpColVector.h>
56 #include <visp3/core/vpDebug.h>
57 #include <visp3/core/vpException.h>
58 #include <visp3/core/vpMath.h>
59 #include <visp3/core/vpRotationVector.h>
61 #include <Simd/SimdLib.hpp>
72 for (
unsigned int i = 0; i <
rowNum; i++)
73 r[i] = (*
this)[i] + v[i];
105 for (
unsigned int i = 0; i < 3; i++)
106 s[i] = (*
this)[i] +
t[i];
119 for (
unsigned int i = 0; i <
rowNum; i++)
131 for (
unsigned int i = 0; i <
rowNum; i++)
147 "Cannot compute the dot product between column vectors "
148 "with different dimensions (%d) and (%d)",
153 for (
unsigned int i = 0; i <
rowNum; i++)
154 r += (*
this)[i] * v[i];
170 for (
unsigned int i = 0; i <
rowNum; i++) {
171 for (
unsigned int j = 0; j < v.
getCols(); j++) {
172 M[i][j] = (*this)[i] * v[j];
183 "Bad size during vpColVector (%dx1) and vpColVector "
184 "(%dx1) subtraction",
189 for (
unsigned int i = 0; i <
rowNum; i++)
190 v[i] = (*
this)[i] - m[i];
251 unsigned int rnrows = r + nrows;
260 for (
unsigned int i = r; i < rnrows; i++)
261 (*
this)[i - r] = v[i];
266 for (
unsigned int i = 0; i < v.
size(); i++)
272 for (
unsigned int i = 0; i < p.
size(); i++)
278 for (
unsigned int i = 0; i < v.
size(); i++)
285 for (
unsigned int i = 0; i < M.
getCols(); i++)
286 (*
this)[i] = M[i][j];
302 for (
unsigned int i = 0; i < M.
getRows(); i++)
303 (*
this)[i] = M[i][0];
311 for (
unsigned int i = 0; i < v.size(); i++)
319 for (
unsigned int i = 0; i < v.size(); i++)
320 (*
this)[i] = (double)(v[i]);
323 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
361 for (
unsigned int i = 0; i <
rowNum; i++)
394 for (
unsigned int i = 0; i <
rowNum; i++)
395 *(vd++) = (*d++) * x;
419 for (
unsigned int i = 0; i <
rowNum; i++)
443 for (
unsigned int i = 0; i <
rowNum; i++)
474 for (
unsigned int i = 0; i <
rowNum; i++)
475 *(vd++) = (*d++) / x;
502 resize((
unsigned int)v.size(),
false);
503 for (
unsigned int i = 0; i < v.size(); i++)
512 resize((
unsigned int)v.size(),
false);
513 for (
unsigned int i = 0; i < v.size(); i++)
514 (*
this)[i] = (float)v[i];
520 unsigned int k = v.
rowNum;
621 for (
unsigned int i = 0; i <
rowNum; i++) {
622 for (
unsigned int j = 0; j <
colNum; j++) {
684 for (
unsigned int i = 0; i <
rowNum; i++)
695 std::vector<double> v(this->
size());
697 for (
unsigned int i = 0; i < this->
size(); i++)
702 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
708 if (
this != &other) {
720 other.rowPtrs = NULL;
753 resize(
static_cast<unsigned int>(list.size()),
false);
754 std::copy(list.begin(), list.end(),
data);
764 for (
unsigned int i = 0; i <
rowNum; i++) {
816 if (a.
data == NULL) {
819 if (b.
data == NULL) {
824 "Cannot compute the dot product between column vectors "
825 "with different dimensions (%d) and (%d)",
833 for (
unsigned int i = 0; i < a.
getRows(); i++)
834 c += *(ad++) * *(bd++);
874 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
875 *
this /= sqrt(sum_square);
911 if (v.
data == NULL) {
916 unsigned int nb_permutation = 1;
918 while (nb_permutation != 0) {
920 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
921 if ((tab[j] > tab[j - 1])) {
963 if (v.
data == NULL) {
968 unsigned int nb_permutation = 1;
970 while (nb_permutation != 0) {
972 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
973 if ((tab[j] < tab[j - 1])) {
1074 unsigned int nrA = A.
getRows();
1075 unsigned int nrB = B.
getRows();
1077 if (nrA == 0 && nrB == 0) {
1093 C.
resize(nrA + nrB,
false);
1095 for (
unsigned int i = 0; i < nrA; i++)
1098 for (
unsigned int i = 0; i < nrB; i++)
1107 if (v.
data == NULL || v.
size() == 0) {
1127 if (v.
data == NULL || v.
size() == 0) {
1141 if (v.
data == NULL || v.
size() == 0) {
1145 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
1170 M.
resize(3, 3,
false,
false);
1197 "Cannot compute the cross product between column "
1198 "vector with dimension %d and %d",
1277 if (
dsize != nrows * ncols) {
1282 M.
resize(nrows, ncols,
false,
false);
1284 for (
unsigned int j = 0; j < ncols; j++)
1285 for (
unsigned int i = 0; i < nrows; i++)
1286 M[i][j] =
data[j * nrows + i];
1323 if (i + v.
size() > this->size())
1352 typedef std::string::size_type size_type;
1357 std::vector<std::string> values(m * n);
1358 std::ostringstream oss;
1359 std::ostringstream ossFixed;
1360 std::ios_base::fmtflags original_flags = oss.flags();
1363 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1365 size_type maxBefore = 0;
1366 size_type maxAfter = 0;
1368 for (
unsigned int i = 0; i < m; ++i) {
1371 if (oss.str().find(
"e") != std::string::npos) {
1373 ossFixed << (*this)[i];
1374 oss.str(ossFixed.str());
1377 values[i] = oss.str();
1378 size_type thislen = values[i].size();
1379 size_type p = values[i].find(
'.');
1381 if (p == std::string::npos) {
1390 size_type totalLength = length;
1394 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1403 s <<
"[" << m <<
"," << n <<
"]=\n";
1405 for (
unsigned int i = 0; i < m; i++) {
1407 size_type p = values[i].find(
'.');
1408 s.setf(std::ios::right, std::ios::adjustfield);
1409 s.width((std::streamsize)maxBefore);
1410 s << values[i].substr(0, p).c_str();
1413 s.setf(std::ios::left, std::ios::adjustfield);
1414 if (p != std::string::npos) {
1415 s.width((std::streamsize)maxAfter);
1416 s << values[i].substr(p, maxAfter).c_str();
1418 assert(maxAfter > 1);
1419 s.width((std::streamsize)maxAfter);
1429 s.flags(original_flags);
1431 return (
int)(maxBefore + maxAfter);
1510 for (
unsigned int i = 0; i <
rowNum; i++) {
1511 double x = fabs((*
this)[i]);
1549 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
1551 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1554 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
1556 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1557 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
1558 << (
unsigned int)((
unsigned char *)&((*this)[i]))[k] <<
"; " << std::endl;
1562 std::cout << std::endl;
1594 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1629 os <<
"([ " << std::endl;
1630 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1632 os << (*this)[i] <<
", ";
1633 os <<
"]," << std::endl;
1635 os <<
"])" << std::endl;
1678 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1679 os << (*this)[i] <<
", ";
1680 if (this->
getRows() != i + 1) {
1681 os <<
";" << std::endl;
1683 os <<
"]" << std::endl;
1689 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
Implementation of a generic 2D array used as base class for matrices and vectors.
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 size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
unsigned int colNum
Number of columns in the array.
Implementation of column vector and the associated operations.
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static double dotProd(const vpColVector &a, const vpColVector &b)
vpColVector operator-() const
vpColVector & operator*=(double x)
std::ostream & matlabPrint(std::ostream &os) const
vp_deprecated double euclideanNorm() const
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = 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)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
bool operator==(const vpColVector &v) const
Comparison operator.
vpColVector & operator/=(double x)
static vpColVector invSort(const vpColVector &v)
bool operator!=(const vpColVector &v) const
static vpMatrix skew(const vpColVector &v)
vp_deprecated void init()
double operator*(const vpColVector &x) const
vpColVector()
Basic constructor that creates an empty 0-size column vector.
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
std::vector< double > toStdVector() const
static double mean(const vpColVector &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
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
vpColVector & operator-=(vpColVector v)
Operator that allows to subtract two column vectors.
static vpColVector sort(const vpColVector &v)
void insert(unsigned int i, const vpColVector &v)
void resize(unsigned int i, bool flagNullify=true)
error that can be emited 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 s=0.001)
Implementation of a matrix and operations on matrices.
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.