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 #if defined(VISP_HAVE_SIMDLIB)
57 #include <Simd/SimdLib.h>
68 for (
unsigned int i = 0; i <
rowNum; ++i) {
69 r[i] = (*this)[i] + v[i];
82 for (
unsigned int i = 0; i < 3; ++i) {
83 s[i] = (*this)[i] +
t[i];
96 for (
unsigned int i = 0; i <
rowNum; ++i) {
109 for (
unsigned int i = 0; i <
rowNum; ++i) {
119 "Cannot compute the dot product between column vectors "
120 "with different dimensions (%d) and (%d)",
125 for (
unsigned int i = 0; i <
rowNum; ++i) {
126 r += (*this)[i] * v[i];
134 unsigned int v_cols = v.
getCols();
135 for (
unsigned int i = 0; i <
rowNum; ++i) {
136 for (
unsigned int j = 0; j < v_cols; ++j) {
137 M[i][j] = (*this)[i] * v[j];
147 "Bad size during vpColVector (%dx1) and vpColVector "
148 "(%dx1) subtraction",
153 for (
unsigned int i = 0; i <
rowNum; ++i) {
154 v[i] = (*this)[i] - m[i];
166 unsigned int rnrows = r + nrows;
174 if (this->
rowPtrs ==
nullptr) {
177 for (
unsigned int i = r; i < rnrows; ++i) {
178 (*this)[i - r] = v[i];
184 unsigned int v_size = v.
size();
185 for (
unsigned int i = 0; i < v_size; ++i) {
192 unsigned int p_size = p.
size();
193 for (
unsigned int i = 0; i < p_size; ++i) {
200 unsigned int v_size = v.
size();
201 for (
unsigned int i = 0; i < v_size; ++i) {
208 unsigned int m_cols = M.
getCols();
209 for (
unsigned int i = 0; i < m_cols; ++i) {
210 (*this)[i] = M[i][j];
221 unsigned int m_rows = M.
getRows();
222 for (
unsigned int i = 0; i < m_rows; ++i) {
223 (*this)[i] = M[i][0];
229 unsigned int v_size = v.
size();
230 for (
unsigned int i = 0; i < v_size; ++i) {
237 unsigned int v_size = v.
size();
238 for (
unsigned int i = 0; i < v_size; ++i) {
239 (*this)[i] =
static_cast<double>(v[i]);
243 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
268 for (
unsigned int i = 0; i <
rowNum; ++i) {
283 for (
unsigned int i = 0; i <
rowNum; ++i) {
285 *(vd++) = (*d++) * x;
292 for (
unsigned int i = 0; i <
rowNum; ++i) {
300 for (
unsigned int i = 0; i <
rowNum; ++i) {
313 for (
unsigned int i = 0; i <
rowNum; ++i) {
315 *(vd++) = (*d++) / x;
335 unsigned int v_size = v.
size();
337 for (
unsigned int i = 0; i < v_size; ++i) {
345 unsigned int v_size = v.
size();
347 for (
unsigned int i = 0; i < v_size; ++i) {
348 (*this)[i] =
static_cast<float>(v[i]);
355 unsigned int k = v.
rowNum;
405 for (
unsigned int i = 0; i <
rowNum; ++i) {
406 for (
unsigned int j = 0; j <
colNum; ++j) {
431 for (
unsigned int i = 0; i <
rowNum; ++i) {
439 std::vector<double> v(this->
size());
441 unsigned int v_this_size = this->
size();
442 for (
unsigned int i = 0; i < v_this_size; ++i) {
448 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
451 if (
this != &other) {
463 other.rowPtrs =
nullptr;
465 other.data =
nullptr;
473 resize(
static_cast<unsigned int>(list.size()),
false);
474 std::copy(list.begin(), list.end(),
data);
485 for (
unsigned int i = 0; i <
rowNum; ++i) {
496 for (
unsigned int i = 0; i <
rowNum; ++i) {
529 if (a.
data ==
nullptr) {
532 if (b.
data ==
nullptr) {
537 "Cannot compute the dot product between column vectors "
538 "with different dimensions (%d) and (%d)",
546 unsigned int a_rows_nbr = a.
getRows();
547 for (
unsigned int i = 0; i < a_rows_nbr; ++i) {
549 c += *(ad++) * *(bd++);
567 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
568 *
this /= sqrt(sum_square);
577 if (v.
data ==
nullptr) {
582 unsigned int nb_permutation = 1;
584 while (nb_permutation != 0) {
586 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); j--) {
587 if (tab[j] > tab[j - 1]) {
602 if (v.
data ==
nullptr) {
607 unsigned int nb_permutation = 1;
609 while (nb_permutation != 0) {
611 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); j--) {
612 if (tab[j] < tab[j - 1]) {
642 unsigned int nrA = A.
getRows();
643 unsigned int nrB = B.
getRows();
645 if ((nrA == 0) && (nrB == 0)) {
661 C.
resize(nrA + nrB,
false);
663 for (
unsigned int i = 0; i < nrA; ++i) {
667 for (
unsigned int i = 0; i < nrB; ++i) {
674 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
686 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
697 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
700 #if defined(VISP_HAVE_SIMDLIB)
701 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
703 double mean_value = v.
sum() / v.
size();
704 double sum_squared_diff = 0.0;
705 for (
size_t i = 0; i < v.
size(); i++) {
706 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
709 double divisor =
static_cast<double>(v.
size());
710 if (useBesselCorrection) {
711 divisor = divisor - 1;
714 return std::sqrt(sum_squared_diff / divisor);
726 M.
resize(3, 3,
false,
false);
744 "Cannot compute the cross product between column "
745 "vector with dimension %d and %d",
761 if (
dsize != (nrows * ncols)) {
766 M.
resize(nrows, ncols,
false,
false);
769 for (
unsigned int j = 0; j < ncols; ++j) {
770 for (
unsigned int i = 0; i < nrows; ++i) {
771 M[i][j] =
data[(j * nrows) + i];
778 if ((i + v.
size()) >(this->size())) {
789 typedef std::string::size_type size_type;
794 std::vector<std::string> values(m * n);
795 std::ostringstream oss;
796 std::ostringstream ossFixed;
797 std::ios_base::fmtflags original_flags = oss.flags();
800 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
802 size_type maxBefore = 0;
803 size_type maxAfter = 0;
805 for (
unsigned int i = 0; i < m; ++i) {
808 if (oss.str().find(
"e") != std::string::npos) {
810 ossFixed << (*this)[i];
811 oss.str(ossFixed.str());
814 values[i] = oss.str();
815 size_type thislen = values[i].size();
816 size_type p = values[i].find(
'.');
818 if (p == std::string::npos) {
828 size_type totalLength = length;
832 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
843 s <<
"[" << m <<
"," << n <<
"]=\n";
845 for (
unsigned int i = 0; i < m; ++i) {
847 size_type p = values[i].find(
'.');
848 s.setf(std::ios::right, std::ios::adjustfield);
849 s.width(
static_cast<std::streamsize
>(maxBefore));
850 s << values[i].substr(0, p).c_str();
853 s.setf(std::ios::left, std::ios::adjustfield);
854 if (p != std::string::npos) {
855 s.width(
static_cast<std::streamsize
>(maxAfter));
856 s << values[i].substr(p, maxAfter).c_str();
859 assert(maxAfter > 1);
860 s.width(
static_cast<std::streamsize
>(maxAfter));
870 s.flags(original_flags);
872 return static_cast<int>(maxBefore + maxAfter);
877 #if defined(VISP_HAVE_SIMDLIB)
881 for (
unsigned int i = 0; i <
rowNum; ++i) {
890 #if defined(VISP_HAVE_SIMDLIB)
893 double sum_square = 0.0;
894 for (
unsigned int i = 0; i <
rowNum; ++i) {
895 sum_square += (*this)[i] * (*this)[i];
916 #if defined(VISP_HAVE_SIMDLIB)
921 for (
unsigned int i = 0; i <
dsize; ++i) {
930 for (
unsigned int i = 0; i <
rowNum; ++i) {
931 double x = fabs((*
this)[i]);
941 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
943 unsigned int rows_nbr = this->
getRows();
944 for (
unsigned int i = 0; i < rows_nbr; ++i) {
947 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
950 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
951 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
952 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[i]))[k]) <<
"; " << std::endl;
956 std::cout << std::endl;
962 unsigned int rows_nbr = this->
getRows();
963 for (
unsigned int i = 0; i < rows_nbr; ++i) {
973 unsigned int rows_nbr = this->
getRows();
974 os <<
"([ " << std::endl;
975 for (
unsigned int i = 0; i < rows_nbr; ++i) {
977 os << (*this)[i] <<
", ";
978 os <<
"]," << std::endl;
980 os <<
"])" << std::endl;
986 unsigned int rows_nbr = this->
getRows();
988 for (
unsigned int i = 0; i < rows_nbr; ++i) {
989 os << (*this)[i] <<
", ";
990 if (this->
getRows() != (i + 1)) {
991 os <<
";" << std::endl;
994 os <<
"]" << std::endl;
1000 #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.