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);
770 for (
unsigned int i = 0; i <
rowNum; i++) {
786 for (
unsigned int i = 0; i <
rowNum; i++) {
851 if (a.
data == NULL) {
854 if (b.
data == NULL) {
859 "Cannot compute the dot product between column vectors "
860 "with different dimensions (%d) and (%d)",
868 for (
unsigned int i = 0; i < a.
getRows(); i++)
869 c += *(ad++) * *(bd++);
909 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
910 *
this /= sqrt(sum_square);
946 if (v.
data == NULL) {
951 unsigned int nb_permutation = 1;
953 while (nb_permutation != 0) {
955 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
956 if ((tab[j] > tab[j - 1])) {
998 if (v.
data == NULL) {
1003 unsigned int nb_permutation = 1;
1005 while (nb_permutation != 0) {
1007 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
1008 if ((tab[j] < tab[j - 1])) {
1009 double tmp = tab[j];
1010 tab[j] = tab[j - 1];
1109 unsigned int nrA = A.
getRows();
1110 unsigned int nrB = B.
getRows();
1112 if (nrA == 0 && nrB == 0) {
1128 C.
resize(nrA + nrB,
false);
1130 for (
unsigned int i = 0; i < nrA; i++)
1133 for (
unsigned int i = 0; i < nrB; i++)
1142 if (v.
data == NULL || v.
size() == 0) {
1162 if (v.
data == NULL || v.
size() == 0) {
1176 if (v.
data == NULL || v.
size() == 0) {
1180 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
1205 M.
resize(3, 3,
false,
false);
1232 "Cannot compute the cross product between column "
1233 "vector with dimension %d and %d",
1312 if (
dsize != nrows * ncols) {
1317 M.
resize(nrows, ncols,
false,
false);
1319 for (
unsigned int j = 0; j < ncols; j++)
1320 for (
unsigned int i = 0; i < nrows; i++)
1321 M[i][j] =
data[j * nrows + i];
1358 if (i + v.
size() > this->size())
1387 typedef std::string::size_type size_type;
1392 std::vector<std::string> values(m * n);
1393 std::ostringstream oss;
1394 std::ostringstream ossFixed;
1395 std::ios_base::fmtflags original_flags = oss.flags();
1398 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1400 size_type maxBefore = 0;
1401 size_type maxAfter = 0;
1403 for (
unsigned int i = 0; i < m; ++i) {
1406 if (oss.str().find(
"e") != std::string::npos) {
1408 ossFixed << (*this)[i];
1409 oss.str(ossFixed.str());
1412 values[i] = oss.str();
1413 size_type thislen = values[i].size();
1414 size_type p = values[i].find(
'.');
1416 if (p == std::string::npos) {
1425 size_type totalLength = length;
1429 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1438 s <<
"[" << m <<
"," << n <<
"]=\n";
1440 for (
unsigned int i = 0; i < m; i++) {
1442 size_type p = values[i].find(
'.');
1443 s.setf(std::ios::right, std::ios::adjustfield);
1444 s.width((std::streamsize)maxBefore);
1445 s << values[i].substr(0, p).c_str();
1448 s.setf(std::ios::left, std::ios::adjustfield);
1449 if (p != std::string::npos) {
1450 s.width((std::streamsize)maxAfter);
1451 s << values[i].substr(p, maxAfter).c_str();
1453 assert(maxAfter > 1);
1454 s.width((std::streamsize)maxAfter);
1464 s.flags(original_flags);
1466 return (
int)(maxBefore + maxAfter);
1545 for (
unsigned int i = 0; i <
rowNum; i++) {
1546 double x = fabs((*
this)[i]);
1584 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
1586 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1589 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
1591 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1592 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
1593 << (
unsigned int)((
unsigned char *)&((*this)[i]))[k] <<
"; " << std::endl;
1597 std::cout << std::endl;
1629 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1664 os <<
"([ " << std::endl;
1665 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1667 os << (*this)[i] <<
", ";
1668 os <<
"]," << std::endl;
1670 os <<
"])" << std::endl;
1713 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1714 os << (*this)[i] <<
", ";
1715 if (this->
getRows() != i + 1) {
1716 os <<
";" << std::endl;
1718 os <<
"]" << std::endl;
1724 #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 threshold=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.