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++)
639 #ifdef VISP_HAVE_CPP11_COMPATIBILITY 642 if (
this != &other) {
654 other.rowPtrs = NULL;
705 if (a.
data == NULL) {
708 if (b.
data == NULL) {
713 "Cannot compute the dot product between column vectors " 714 "with different dimensions (%d) and (%d)",
722 for (
unsigned int i = 0; i < a.
getRows(); i++)
723 c += *(ad++) * *(bd++);
756 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon())
757 *
this /= sqrt(sum_square);
769 if (v.
data == NULL) {
774 unsigned int nb_permutation = 1;
776 while (nb_permutation != 0) {
778 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
779 if ((tab[j] > tab[j - 1])) {
798 if (v.
data == NULL) {
803 unsigned int nb_permutation = 1;
805 while (nb_permutation != 0) {
807 for (
unsigned int j = v.
getRows() - 1; j >= i + 1; j--) {
808 if ((tab[j] < tab[j - 1])) {
909 unsigned int nrA = A.
getRows();
910 unsigned int nrB = B.
getRows();
912 if (nrA == 0 && nrB == 0) {
928 C.
resize(nrA + nrB,
false);
930 for (
unsigned int i = 0; i < nrA; i++)
933 for (
unsigned int i = 0; i < nrB; i++)
942 if (v.
data == NULL || v.
size() == 0) {
962 if (v.
data == NULL || v.
size() == 0) {
976 if (v.
data == NULL || v.
size() == 0) {
980 double mean_value =
mean(v);
981 double sum_squared_diff = 0.0;
986 __m128d v_sub, v_mul, v_sum = _mm_setzero_pd();
987 __m128d v_mean = _mm_set1_pd(mean_value);
990 for (; i <= v.
getRows() - 4; i += 4) {
991 v_sub = _mm_sub_pd(_mm_loadu_pd(v.
data + i), v_mean);
992 v_mul = _mm_mul_pd(v_sub, v_sub);
993 v_sum = _mm_add_pd(v_mul, v_sum);
995 v_sub = _mm_sub_pd(_mm_loadu_pd(v.
data + i + 2), v_mean);
996 v_mul = _mm_mul_pd(v_sub, v_sub);
997 v_sum = _mm_add_pd(v_mul, v_sum);
1002 _mm_storeu_pd(res, v_sum);
1004 sum_squared_diff = res[0] + res[1];
1013 for (; i < v.
getRows(); i++) {
1014 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
1017 double divisor = (double)v.
size();
1018 if (useBesselCorrection && v.
size() > 1) {
1019 divisor = divisor - 1;
1022 return std::sqrt(sum_squared_diff / divisor);
1047 M.
resize(3, 3,
false,
false);
1075 "Cannot compute the cross product between column " 1076 "vector with dimension %d and %d",
1155 if (
dsize != nrows * ncols) {
1160 M.
resize(nrows, ncols,
false,
false);
1162 for (
unsigned int j = 0; j < ncols; j++)
1163 for (
unsigned int i = 0; i < nrows; i++)
1164 M[i][j] =
data[j * nrows + i];
1230 typedef std::string::size_type size_type;
1235 std::vector<std::string> values(m * n);
1236 std::ostringstream oss;
1237 std::ostringstream ossFixed;
1238 std::ios_base::fmtflags original_flags = oss.flags();
1241 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1243 size_type maxBefore = 0;
1244 size_type maxAfter = 0;
1246 for (
unsigned int i = 0; i < m; ++i) {
1249 if (oss.str().find(
"e") != std::string::npos) {
1251 ossFixed << (*this)[i];
1252 oss.str(ossFixed.str());
1255 values[i] = oss.str();
1256 size_type thislen = values[i].size();
1257 size_type p = values[i].find(
'.');
1259 if (p == std::string::npos) {
1268 size_type totalLength = length;
1272 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1281 s <<
"[" << m <<
"," << n <<
"]=\n";
1283 for (
unsigned int i = 0; i < m; i++) {
1285 size_type p = values[i].find(
'.');
1286 s.setf(std::ios::right, std::ios::adjustfield);
1287 s.width((std::streamsize)maxBefore);
1288 s << values[i].substr(0, p).c_str();
1291 s.setf(std::ios::left, std::ios::adjustfield);
1292 if (p != std::string::npos) {
1293 s.width((std::streamsize)maxAfter);
1294 s << values[i].substr(p, maxAfter).c_str();
1296 assert(maxAfter > 1);
1297 s.width((std::streamsize)maxAfter);
1307 s.flags(original_flags);
1309 return (
int)(maxBefore + maxAfter);
1324 __m128d v_sum1 = _mm_setzero_pd(), v_sum2 = _mm_setzero_pd(), v_sum;
1327 for (; i <=
rowNum - 4; i += 4) {
1328 v_sum1 = _mm_add_pd(_mm_loadu_pd(
data + i), v_sum1);
1329 v_sum2 = _mm_add_pd(_mm_loadu_pd(
data + i + 2), v_sum2);
1333 v_sum = _mm_add_pd(v_sum1, v_sum2);
1336 _mm_storeu_pd(res, v_sum);
1338 sum = res[0] + res[1];
1347 for (; i <
rowNum; i++) {
1362 double sum_square = 0.0;
1367 __m128d v_mul1, v_mul2;
1368 __m128d v_sum = _mm_setzero_pd();
1371 for (; i <=
rowNum - 4; i += 4) {
1372 v_mul1 = _mm_mul_pd(_mm_loadu_pd(
data + i), _mm_loadu_pd(
data + i));
1373 v_mul2 = _mm_mul_pd(_mm_loadu_pd(
data + i + 2), _mm_loadu_pd(
data + i + 2));
1375 v_sum = _mm_add_pd(v_mul1, v_sum);
1376 v_sum = _mm_add_pd(v_mul2, v_sum);
1381 _mm_storeu_pd(res, v_sum);
1383 sum_square = res[0] + res[1];
1393 for (; i <
rowNum; i++) {
1394 sum_square += (*this)[i] * (*this)[i];
1438 for (; i <=
dsize - 2; i += 2) {
1439 __m128d vout = _mm_mul_pd(_mm_loadu_pd(
data + i), _mm_loadu_pd(v.
data + i));
1440 _mm_storeu_pd(out.
data + i, vout);
1445 for (; i <
dsize; i++) {
1466 for (
unsigned int i = 0; i <
rowNum; i++) {
1467 double x = fabs((*
this)[i]);
1505 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
1507 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1510 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
1512 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1513 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
1514 << (
unsigned int)((
unsigned char *)&((*this)[i]))[k] <<
"; " << std::endl;
1518 std::cout << std::endl;
1550 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1585 os <<
"([ " << std::endl;
1586 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1588 os << (*this)[i] <<
", ";
1589 os <<
"]," << std::endl;
1591 os <<
"])" << std::endl;
1634 for (
unsigned int i = 0; i < this->
getRows(); ++i) {
1635 os << (*this)[i] <<
", ";
1636 if (this->
getRows() != i + 1) {
1637 os <<
";" << std::endl;
1639 os <<
"]" << std::endl;
1645 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) 1665 #endif // defined(VISP_BUILD_DEPRECATED_FUNCTIONS) double euclideanNorm() const
Implementation of a matrix and operations on matrices.
Implementation of a generic rotation vector.
double operator*(const vpColVector &x) const
vp_deprecated void init()
static vpColVector invSort(const vpColVector &v)
void stack(const double &d)
static vpColVector sort(const vpColVector &v)
static double stdev(const vpColVector &v, const bool useBesselCorrection=false)
Implementation of row vector and the associated operations.
static double getMedian(const std::vector< double > &v)
vpColVector operator*(const double &x, const vpColVector &v)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
error that can be emited by ViSP classes.
unsigned int getRows() 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.
static double median(const vpColVector &v)
static Type maximum(const Type &a, const Type &b)
unsigned int getCols() const
vpColVector & operator/=(double x)
vpColVector hadamard(const vpColVector &v) const
unsigned int rowNum
Number of rows in the array.
vpRowVector transpose() const
vpColVector & normalize()
std::ostream & csvPrint(std::ostream &os) const
double infinityNorm() const
VISP_EXPORT bool checkSSE2()
std::ostream & matlabPrint(std::ostream &os) const
vpColVector & operator<<(const vpColVector &v)
static double mean(const vpColVector &v)
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)
vpColVector & operator=(const vpColVector &v)
Copy operator. Allow operation such as A = v.
int print(std::ostream &s, unsigned int length, char const *intro=0) const
vpColVector & operator+=(vpColVector v)
Operator that allows to add two column vectors.
Implementation of column vector and the associated operations.
vpColVector operator/(const double x) const
static double dotProd(const vpColVector &a, const vpColVector &b)
vpColVector operator-() const
Implementation of a pose vector and operations on poses.
vpColVector()
Basic constructor that creates an empty 0-size column vector.
std::ostream & maplePrint(std::ostream &os) const
vpColVector operator+(const vpColVector &v) const
Operator that allows to add two column vectors.
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)
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) 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)