49 #include <visp3/core/vpArray2D.h>
50 #include <visp3/core/vpMatrix.h>
51 #include <visp3/core/vpException.h>
52 #include <visp3/core/vpRowVector.h>
53 #include <visp3/core/vpColVector.h>
54 #include <visp3/core/vpDebug.h>
59 unsigned int k = v.
colNum ;
85 "Cannot initialize a (1x%d) row vector from a (%dx%d) matrix",
101 resize((
unsigned int)v.size());
102 for(
unsigned int i=0; i<v.size(); i++)
111 resize((
unsigned int)v.size());
112 for(
unsigned int i=0; i<v.size(); i++)
113 (*
this)[i] = (float)v[i];
120 for (
unsigned int i=0; i<
rowNum; i++) {
121 for (
unsigned int j=0; j<
colNum; j++) {
144 unsigned int nelements = x.
getRows();
147 "Cannot multiply (1x%d) row vector by (%dx1) column vector",
153 for (
unsigned int i=0; i<nelements; i++) {
154 scalar += (*this)[i] * x[i];
179 "Cannot multiply (1x%d) row vector by (%dx%d) matrix",
185 for (
unsigned int i=0;i<
colNum;i++) {
186 double bi =
data[i] ;
187 for (
unsigned int j=0;j<M.
getCols();j++) {
218 double *vd = v.
data ;
double *d =
data ;
220 for (
unsigned int i=0;i<
colNum;i++)
221 *(vd++) = (*d++) * x;
244 for (
unsigned int i=0;i<
colNum;i++)
272 double *vd = v.
data ;
double *d =
data ;
274 for (
unsigned int i=0;i<
colNum;i++)
275 *(vd++) = (*d++) / x;
299 for (
unsigned int i=0;i<
colNum;i++)
318 double *vd = A.
data ;
double *d =
data ;
320 for (
unsigned int i=0; i<
colNum; i++)
334 "Cannot substract (1x%d) row vector to (1x%d) row vector",
340 for (
unsigned int i=0;i<
colNum;i++)
341 v[i] = (*
this)[i] - m[i];
353 "Cannot add (1x%d) row vector to (1x%d) row vector",
359 for (
unsigned int i=0;i<
colNum;i++)
360 r[i] = (*
this)[i] + v[i];
373 "Cannot add (1x%d) row vector to (1x%d) row vector",
377 for (
unsigned int i=0;i<
colNum;i++)
391 "Cannot substract (1x%d) row vector to (1x%d) row vector",
395 for (
unsigned int i=0;i<
colNum;i++)
461 for(
unsigned int j=0; j< M.
getCols(); j++)
462 (*
this)[j] = M[i][j];
474 "Cannot construct a (1x%d) row vector from a (%dx%d) matrix",
478 for(
unsigned int j=0; j< M.
getCols(); j++)
479 (*
this)[j] = M[0][j];
486 :
vpArray2D<double>(1, (unsigned int)v.size())
488 for(
unsigned int j=0; j< v.size(); j++)
495 :
vpArray2D<double>(1, (unsigned int)v.size())
497 for(
unsigned int j=0; j< v.size(); j++)
498 (*
this)[j] = (double)(v[j]);
546 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
547 *
this /= sqrt(sum_square) ;
578 if(
dsize!=nrows*ncols) {
580 "Cannot reshape (1x%d) row vector in (%dx%d) matrix",
589 for(
unsigned int i =0; i< nrows; i++)
590 for(
unsigned int j =0; j< ncols; j++)
591 M[i][j]=
data[i*nrows+j];
629 "Unable to insert (1x%d) row vector in (1x%d) row vector at position (%d)",
631 for (
unsigned int j=0; j < v.
size(); j++)
730 unsigned int nrA = A.
getCols();
731 unsigned int nrB = B.
getCols();
733 if (nrA == 0 && nrB == 0) {
751 for (
unsigned int i=0; i<nrA; i++)
754 for (
unsigned int i=0; i<nrB; i++)
763 if (v.
data == NULL) {
765 "Cannot compute mean value of an empty row vector"));
770 for (
unsigned int i = 0; i < v.
getCols(); i++)
784 "Cannot compute mean value of an empty row vector"));
787 std::vector<double> vectorOfDoubles(v.
size());
788 for(
unsigned int i = 0; i < v.
size(); i++) {
789 vectorOfDoubles[i] = v[i];
803 "Cannot compute mean value of an empty row vector"));
806 double mean_value =
mean(v);
807 double sum_squared_diff = 0.0;
808 for(
unsigned int i = 0; i < v.
size(); i++) {
809 sum_squared_diff += (v[i]-mean_value) * (v[i]-mean_value);
812 double divisor = (double) v.
size();
813 if(useBesselCorrection && v.
size() > 1) {
817 return std::sqrt(sum_squared_diff / divisor);
842 typedef std::string::size_type size_type;
847 std::vector<std::string> values(m*n);
848 std::ostringstream oss;
849 std::ostringstream ossFixed;
850 std::ios_base::fmtflags original_flags = oss.flags();
853 ossFixed.setf ( std::ios::fixed, std::ios::floatfield );
855 size_type maxBefore=0;
856 size_type maxAfter=0;
858 for (
unsigned int j=0;j<n;++j){
861 if (oss.str().find(
"e")!=std::string::npos){
863 ossFixed << (*this)[j];
864 oss.str(ossFixed.str());
868 size_type thislen=values[j].size();
869 size_type p=values[j].find(
'.');
871 if (p==std::string::npos){
881 size_type totalLength=length;
885 maxAfter=std::min(maxAfter, totalLength-maxBefore);
886 if (maxAfter==1) maxAfter=0;
891 if (intro) s <<intro;
892 s <<
"["<<m<<
","<<n<<
"]=\n";
895 for (
unsigned int j=0;j<n;j++){
896 size_type p=values[j].find(
'.');
897 s.setf(std::ios::right, std::ios::adjustfield);
898 s.width((std::streamsize)maxBefore);
899 s <<values[j].substr(0,p).c_str();
902 s.setf(std::ios::left, std::ios::adjustfield);
903 if (p!=std::string::npos){
904 s.width((std::streamsize)maxAfter);
905 s <<values[j].substr(p,maxAfter).c_str();
908 s.width((std::streamsize)maxAfter);
918 s.flags(original_flags);
920 return (
int)(maxBefore+maxAfter);
940 double sum_square=0.0;
943 for (
unsigned int j=0;j<
colNum;j++) {
960 for (
unsigned int i=0;i<
dsize;i++) {
961 x = *(
data +i); norm += x*x;
1004 unsigned int cncols = c+ncols ;
1008 "Bad column dimension (%d > %d) used to initialize vpRowVector",
1013 for (
unsigned int i=0 ; i < ncols; i++)
1014 (*
this)[i] = v[i+c];
vpRowVector & operator/=(double x)
Implementation of a matrix and operations on matrices.
vpRowVector & normalize()
static double median(const vpRowVector &v)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Implementation of row vector and the associated operations.
static double getMedian(const std::vector< double > &v)
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emited by ViSP classes.
static double mean(const vpRowVector &v)
vpRowVector operator+(const vpRowVector &v) const
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.
unsigned int getCols() const
Return the number of columns of the 2D array.
static Type maximum(const Type &a, const Type &b)
vpColVector transpose() const
unsigned int rowNum
Number of rows in the array.
vpRowVector operator/(const double x) const
double euclideanNorm() const
double operator*(const vpColVector &x) const
void stack(const double &d)
vpRowVector & operator-=(vpRowVector v)
unsigned int getRows() const
Return the number of rows of the 2D array.
vpRowVector operator-() 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)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
vpRowVector & operator=(const vpRowVector &v)
Copy operator. Allow operation such as A = v.
unsigned int dsize
Current array size (rowNum * colNum)
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)