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)
276 for (
unsigned int i = 0; i <
rowNum; ++i) {
293 for (
unsigned int i = 0; i <
rowNum; ++i) {
304 for (
unsigned int i = 0; i <
rowNum; ++i) {
312 for (
unsigned int i = 0; i <
rowNum; ++i) {
325 for (
unsigned int i = 0; i <
rowNum; ++i) {
349 unsigned int v_size =
static_cast<unsigned int>(v.size());
351 for (
unsigned int i = 0; i < v_size; ++i) {
359 unsigned int v_size =
static_cast<unsigned int>(v.size());
361 for (
unsigned int i = 0; i < v_size; ++i) {
362 (*this)[i] =
static_cast<float>(v[i]);
369 unsigned int k = v.
rowNum;
419 for (
unsigned int i = 0; i <
rowNum; ++i) {
420 for (
unsigned int j = 0; j <
colNum; ++j) {
445 for (
unsigned int i = 0; i <
rowNum; ++i) {
453 std::vector<double> v(this->
size());
455 unsigned int v_this_size = this->
size();
456 for (
unsigned int i = 0; i < v_this_size; ++i) {
462 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
488 resize(
static_cast<unsigned int>(list.size()),
false);
489 std::copy(list.begin(), list.end(),
data);
500 for (
unsigned int i = 0; i <
rowNum; ++i) {
511 for (
unsigned int i = 0; i <
rowNum; ++i) {
537 if (a.
data ==
nullptr) {
540 if (b.
data ==
nullptr) {
545 "Cannot compute the dot product between column vectors "
546 "with different dimensions (%d) and (%d)",
554 unsigned int a_rows_nbr = a.
getRows();
555 for (
unsigned int i = 0; i < a_rows_nbr; ++i) {
577 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
578 *
this /= sqrt(sum_square);
587 if (v.
data ==
nullptr) {
592 unsigned int nb_permutation = 1;
594 while (nb_permutation != 0) {
596 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
597 if (tab[j] > tab[j - 1]) {
612 if (v.
data ==
nullptr) {
617 unsigned int nb_permutation = 1;
619 while (nb_permutation != 0) {
621 for (
unsigned int j = v.
getRows() - 1; j >= (i + 1); --j) {
622 if (tab[j] < tab[j - 1]) {
652 unsigned int nrA = A.
getRows();
653 unsigned int nrB = B.
getRows();
655 if ((nrA == 0) && (nrB == 0)) {
671 C.
resize(nrA + nrB,
false);
673 for (
unsigned int i = 0; i < nrA; ++i) {
677 for (
unsigned int i = 0; i < nrB; ++i) {
684 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
696 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
707 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
710 #if defined(VISP_HAVE_SIMDLIB)
711 return SimdVectorStdev(v.
data, v.
rowNum, useBesselCorrection);
713 double mean_value = v.
sum() / v.
size();
714 double sum_squared_diff = 0.0;
715 unsigned int v_size = v.
size();
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(rows_size, rows_size,
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;
757 const unsigned int val_3 = 3;
760 "Cannot compute the cross product between column "
761 "vector with dimension %d and %d",
777 if (
dsize != (nrows * ncols)) {
782 M.
resize(nrows, ncols,
false,
false);
785 for (
unsigned int j = 0; j < ncols; ++j) {
786 for (
unsigned int i = 0; i < nrows; ++i) {
787 M[i][j] =
data[(j * nrows) + i];
794 if ((i + v.
size()) >(this->size())) {
805 typedef std::string::size_type size_type;
810 std::vector<std::string> values(m * n);
811 std::ostringstream oss;
812 std::ostringstream ossFixed;
813 std::ios_base::fmtflags original_flags = oss.flags();
816 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
818 size_type maxBefore = 0;
819 size_type maxAfter = 0;
821 for (
unsigned int i = 0; i < m; ++i) {
824 if (oss.str().find(
"e") != std::string::npos) {
826 ossFixed << (*this)[i];
827 oss.str(ossFixed.str());
830 values[i] = oss.str();
831 size_type thislen = values[i].size();
832 size_type p = values[i].find(
'.');
834 if (p == std::string::npos) {
844 size_type totalLength = length;
848 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
859 s <<
"[" << m <<
"," << n <<
"]=\n";
861 for (
unsigned int i = 0; i < m; ++i) {
863 size_type p = values[i].find(
'.');
864 s.setf(std::ios::right, std::ios::adjustfield);
865 s.width(
static_cast<std::streamsize
>(maxBefore));
866 s << values[i].substr(0, p).c_str();
869 s.setf(std::ios::left, std::ios::adjustfield);
870 if (p != std::string::npos) {
871 s.width(
static_cast<std::streamsize
>(maxAfter));
872 s << values[i].substr(p, maxAfter).c_str();
875 assert(maxAfter > 1);
876 s.width(
static_cast<std::streamsize
>(maxAfter));
886 s.flags(original_flags);
888 return static_cast<int>(maxBefore + maxAfter);
893 #if defined(VISP_HAVE_SIMDLIB)
897 for (
unsigned int i = 0; i <
rowNum; ++i) {
906 #if defined(VISP_HAVE_SIMDLIB)
909 double sum_square = 0.0;
910 for (
unsigned int i = 0; i <
rowNum; ++i) {
911 sum_square += (*this)[i] * (*this)[i];
932 #if defined(VISP_HAVE_SIMDLIB)
935 for (
unsigned int i = 0; i <
dsize; ++i) {
945 for (
unsigned int i = 0; i <
rowNum; ++i) {
946 double x = fabs((*
this)[i]);
956 os <<
"vpColVector " << matrixName <<
" (" << this->
getRows() <<
"); " << std::endl;
958 unsigned int rows_nbr = this->
getRows();
959 for (
unsigned int i = 0; i < rows_nbr; ++i) {
962 os << matrixName <<
"[" << i <<
"] = " << (*this)[i] <<
"; " << std::endl;
965 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
966 os <<
"((unsigned char*)&(" << matrixName <<
"[" << i <<
"]) )[" << k <<
"] = 0x" << std::hex
967 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[i]))[k]) <<
"; " << std::endl;
971 std::cout << std::endl;
977 unsigned int rows_nbr = this->
getRows();
978 for (
unsigned int i = 0; i < rows_nbr; ++i) {
988 unsigned int rows_nbr = this->
getRows();
989 os <<
"([ " << std::endl;
990 for (
unsigned int i = 0; i < rows_nbr; ++i) {
992 os << (*this)[i] <<
", ";
993 os <<
"]," << std::endl;
995 os <<
"])" << std::endl;
1001 unsigned int rows_nbr = this->
getRows();
1003 for (
unsigned int i = 0; i < rows_nbr; ++i) {
1004 os << (*this)[i] <<
", ";
1005 if (this->
getRows() != (i + 1)) {
1006 os <<
";" << std::endl;
1009 os <<
"]" << std::endl;
1015 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1028 double vpColVector::euclideanNorm()
const {
return frobeniusNorm(); }
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
Type * 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.
static vpArray2D< Type > view(const vpArray2D< Type > &A)
Creates a view of the Matrix A. A view shares the same underlying memory as the original 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
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
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)
static vpColVector view(double *data, unsigned int rows)
Create a column vector view of a raw data array. The view can modify the contents of the raw data arr...
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.