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];
76 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) {
303 for (
unsigned int i = 0; i <
rowNum; ++i) {
314 for (
unsigned int i = 0; i <
rowNum; ++i) {
322 for (
unsigned int i = 0; i <
rowNum; ++i) {
335 for (
unsigned int i = 0; i <
rowNum; ++i) {
359 unsigned int v_size =
static_cast<unsigned int>(v.size());
361 for (
unsigned int i = 0; i < v_size; ++i) {
369 unsigned int v_size =
static_cast<unsigned int>(v.size());
371 for (
unsigned int i = 0; i < v_size; ++i) {
372 (*this)[i] =
static_cast<float>(v[i]);
379 unsigned int k = v.
rowNum;
429 for (
unsigned int i = 0; i <
rowNum; ++i) {
430 for (
unsigned int j = 0; j <
colNum; ++j) {
455 for (
unsigned int i = 0; i <
rowNum; ++i) {
463 std::vector<double> v(this->
size());
465 unsigned int v_this_size = this->
size();
466 for (
unsigned int i = 0; i < v_this_size; ++i) {
472 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
475 if (
this != &other) {
487 other.rowPtrs =
nullptr;
489 other.data =
nullptr;
497 resize(
static_cast<unsigned int>(list.size()),
false);
498 std::copy(list.begin(), list.end(),
data);
509 for (
unsigned int i = 0; i <
rowNum; ++i) {
520 for (
unsigned int i = 0; i <
rowNum; ++i) {
546 if (a.
data ==
nullptr) {
549 if (b.
data ==
nullptr) {
554 "Cannot compute the dot product between column vectors "
555 "with different dimensions (%d) and (%d)",
563 unsigned int a_rows_nbr = a.
getRows();
564 for (
unsigned int i = 0; i < a_rows_nbr; ++i) {
586 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
587 *
this /= sqrt(sum_square);
596 if (v.
data ==
nullptr) {
601 unsigned int nb_permutation = 1;
603 while (nb_permutation != 0) {
605 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
606 if (tab[j] > tab[j - 1]) {
621 if (v.
data ==
nullptr) {
626 unsigned int nb_permutation = 1;
628 while (nb_permutation != 0) {
630 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
631 if (tab[j] < tab[j - 1]) {
661 unsigned int nrA = A.
getRows();
662 unsigned int nrB = B.
getRows();
664 if ((nrA == 0) && (nrB == 0)) {
680 C.
resize(nrA + nrB,
false);
682 for (
unsigned int i = 0; i < nrA; ++i) {
686 for (
unsigned int i = 0; i < nrB; ++i) {
693 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
705 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
716 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
719 #if defined(VISP_HAVE_SIMDLIB)
720 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
722 double mean_value = v.
sum() / v.
size();
723 double sum_squared_diff = 0.0;
724 unsigned int v_size = v.
size();
725 for (
size_t i = 0; i < v_size; ++i) {
726 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
729 double divisor =
static_cast<double>(v.
size());
730 if (useBesselCorrection) {
731 divisor = divisor - 1;
734 return std::sqrt(sum_squared_diff / divisor);
741 const unsigned int rows_size = 3;
742 if (v.
getRows() != rows_size) {
747 M.
resize(rows_size, rows_size,
false,
false);
748 const unsigned int index_0 = 0;
749 const unsigned int index_1 = 1;
750 const unsigned int index_2 = 2;
751 M[index_0][index_0] = 0;
752 M[index_0][index_1] = -v[index_2];
753 M[index_0][index_2] = v[index_1];
754 M[index_1][index_0] = v[index_2];
755 M[index_1][index_1] = 0;
756 M[index_1][index_2] = -v[index_0];
757 M[index_2][index_0] = -v[index_1];
758 M[index_2][index_1] = v[index_0];
759 M[index_2][index_2] = 0;
766 const unsigned int val_3 = 3;
769 "Cannot compute the cross product between column "
770 "vector with dimension %d and %d",
786 if (
dsize != (nrows * ncols)) {
791 M.
resize(nrows, ncols,
false,
false);
794 for (
unsigned int j = 0; j < ncols; ++j) {
795 for (
unsigned int i = 0; i < nrows; ++i) {
796 M[i][j] =
data[(j * nrows) + i];
803 if ((i + v.
size()) >(this->size())) {
814 typedef std::string::size_type size_type;
819 std::vector<std::string> values(m * n);
820 std::ostringstream oss;
821 std::ostringstream ossFixed;
822 std::ios_base::fmtflags original_flags = oss.flags();
825 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
827 size_type maxBefore = 0;
828 size_type maxAfter = 0;
830 for (
unsigned int i = 0; i < m; ++i) {
833 if (oss.str().find(
"e") != std::string::npos) {
835 ossFixed << (*this)[i];
836 oss.str(ossFixed.str());
839 values[i] = oss.str();
840 size_type thislen = values[i].size();
841 size_type p = values[i].find(
'.');
843 if (p == std::string::npos) {
853 size_type totalLength = length;
857 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
868 s <<
"[" << m <<
"," << n <<
"]=\n";
870 for (
unsigned int i = 0; i < m; ++i) {
872 size_type p = values[i].find(
'.');
873 s.setf(std::ios::right, std::ios::adjustfield);
874 s.width(
static_cast<std::streamsize
>(maxBefore));
875 s << values[i].substr(0, p).c_str();
878 s.setf(std::ios::left, std::ios::adjustfield);
879 if (p != std::string::npos) {
880 s.width(
static_cast<std::streamsize
>(maxAfter));
881 s << values[i].substr(p, maxAfter).c_str();
884 assert(maxAfter > 1);
885 s.width(
static_cast<std::streamsize
>(maxAfter));
895 s.flags(original_flags);
897 return static_cast<int>(maxBefore + maxAfter);
902 #if defined(VISP_HAVE_SIMDLIB)
906 for (
unsigned int i = 0; i <
rowNum; ++i) {
915 #if defined(VISP_HAVE_SIMDLIB)
918 double sum_square = 0.0;
919 for (
unsigned int i = 0; i <
rowNum; ++i) {
920 sum_square += (*this)[i] * (*this)[i];
941 #if defined(VISP_HAVE_SIMDLIB)
944 for (
unsigned int i = 0; i <
dsize; ++i) {
954 for (
unsigned int i = 0; i <
rowNum; ++i) {
955 double x = fabs((*
this)[i]);
965 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
967 unsigned int rows_nbr = this->
getRows();
968 for (
unsigned int i = 0; i < rows_nbr; ++i) {
971 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
974 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
975 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
976 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[i]))[k]) <<
"; " << std::endl;
980 std::cout << std::endl;
986 unsigned int rows_nbr = this->
getRows();
987 for (
unsigned int i = 0; i < rows_nbr; ++i) {
997 unsigned int rows_nbr = this->
getRows();
998 os <<
"([ " << std::endl;
999 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1001 os << (*this)[i] <<
", ";
1002 os <<
"]," << std::endl;
1004 os <<
"])" << std::endl;
1010 unsigned int rows_nbr = this->
getRows();
1012 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1013 os << (*this)[i] <<
", ";
1014 if (this->
getRows() != (i + 1)) {
1015 os <<
";" << std::endl;
1018 os <<
"]" << std::endl;
1024 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1037 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.