49 #include <visp3/core/vpCPUFeatures.h>
50 #include <visp3/core/vpColVector.h>
51 #include <visp3/core/vpException.h>
52 #include <visp3/core/vpMath.h>
53 #include <visp3/core/vpRotationVector.h>
55 #if defined(VISP_HAVE_SIMDLIB)
56 #include <Simd/SimdLib.h>
68 for (
unsigned int i = 0; i <
rowNum; ++i) {
69 r[i] = (*this)[i] + v[i];
82 const unsigned int val_3 = 3;
83 for (
unsigned int i = 0; i < val_3; ++i) {
84 s[i] = (*this)[i] +
t[i];
97 for (
unsigned int i = 0; i <
rowNum; ++i) {
110 for (
unsigned int i = 0; i <
rowNum; ++i) {
120 "Cannot compute the dot product between column vectors "
121 "with different dimensions (%d) and (%d)",
126 for (
unsigned int i = 0; i <
rowNum; ++i) {
127 r += (*this)[i] * v[i];
135 unsigned int v_cols = v.
getCols();
136 for (
unsigned int i = 0; i <
rowNum; ++i) {
137 for (
unsigned int j = 0; j < v_cols; ++j) {
138 M[i][j] = (*this)[i] * v[j];
148 "Bad size during vpColVector (%dx1) and vpMatrix (%dx%d) multiplication",
152 unsigned int M_cols = M.
getCols();
153 for (
unsigned int i = 0; i <
rowNum; ++i) {
154 for (
unsigned int j = 0; j < M_cols; ++j) {
155 R[i][j] = (*this)[i] * M[0][j];
165 "Bad size during vpColVector (%dx1) and vpColVector "
166 "(%dx1) subtraction",
171 for (
unsigned int i = 0; i <
rowNum; ++i) {
172 v[i] = (*this)[i] - m[i];
184 unsigned int rnrows = r + nrows;
192 if (this->
rowPtrs ==
nullptr) {
195 for (
unsigned int i = r; i < rnrows; ++i) {
196 (*this)[i - r] = v[i];
202 unsigned int v_size = v.
size();
203 for (
unsigned int i = 0; i < v_size; ++i) {
210 unsigned int p_size = p.
size();
211 for (
unsigned int i = 0; i < p_size; ++i) {
218 unsigned int v_size = v.
size();
219 for (
unsigned int i = 0; i < v_size; ++i) {
226 unsigned int m_cols = M.
getCols();
227 for (
unsigned int i = 0; i < m_cols; ++i) {
228 (*this)[i] = M[i][j];
239 unsigned int m_rows = M.
getRows();
240 for (
unsigned int i = 0; i < m_rows; ++i) {
241 (*this)[i] = M[i][0];
247 unsigned int v_size =
static_cast<unsigned int>(v.size());
248 for (
unsigned int i = 0; i < v_size; ++i) {
255 unsigned int v_size =
static_cast<unsigned int>(v.size());
256 for (
unsigned int i = 0; i < v_size; ++i) {
257 (*this)[i] =
static_cast<double>(v[i]);
261 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
286 for (
unsigned int i = 0; i <
rowNum; ++i) {
301 for (
unsigned int i = 0; i <
rowNum; ++i) {
303 *(vd++) = (*d++) * x;
310 for (
unsigned int i = 0; i <
rowNum; ++i) {
318 for (
unsigned int i = 0; i <
rowNum; ++i) {
331 for (
unsigned int i = 0; i <
rowNum; ++i) {
333 *(vd++) = (*d++) / x;
353 unsigned int v_size =
static_cast<unsigned int>(v.size());
355 for (
unsigned int i = 0; i < v_size; ++i) {
363 unsigned int v_size =
static_cast<unsigned int>(v.size());
365 for (
unsigned int i = 0; i < v_size; ++i) {
366 (*this)[i] =
static_cast<float>(v[i]);
373 unsigned int k = v.
rowNum;
423 for (
unsigned int i = 0; i <
rowNum; ++i) {
424 for (
unsigned int j = 0; j <
colNum; ++j) {
449 for (
unsigned int i = 0; i <
rowNum; ++i) {
457 std::vector<double> v(this->
size());
459 unsigned int v_this_size = this->
size();
460 for (
unsigned int i = 0; i < v_this_size; ++i) {
466 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
469 if (
this != &other) {
481 other.rowPtrs =
nullptr;
483 other.data =
nullptr;
491 resize(
static_cast<unsigned int>(list.size()),
false);
492 std::copy(list.begin(), list.end(),
data);
503 for (
unsigned int i = 0; i <
rowNum; ++i) {
514 for (
unsigned int i = 0; i <
rowNum; ++i) {
540 if (a.
data ==
nullptr) {
543 if (b.
data ==
nullptr) {
548 "Cannot compute the dot product between column vectors "
549 "with different dimensions (%d) and (%d)",
557 unsigned int a_rows_nbr = a.
getRows();
558 for (
unsigned int i = 0; i < a_rows_nbr; ++i) {
560 c += *(ad++) * *(bd++);
578 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
579 *
this /= sqrt(sum_square);
588 if (v.
data ==
nullptr) {
593 unsigned int nb_permutation = 1;
595 while (nb_permutation != 0) {
597 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
598 if (tab[j] > tab[j - 1]) {
613 if (v.
data ==
nullptr) {
618 unsigned int nb_permutation = 1;
620 while (nb_permutation != 0) {
622 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
623 if (tab[j] < tab[j - 1]) {
653 unsigned int nrA = A.
getRows();
654 unsigned int nrB = B.
getRows();
656 if ((nrA == 0) && (nrB == 0)) {
672 C.
resize(nrA + nrB,
false);
674 for (
unsigned int i = 0; i < nrA; ++i) {
678 for (
unsigned int i = 0; i < nrB; ++i) {
685 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
697 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
708 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
711 #if defined(VISP_HAVE_SIMDLIB)
712 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
714 double mean_value = v.
sum() / v.
size();
715 double sum_squared_diff = 0.0;
716 for (
size_t i = 0; i < v.
size(); i++) {
717 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
720 double divisor =
static_cast<double>(v.
size());
721 if (useBesselCorrection) {
722 divisor = divisor - 1;
725 return std::sqrt(sum_squared_diff / divisor);
732 const unsigned int rows_size = 3;
733 if (v.
getRows() != rows_size) {
738 M.
resize(3, 3,
false,
false);
739 const unsigned int index_0 = 0;
740 const unsigned int index_1 = 1;
741 const unsigned int index_2 = 2;
742 M[index_0][index_0] = 0;
743 M[index_0][index_1] = -v[index_2];
744 M[index_0][index_2] = v[index_1];
745 M[index_1][index_0] = v[index_2];
746 M[index_1][index_1] = 0;
747 M[index_1][index_2] = -v[index_0];
748 M[index_2][index_0] = -v[index_1];
749 M[index_2][index_1] = v[index_0];
750 M[index_2][index_2] = 0;
759 "Cannot compute the cross product between column "
760 "vector with dimension %d and %d",
776 if (
dsize != (nrows * ncols)) {
781 M.
resize(nrows, ncols,
false,
false);
784 for (
unsigned int j = 0; j < ncols; ++j) {
785 for (
unsigned int i = 0; i < nrows; ++i) {
786 M[i][j] =
data[(j * nrows) + i];
793 if ((i + v.
size()) >(this->size())) {
804 typedef std::string::size_type size_type;
809 std::vector<std::string> values(m * n);
810 std::ostringstream oss;
811 std::ostringstream ossFixed;
812 std::ios_base::fmtflags original_flags = oss.flags();
815 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
817 size_type maxBefore = 0;
818 size_type maxAfter = 0;
820 for (
unsigned int i = 0; i < m; ++i) {
823 if (oss.str().find(
"e") != std::string::npos) {
825 ossFixed << (*this)[i];
826 oss.str(ossFixed.str());
829 values[i] = oss.str();
830 size_type thislen = values[i].size();
831 size_type p = values[i].find(
'.');
833 if (p == std::string::npos) {
843 size_type totalLength = length;
847 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
858 s <<
"[" << m <<
"," << n <<
"]=\n";
860 for (
unsigned int i = 0; i < m; ++i) {
862 size_type p = values[i].find(
'.');
863 s.setf(std::ios::right, std::ios::adjustfield);
864 s.width(
static_cast<std::streamsize
>(maxBefore));
865 s << values[i].substr(0, p).c_str();
868 s.setf(std::ios::left, std::ios::adjustfield);
869 if (p != std::string::npos) {
870 s.width(
static_cast<std::streamsize
>(maxAfter));
871 s << values[i].substr(p, maxAfter).c_str();
874 assert(maxAfter > 1);
875 s.width(
static_cast<std::streamsize
>(maxAfter));
885 s.flags(original_flags);
887 return static_cast<int>(maxBefore + maxAfter);
892 #if defined(VISP_HAVE_SIMDLIB)
896 for (
unsigned int i = 0; i <
rowNum; ++i) {
905 #if defined(VISP_HAVE_SIMDLIB)
908 double sum_square = 0.0;
909 for (
unsigned int i = 0; i <
rowNum; ++i) {
910 sum_square += (*this)[i] * (*this)[i];
931 #if defined(VISP_HAVE_SIMDLIB)
934 for (
unsigned int i = 0; i <
dsize; ++i) {
944 for (
unsigned int i = 0; i <
rowNum; ++i) {
945 double x = fabs((*
this)[i]);
955 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
957 unsigned int rows_nbr = this->
getRows();
958 for (
unsigned int i = 0; i < rows_nbr; ++i) {
961 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
964 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
965 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
966 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[i]))[k]) <<
"; " << std::endl;
970 std::cout << std::endl;
976 unsigned int rows_nbr = this->
getRows();
977 for (
unsigned int i = 0; i < rows_nbr; ++i) {
987 unsigned int rows_nbr = this->
getRows();
988 os <<
"([ " << std::endl;
989 for (
unsigned int i = 0; i < rows_nbr; ++i) {
991 os << (*this)[i] <<
", ";
992 os <<
"]," << std::endl;
994 os <<
"])" << std::endl;
1000 unsigned int rows_nbr = this->
getRows();
1002 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1003 os << (*this)[i] <<
", ";
1004 if (this->
getRows() != (i + 1)) {
1005 os <<
";" << std::endl;
1008 os <<
"]" << std::endl;
1014 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1027 double vpColVector::euclideanNorm()
const {
return frobeniusNorm(); }
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
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
void init(const vpColVector &v, unsigned int r, unsigned int nrows)
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)
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+(const vpColVector &v) 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.