50 #include <visp3/core/vpArray2D.h> 51 #include <visp3/core/vpColVector.h> 52 #include <visp3/core/vpDebug.h> 53 #include <visp3/core/vpException.h> 54 #include <visp3/core/vpMatrix.h> 55 #include <visp3/core/vpRowVector.h> 100 resize((
unsigned int)v.size());
101 for (
unsigned int i = 0; i < v.size(); i++)
110 resize((
unsigned int)v.size());
111 for (
unsigned int i = 0; i < v.size(); i++)
112 (*
this)[i] = (float)v[i];
119 for (
unsigned int i = 0; i <
rowNum; i++) {
120 for (
unsigned int j = 0; j <
colNum; j++) {
143 unsigned int nelements = x.
getRows();
151 for (
unsigned int i = 0; i < nelements; i++) {
152 scalar += (*this)[i] * x[i];
182 for (
unsigned int i = 0; i <
colNum; i++) {
184 for (
unsigned int j = 0; j < M.
getCols(); j++) {
185 c[j] += bi * M[i][j];
218 for (
unsigned int i = 0; i <
colNum; i++)
219 *(vd++) = (*d++) * x;
242 for (
unsigned int i = 0; i <
colNum; i++)
273 for (
unsigned int i = 0; i <
colNum; i++)
274 *(vd++) = (*d++) / x;
298 for (
unsigned int i = 0; i <
colNum; i++)
320 for (
unsigned int i = 0; i <
colNum; i++)
339 for (
unsigned int i = 0; i <
colNum; i++)
340 v[i] = (*
this)[i] - m[i];
357 for (
unsigned int i = 0; i <
colNum; i++)
358 r[i] = (*
this)[i] + v[i];
374 for (
unsigned int i = 0; i <
colNum; i++)
391 for (
unsigned int i = 0; i <
colNum; i++)
450 for (
unsigned int j = 0; j < M.
getCols(); j++)
451 (*
this)[j] = M[i][j];
466 for (
unsigned int j = 0; j < M.
getCols(); j++)
467 (*
this)[j] = M[0][j];
475 for (
unsigned int j = 0; j < v.size(); j++)
483 for (
unsigned int j = 0; j < v.size(); j++)
484 (*
this)[j] = (double)(v[j]);
532 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
533 *
this /= sqrt(sum_square);
603 if (
dsize != nrows * ncols) {
613 for (
unsigned int i = 0; i < nrows; i++)
614 for (
unsigned int j = 0; j < ncols; j++)
615 M[i][j] =
data[i * ncols + j];
653 "Unable to insert (1x%d) row vector in (1x%d) row " 654 "vector at position (%d)",
656 for (
unsigned int j = 0; j < v.
size(); j++)
657 (*
this)[i + j] = v[j];
752 unsigned int nrA = A.
getCols();
753 unsigned int nrB = B.
getCols();
755 if (nrA == 0 && nrB == 0) {
773 for (
unsigned int i = 0; i < nrA; i++)
776 for (
unsigned int i = 0; i < nrB; i++)
785 if (v.
data == NULL || v.
size() == 0) {
791 for (
unsigned int i = 0; i < v.
getCols(); i++)
802 if (v.
data == NULL || v.
size() == 0) {
816 if (v.
data == NULL || v.
size() == 0) {
820 double mean_value =
mean(v);
821 double sum_squared_diff = 0.0;
822 for (
unsigned int i = 0; i < v.
size(); i++) {
823 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
826 double divisor = (double)v.
size();
827 if (useBesselCorrection && v.
size() > 1) {
828 divisor = divisor - 1;
831 return std::sqrt(sum_squared_diff / divisor);
855 typedef std::string::size_type size_type;
860 std::vector<std::string> values(m * n);
861 std::ostringstream oss;
862 std::ostringstream ossFixed;
863 std::ios_base::fmtflags original_flags = oss.flags();
866 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
868 size_type maxBefore = 0;
869 size_type maxAfter = 0;
871 for (
unsigned int j = 0; j < n; ++j) {
874 if (oss.str().find(
"e") != std::string::npos) {
876 ossFixed << (*this)[j];
877 oss.str(ossFixed.str());
880 values[j] = oss.str();
881 size_type thislen = values[j].size();
882 size_type p = values[j].find(
'.');
884 if (p == std::string::npos) {
893 size_type totalLength = length;
897 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
906 s <<
"[" << m <<
"," << n <<
"]=\n";
909 for (
unsigned int j = 0; j < n; j++) {
910 size_type p = values[j].find(
'.');
911 s.setf(std::ios::right, std::ios::adjustfield);
912 s.width((std::streamsize)maxBefore);
913 s << values[j].substr(0, p).c_str();
916 s.setf(std::ios::left, std::ios::adjustfield);
917 if (p != std::string::npos) {
918 s.width((std::streamsize)maxAfter);
919 s << values[j].substr(p, maxAfter).c_str();
921 assert(maxAfter > 1);
922 s.width((std::streamsize)maxAfter);
931 s.flags(original_flags);
933 return (
int)(maxBefore + maxAfter);
955 for (
unsigned int j = 0; j <
colNum; j++) {
970 double sum_square = 0.0;
972 for (
unsigned int j = 0; j <
colNum; j++) {
988 for (
unsigned int i = 0; i <
dsize; i++) {
989 double x = *(
data + i);
1033 unsigned int cncols = c + ncols;
1041 for (
unsigned int i = 0; i < ncols; i++)
1042 (*
this)[i] = v[i + c];
1077 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1079 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1081 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1083 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1084 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1085 << (
unsigned int)((
unsigned char *)&((*this)[j]))[k] <<
"; " << std::endl;
1089 std::cout << std::endl;
1119 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1121 if (!(j == (this->
getCols() - 1)))
1153 os <<
"([ " << std::endl;
1155 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1156 os << (*this)[j] <<
", ";
1158 os <<
"]," << std::endl;
1159 os <<
"])" << std::endl;
1196 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1197 os << (*this)[j] <<
", ";
1199 os <<
"]" << std::endl;
vpRowVector & operator/=(double x)
Implementation of a matrix and operations on matrices.
vpRowVector & normalize()
static double median(const vpRowVector &v)
vpRowVector operator+(const vpRowVector &v) const
Implementation of row vector and the associated operations.
static double getMedian(const std::vector< double > &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
static double mean(const vpRowVector &v)
vp_deprecated void init()
static double stdev(const vpRowVector &v, const bool useBesselCorrection=false)
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.
unsigned int size() const
Return the number of elements of the 2D array.
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpRowVector operator/(const double x) const
std::ostream & matlabPrint(std::ostream &os) const
int print(std::ostream &s, unsigned int length, char const *intro=0) const
std::ostream & csvPrint(std::ostream &os) const
static Type maximum(const Type &a, const Type &b)
unsigned int getCols() const
std::ostream & maplePrint(std::ostream &os) const
unsigned int rowNum
Number of rows in the array.
double operator*(const vpColVector &x) const
void stack(const double &d)
vpRowVector & operator-=(vpRowVector v)
vpColVector transpose() const
unsigned int colNum
Number of columns in the array.
void resize(const unsigned int i, const bool flagNullify=true)
vpRowVector & operator+=(vpRowVector v)
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
vpRowVector & operator<<(const vpRowVector &v)
Implementation of column vector and the associated operations.
vpRowVector & operator*=(double x)
vpRowVector & operator=(const vpRowVector &v)
Copy operator. Allow operation such as A = v.
unsigned int dsize
Current array size (rowNum * colNum)
double euclideanNorm() const
double ** rowPtrs
Address of the first element of each rows.
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
void insert(unsigned int i, const vpRowVector &v)
vpRowVector operator-() const