49 #include <visp3/core/vpCPUFeatures.h>
50 #include <visp3/core/vpColVector.h>
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/core/vpException.h>
53 #include <visp3/core/vpMath.h>
54 #include <visp3/core/vpRotationVector.h>
56 #include <Simd/SimdLib.hpp>
66 for (
unsigned int i = 0; i <
rowNum; i++)
67 r[i] = (*
this)[i] + v[i];
79 for (
unsigned int i = 0; i < 3; i++)
80 s[i] = (*
this)[i] +
t[i];
92 for (
unsigned int i = 0; i <
rowNum; i++)
104 for (
unsigned int i = 0; i <
rowNum; i++)
113 "Cannot compute the dot product between column vectors "
114 "with different dimensions (%d) and (%d)",
119 for (
unsigned int i = 0; i <
rowNum; i++)
120 r += (*
this)[i] * v[i];
127 for (
unsigned int i = 0; i <
rowNum; i++) {
128 for (
unsigned int j = 0; j < v.
getCols(); j++) {
129 M[i][j] = (*this)[i] * v[j];
139 "Bad size during vpColVector (%dx1) and vpColVector "
140 "(%dx1) subtraction",
145 for (
unsigned int i = 0; i <
rowNum; i++)
146 v[i] = (*
this)[i] - m[i];
157 unsigned int rnrows = r + nrows;
166 for (
unsigned int i = r; i < rnrows; i++)
167 (*
this)[i - r] = v[i];
172 for (
unsigned int i = 0; i < v.
size(); i++)
178 for (
unsigned int i = 0; i < p.
size(); i++)
184 for (
unsigned int i = 0; i < v.
size(); i++)
190 for (
unsigned int i = 0; i < M.
getCols(); i++)
191 (*
this)[i] = M[i][j];
201 for (
unsigned int i = 0; i < M.
getRows(); i++)
202 (*
this)[i] = M[i][0];
207 for (
unsigned int i = 0; i < v.size(); i++)
213 for (
unsigned int i = 0; i < v.size(); i++)
214 (*
this)[i] = (double)(v[i]);
240 for (
unsigned int i = 0; i <
rowNum; i++)
253 for (
unsigned int i = 0; i <
rowNum; i++)
254 *(vd++) = (*d++) * x;
260 for (
unsigned int i = 0; i <
rowNum; i++)
267 for (
unsigned int i = 0; i <
rowNum; i++)
279 for (
unsigned int i = 0; i <
rowNum; i++)
280 *(vd++) = (*d++) / x;
299 resize((
unsigned int)v.size(),
false);
300 for (
unsigned int i = 0; i < v.size(); i++)
307 resize((
unsigned int)v.size(),
false);
308 for (
unsigned int i = 0; i < v.size(); i++)
309 (*
this)[i] = (float)v[i];
315 unsigned int k = v.
rowNum;
365 for (
unsigned int i = 0; i <
rowNum; i++) {
366 for (
unsigned int j = 0; j <
colNum; j++) {
391 for (
unsigned int i = 0; i <
rowNum; i++)
398 std::vector<double> v(this->
size());
400 for (
unsigned int i = 0; i < this->
size(); i++)
407 if (
this != &other) {
419 other.rowPtrs =
nullptr;
421 other.data =
nullptr;
429 resize(
static_cast<unsigned int>(list.size()),
false);
430 std::copy(list.begin(), list.end(),
data);
439 for (
unsigned int i = 0; i <
rowNum; i++) {
449 for (
unsigned int i = 0; i <
rowNum; i++) {
481 if (a.
data ==
nullptr) {
484 if (b.
data ==
nullptr) {
489 "Cannot compute the dot product between column vectors "
490 "with different dimensions (%d) and (%d)",
498 for (
unsigned int i = 0; i < a.
getRows(); i++)
499 c += *(ad++) * *(bd++);
518 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
519 *
this /= sqrt(sum_square);
527 if (v.
data ==
nullptr) {
532 unsigned int nb_permutation = 1;
534 while (nb_permutation != 0) {
536 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
537 if ((tab[j] > tab[j - 1])) {
552 if (v.
data ==
nullptr) {
557 unsigned int nb_permutation = 1;
559 while (nb_permutation != 0) {
561 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
562 if ((tab[j] < tab[j - 1])) {
592 unsigned int nrA = A.
getRows();
593 unsigned int nrB = B.
getRows();
595 if (nrA == 0 && nrB == 0) {
611 C.
resize(nrA + nrB,
false);
613 for (
unsigned int i = 0; i < nrA; i++)
616 for (
unsigned int i = 0; i < nrB; i++)
622 if (v.
data ==
nullptr || v.
size() == 0) {
634 if (v.
data ==
nullptr || v.
size() == 0) {
645 if (v.
data ==
nullptr || v.
size() == 0) {
649 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
660 M.
resize(3, 3,
false,
false);
678 "Cannot compute the cross product between column "
679 "vector with dimension %d and %d",
695 if (
dsize != nrows * ncols) {
700 M.
resize(nrows, ncols,
false,
false);
702 for (
unsigned int j = 0; j < ncols; j++)
703 for (
unsigned int i = 0; i < nrows; i++)
704 M[i][j] =
data[j * nrows + i];
709 if (i + v.
size() > this->size())
719 typedef std::string::size_type size_type;
724 std::vector<std::string> values(m * n);
725 std::ostringstream oss;
726 std::ostringstream ossFixed;
727 std::ios_base::fmtflags original_flags = oss.flags();
730 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
732 size_type maxBefore = 0;
733 size_type maxAfter = 0;
735 for (
unsigned int i = 0; i < m; ++i) {
738 if (oss.str().find(
"e") != std::string::npos) {
740 ossFixed << (*this)[i];
741 oss.str(ossFixed.str());
744 values[i] = oss.str();
745 size_type thislen = values[i].size();
746 size_type p = values[i].find(
'.');
748 if (p == std::string::npos) {
758 size_type totalLength = length;
762 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
771 s <<
"[" << m <<
"," << n <<
"]=\n";
773 for (
unsigned int i = 0; i < m; i++) {
775 size_type p = values[i].find(
'.');
776 s.setf(std::ios::right, std::ios::adjustfield);
777 s.width((std::streamsize)maxBefore);
778 s << values[i].substr(0, p).c_str();
781 s.setf(std::ios::left, std::ios::adjustfield);
782 if (p != std::string::npos) {
783 s.width((std::streamsize)maxAfter);
784 s << values[i].substr(p, maxAfter).c_str();
787 assert(maxAfter > 1);
788 s.width((std::streamsize)maxAfter);
798 s.flags(original_flags);
800 return (
int)(maxBefore + maxAfter);
831 for (
unsigned int i = 0; i <
rowNum; i++) {
832 double x = fabs((*
this)[i]);
842 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
844 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
847 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
850 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
851 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
852 << (
unsigned int)((
unsigned char *)&((*this)[i]))[k] <<
"; " << std::endl;
856 std::cout << std::endl;
862 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
872 os <<
"([ " << std::endl;
873 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
875 os << (*this)[i] <<
", ";
876 os <<
"]," << std::endl;
878 os <<
"])" << std::endl;
885 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
886 os << (*this)[i] <<
", ";
887 if (this->
getRows() != i + 1) {
888 os <<
";" << std::endl;
891 os <<
"]" << std::endl;
897 #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)
double operator*(const vpColVector &v) const
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)
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
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()
vpColVector operator+(const vpColVector &v) const
std::vector< double > toStdVector() const
static double mean(const vpColVector &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector & operator+=(vpColVector v)
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)
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 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 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.