50 #include <visp3/core/vpArray2D.h> 51 #include <visp3/core/vpMatrix.h> 52 #include <visp3/core/vpException.h> 53 #include <visp3/core/vpRowVector.h> 54 #include <visp3/core/vpColVector.h> 55 #include <visp3/core/vpDebug.h> 60 unsigned int k = v.
colNum ;
86 "Cannot initialize a (1x%d) row vector from a (%dx%d) matrix",
102 resize((
unsigned int)v.size());
103 for(
unsigned int i=0; i<v.size(); i++)
112 resize((
unsigned int)v.size());
113 for(
unsigned int i=0; i<v.size(); i++)
114 (*
this)[i] = (float)v[i];
121 for (
unsigned int i=0; i<
rowNum; i++) {
122 for (
unsigned int j=0; j<
colNum; j++) {
145 unsigned int nelements = x.
getRows();
148 "Cannot multiply (1x%d) row vector by (%dx1) column vector",
154 for (
unsigned int i=0; i<nelements; i++) {
155 scalar += (*this)[i] * x[i];
180 "Cannot multiply (1x%d) row vector by (%dx%d) matrix",
186 for (
unsigned int i=0;i<
colNum;i++) {
187 double bi =
data[i] ;
188 for (
unsigned int j=0;j<M.
getCols();j++) {
219 double *vd = v.
data ;
double *d =
data ;
221 for (
unsigned int i=0;i<
colNum;i++)
222 *(vd++) = (*d++) * x;
245 for (
unsigned int i=0;i<
colNum;i++)
273 double *vd = v.
data ;
double *d =
data ;
275 for (
unsigned int i=0;i<
colNum;i++)
276 *(vd++) = (*d++) / x;
300 for (
unsigned int i=0;i<
colNum;i++)
319 double *vd = A.
data ;
double *d =
data ;
321 for (
unsigned int i=0; i<
colNum; i++)
335 "Cannot substract (1x%d) row vector to (1x%d) row vector",
341 for (
unsigned int i=0;i<
colNum;i++)
342 v[i] = (*
this)[i] - m[i];
354 "Cannot add (1x%d) row vector to (1x%d) row vector",
360 for (
unsigned int i=0;i<
colNum;i++)
361 r[i] = (*
this)[i] + v[i];
374 "Cannot add (1x%d) row vector to (1x%d) row vector",
378 for (
unsigned int i=0;i<
colNum;i++)
392 "Cannot substract (1x%d) row vector to (1x%d) row vector",
396 for (
unsigned int i=0;i<
colNum;i++)
462 for(
unsigned int j=0; j< M.
getCols(); j++)
463 (*
this)[j] = M[i][j];
475 "Cannot construct a (1x%d) row vector from a (%dx%d) matrix",
479 for(
unsigned int j=0; j< M.
getCols(); j++)
480 (*
this)[j] = M[0][j];
489 for(
unsigned int j=0; j< v.size(); j++)
498 for(
unsigned int j=0; j< v.size(); j++)
499 (*
this)[j] = (double)(v[j]);
547 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
548 *
this /= sqrt(sum_square) ;
616 if(
dsize!=nrows*ncols) {
618 "Cannot reshape (1x%d) row vector in (%dx%d) matrix",
627 for(
unsigned int i =0; i< nrows; i++)
628 for(
unsigned int j =0; j< ncols; j++)
629 M[i][j]=
data[i*ncols+j];
667 "Unable to insert (1x%d) row vector in (1x%d) row vector at position (%d)",
669 for (
unsigned int j=0; j < v.
size(); j++)
768 unsigned int nrA = A.
getCols();
769 unsigned int nrB = B.
getCols();
771 if (nrA == 0 && nrB == 0) {
789 for (
unsigned int i=0; i<nrA; i++)
792 for (
unsigned int i=0; i<nrB; i++)
801 if (v.
data == NULL) {
803 "Cannot compute mean value of an empty row vector"));
808 for (
unsigned int i = 0; i < v.
getCols(); i++)
822 "Cannot compute mean value of an empty row vector"));
825 std::vector<double> vectorOfDoubles(v.
size());
826 for(
unsigned int i = 0; i < v.
size(); i++) {
827 vectorOfDoubles[i] = v[i];
841 "Cannot compute mean value of an empty row vector"));
844 double mean_value =
mean(v);
845 double sum_squared_diff = 0.0;
846 for(
unsigned int i = 0; i < v.
size(); i++) {
847 sum_squared_diff += (v[i]-mean_value) * (v[i]-mean_value);
850 double divisor = (double) v.
size();
851 if(useBesselCorrection && v.
size() > 1) {
855 return std::sqrt(sum_squared_diff / divisor);
880 typedef std::string::size_type size_type;
885 std::vector<std::string> values(m*n);
886 std::ostringstream oss;
887 std::ostringstream ossFixed;
888 std::ios_base::fmtflags original_flags = oss.flags();
891 ossFixed.setf ( std::ios::fixed, std::ios::floatfield );
893 size_type maxBefore=0;
894 size_type maxAfter=0;
896 for (
unsigned int j=0;j<n;++j){
899 if (oss.str().find(
"e")!=std::string::npos){
901 ossFixed << (*this)[j];
902 oss.str(ossFixed.str());
906 size_type thislen=values[j].size();
907 size_type p=values[j].find(
'.');
909 if (p==std::string::npos){
919 size_type totalLength=length;
923 maxAfter=std::min(maxAfter, totalLength-maxBefore);
924 if (maxAfter==1) maxAfter=0;
929 if (intro) s <<intro;
930 s <<
"["<<m<<
","<<n<<
"]=\n";
933 for (
unsigned int j=0;j<n;j++){
934 size_type p=values[j].find(
'.');
935 s.setf(std::ios::right, std::ios::adjustfield);
936 s.width((std::streamsize)maxBefore);
937 s <<values[j].substr(0,p).c_str();
940 s.setf(std::ios::left, std::ios::adjustfield);
941 if (p!=std::string::npos){
942 s.width((std::streamsize)maxAfter);
943 s <<values[j].substr(p,maxAfter).c_str();
946 s.width((std::streamsize)maxAfter);
956 s.flags(original_flags);
958 return (
int)(maxBefore+maxAfter);
980 for (
unsigned int j=0;j<
colNum;j++) {
994 double sum_square=0.0;
996 for (
unsigned int j=0;j<
colNum;j++) {
1012 for (
unsigned int i=0;i<
dsize;i++) {
1013 double x = *(
data +i); norm += x*x;
1056 unsigned int cncols = c+ncols ;
1060 "Bad column dimension (%d > %d) used to initialize vpRowVector",
1065 for (
unsigned int i=0 ; i < ncols; i++)
1066 (*
this)[i] = v[i+c];
1101 os <<
"vpRowVector " << matrixName
1102 <<
" ("<<
this ->getCols () <<
"); " <<std::endl;
1104 for (
unsigned int j=0; j <
this ->getCols(); ++ j) {
1106 os << matrixName <<
"[" << j
1107 <<
"] = " << (*this)[j] <<
"; " << std::endl;
1110 for (
unsigned int k = 0; k <
sizeof(double); ++ k) {
1111 os <<
"((unsigned char*)&(" << matrixName
1112 <<
"[" << j <<
"]) )[" << k
1113 <<
"] = 0x" <<std::hex<<
1114 (
unsigned int)((
unsigned char*)& ((*this)[j])) [k]
1115 <<
"; " << std::endl;
1119 std::cout << std::endl;
1149 for (
unsigned int j=0; j < this->
getCols(); ++ j) {
1151 if (!(j==(this->
getCols()-1)))
1183 os <<
"([ " << std::endl;
1185 for (
unsigned int j=0; j < this->
getCols(); ++ j) {
1186 os << (*this)[j] <<
", ";
1188 os <<
"]," << std::endl;
1189 os <<
"])" << std::endl;
1226 for (
unsigned int j=0; j <
this ->getCols(); ++ j) {
1227 os << (*this)[j] <<
", ";
1229 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
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)
error that can be emited by ViSP classes.
unsigned int getRows() const
Return the number of rows of the 2D array.
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
Return the number of columns of the 2D array.
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