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 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) 62 #include <emmintrin.h> 63 #define VISP_HAVE_SSE2 1 75 for (
unsigned int i = 0; i <
rowNum; i++)
76 r[i] = (*
this)[i] + v[i];
108 for (
unsigned int i = 0; i < 3; i++)
109 s[i] = (*
this)[i] + t[i];
122 for (
unsigned int i = 0; i <
rowNum; i++)
134 for (
unsigned int i = 0; i <
rowNum; i++)
150 "Cannot compute the dot product between column vectors " 151 "with different dimensions (%d) and (%d)",
156 for (
unsigned int i = 0; i <
rowNum; i++)
157 r += (*
this)[i] * v[i];
173 for (
unsigned int i = 0; i <
rowNum; i++) {
174 for (
unsigned int j = 0; j < v.
getCols(); j++) {
175 M[i][j] = (*this)[i] * v[j];
186 "Bad size during vpColVector (%dx1) and vpColVector " 187 "(%dx1) substraction",
192 for (
unsigned int i = 0; i <
rowNum; i++)
193 v[i] = (*
this)[i] - m[i];
254 unsigned int rnrows = r + nrows;
263 for (
unsigned int i = r; i < rnrows; i++)
264 (*
this)[i - r] = v[i];
269 for (
unsigned int i = 0; i < v.
size(); i++)
275 for (
unsigned int i = 0; i < p.
size(); i++)
281 for (
unsigned int i = 0; i < v.
size(); i++)
288 for (
unsigned int i = 0; i < M.
getCols(); i++)
289 (*
this)[i] = M[i][j];
305 for (
unsigned int i = 0; i < M.
getRows(); i++)
306 (*
this)[i] = M[i][0];
314 for (
unsigned int i = 0; i < v.size(); i++)
322 for (
unsigned int i = 0; i < v.size(); i++)
323 (*
this)[i] = (double)(v[i]);
326 #ifdef VISP_HAVE_CPP11_COMPATIBILITY 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++) {
634 for (
unsigned int i = 0; i <
rowNum; i++)
645 std::vector<double> v(this->
size());
647 for (
unsigned int i = 0; i < this->
size(); i++)
652 #ifdef VISP_HAVE_CPP11_COMPATIBILITY 655 if (
this != &other) {
667 other.rowPtrs = NULL;
681 for (
unsigned int i = 0; i <
rowNum; i++) {
690 return !(*
this == v);
735 if (a.
data == NULL) {
738 if (b.
data == NULL) {
743 "Cannot compute the dot product between column vectors " 744 "with different dimensions (%d) and (%d)",
752 for (
unsigned int i = 0; i < a.
getRows(); i++)
753 c += *(ad++) * *(bd++);
786 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
787 *
this /= sqrt(sum_square);
823 if (v.
data == NULL) {
828 unsigned int nb_permutation = 1;
830 while (nb_permutation != 0) {
832 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
833 if ((tab[j] > tab[j - 1])) {
875 if (v.
data == NULL) {
880 unsigned int nb_permutation = 1;
882 while (nb_permutation != 0) {
884 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
885 if ((tab[j] < tab[j - 1])) {
986 unsigned int nrA = A.
getRows();
987 unsigned int nrB = B.
getRows();
989 if (nrA == 0 && nrB == 0) {
1005 C.
resize(nrA + nrB,
false);
1007 for (
unsigned int i = 0; i < nrA; i++)
1010 for (
unsigned int i = 0; i < nrB; i++)
1019 if (v.
data == NULL || v.
size() == 0) {
1039 if (v.
data == NULL || v.
size() == 0) {
1053 if (v.
data == NULL || v.
size() == 0) {
1057 double mean_value =
mean(v);
1058 double sum_squared_diff = 0.0;
1063 __m128d v_sub, v_mul, v_sum = _mm_setzero_pd();
1064 __m128d v_mean = _mm_set1_pd(mean_value);
1067 for (; i <= v.
getRows() - 4; i += 4) {
1068 v_sub = _mm_sub_pd(_mm_loadu_pd(v.
data + i), v_mean);
1069 v_mul = _mm_mul_pd(v_sub, v_sub);
1070 v_sum = _mm_add_pd(v_mul, v_sum);
1072 v_sub = _mm_sub_pd(_mm_loadu_pd(v.
data + i + 2), v_mean);
1073 v_mul = _mm_mul_pd(v_sub, v_sub);
1074 v_sum = _mm_add_pd(v_mul, v_sum);
1079 _mm_storeu_pd(res, v_sum);
1081 sum_squared_diff = res[0] + res[1];
1090 for (; i < v.
getRows(); i++) {
1091 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
1094 double divisor = (double)v.
size();
1095 if (useBesselCorrection && v.
size() > 1) {
1096 divisor = divisor - 1;
1099 return std::sqrt(sum_squared_diff / divisor);
1124 M.
resize(3, 3,
false,
false);
1152 "Cannot compute the cross product between column " 1153 "vector with dimension %d and %d",
1232 if (
dsize != nrows * ncols) {
1237 M.
resize(nrows, ncols,
false,
false);
1239 for (
unsigned int j = 0; j < ncols; j++)
1240 for (
unsigned int i = 0; i < nrows; i++)
1241 M[i][j] =
data[j * nrows + i];
1307 typedef std::string::size_type size_type;
1312 std::vector<std::string> values(m * n);
1313 std::ostringstream oss;
1314 std::ostringstream ossFixed;
1315 std::ios_base::fmtflags original_flags = oss.flags();
1318 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1320 size_type maxBefore = 0;
1321 size_type maxAfter = 0;
1323 for (
unsigned int i = 0; i < m; ++i) {
1326 if (oss.str().find(
"e") != std::string::npos) {
1328 ossFixed << (*this)[i];
1329 oss.str(ossFixed.str());
1332 values[i] = oss.str();
1333 size_type thislen = values[i].size();
1334 size_type p = values[i].find(
'.');
1336 if (p == std::string::npos) {
1345 size_type totalLength = length;
1349 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1358 s <<
"[" << m <<
"," << n <<
"]=\n";
1360 for (
unsigned int i = 0; i < m; i++) {
1362 size_type p = values[i].find(
'.');
1363 s.setf(std::ios::right, std::ios::adjustfield);
1364 s.width((std::streamsize)maxBefore);
1365 s << values[i].substr(0, p).c_str();
1368 s.setf(std::ios::left, std::ios::adjustfield);
1369 if (p != std::string::npos) {
1370 s.width((std::streamsize)maxAfter);
1371 s << values[i].substr(p, maxAfter).c_str();
1373 assert(maxAfter > 1);
1374 s.width((std::streamsize)maxAfter);
1384 s.flags(original_flags);
1386 return (
int)(maxBefore + maxAfter);
1401 __m128d v_sum1 = _mm_setzero_pd(), v_sum2 = _mm_setzero_pd(), v_sum;
1404 for (; i <=
rowNum - 4; i += 4) {
1405 v_sum1 = _mm_add_pd(_mm_loadu_pd(
data + i), v_sum1);
1406 v_sum2 = _mm_add_pd(_mm_loadu_pd(
data + i + 2), v_sum2);
1410 v_sum = _mm_add_pd(v_sum1, v_sum2);
1413 _mm_storeu_pd(res, v_sum);
1415 sum = res[0] + res[1];
1424 for (; i <
rowNum; i++) {
1439 double sum_square = 0.0;
1444 __m128d v_mul1, v_mul2;
1445 __m128d v_sum = _mm_setzero_pd();
1448 for (; i <=
rowNum - 4; i += 4) {
1449 v_mul1 = _mm_mul_pd(_mm_loadu_pd(
data + i), _mm_loadu_pd(
data + i));
1450 v_mul2 = _mm_mul_pd(_mm_loadu_pd(
data + i + 2), _mm_loadu_pd(
data + i + 2));
1452 v_sum = _mm_add_pd(v_mul1, v_sum);
1453 v_sum = _mm_add_pd(v_mul2, v_sum);
1458 _mm_storeu_pd(res, v_sum);
1460 sum_square = res[0] + res[1];
1470 for (; i <
rowNum; i++) {
1471 sum_square += (*this)[i] * (*this)[i];
1515 for (; i <=
dsize - 2; i += 2) {
1516 __m128d vout = _mm_mul_pd(_mm_loadu_pd(
data + i), _mm_loadu_pd(v.
data + i));
1517 _mm_storeu_pd(out.
data + i, vout);
1522 for (; i <
dsize; i++) {
1543 for (
unsigned int i = 0; i <
rowNum; i++) {
1544 double x = fabs((*
this)[i]);
1582 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
1584 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1587 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
1589 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1590 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
1591 << (
unsigned int)((
unsigned char *)&((*this)[i]))[k] <<
"; " << std::endl;
1595 std::cout << std::endl;
1627 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1662 os <<
"([ " << std::endl;
1663 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1665 os << (*this)[i] <<
", ";
1666 os <<
"]," << std::endl;
1668 os <<
"])" << std::endl;
1711 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1712 os << (*this)[i] <<
", ";
1713 if (this->
getRows() != i + 1) {
1714 os <<
";" << std::endl;
1716 os <<
"]" << std::endl;
1722 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 1742 #endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS) bool operator==(const vpColVector &v) const
Comparison operator.
Implementation of a matrix and operations on matrices.
Implementation of a generic rotation vector.
vp_deprecated void init()
static vpColVector invSort(const vpColVector &v)
static vpColVector sort(const vpColVector &v)
static double stdev(const vpColVector &v, const bool useBesselCorrection=false)
double euclideanNorm() const
Implementation of row vector and the associated operations.
std::ostream & matlabPrint(std::ostream &os) const
static double getMedian(const std::vector< double > &v)
vpColVector operator*(const double &x, const vpColVector &v)
vpColVector operator/(const double x) const
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
static bool equal(double x, double y, double s=0.001)
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
error that can be emited by ViSP classes.
std::ostream & csvPrint(std::ostream &os) const
double * data
Address of the first element of the data array.
Implementation of a generic 2D array used as vase class of matrices and vectors.
vpColVector & operator*=(double x)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
vpColVector operator-() const
static double median(const vpColVector &v)
static Type maximum(const Type &a, const Type &b)
vpColVector & operator/=(double x)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
bool operator!=(const vpColVector &v) const
unsigned int rowNum
Number of rows in the array.
double infinityNorm() const
vpColVector & normalize()
vpColVector hadamard(const vpColVector &v) const
std::ostream & maplePrint(std::ostream &os) const
VISP_EXPORT bool checkSSE2()
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpColVector & operator<<(const vpColVector &v)
static double mean(const vpColVector &v)
unsigned int getRows() const
vpColVector & operator-=(vpColVector v)
Operator that allows to substract two column vectors.
unsigned int colNum
Number of columns in the array.
void insert(unsigned int i, const vpColVector &v)
std::vector< double > toStdVector()
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = v.
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
Implementation of column vector and the associated operations.
static double dotProd(const vpColVector &a, const vpColVector &b)
vpRowVector transpose() const
Implementation of a pose vector and operations on poses.
vpColVector()
Basic constructor that creates an empty 0-size column vector.
static vpMatrix skew(const vpColVector &v)
unsigned int dsize
Current array size (rowNum * colNum)
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static vpColVector crossProd(const vpColVector &a, const vpColVector &b)
double operator*(const vpColVector &x) const
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
void resize(const unsigned int i, const bool flagNullify=true)