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];
666 std::vector<double> v(this->
size());
668 for (
unsigned int i = 0; i < this->
size(); i++)
765 unsigned int nrA = A.
getCols();
766 unsigned int nrB = B.
getCols();
768 if (nrA == 0 && nrB == 0) {
786 for (
unsigned int i = 0; i < nrA; i++)
789 for (
unsigned int i = 0; i < nrB; i++)
798 if (v.
data == NULL || v.
size() == 0) {
804 for (
unsigned int i = 0; i < v.
getCols(); i++)
815 if (v.
data == NULL || v.
size() == 0) {
829 if (v.
data == NULL || v.
size() == 0) {
833 double mean_value =
mean(v);
834 double sum_squared_diff = 0.0;
835 for (
unsigned int i = 0; i < v.
size(); i++) {
836 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
839 double divisor = (double)v.
size();
840 if (useBesselCorrection && v.
size() > 1) {
841 divisor = divisor - 1;
844 return std::sqrt(sum_squared_diff / divisor);
868 typedef std::string::size_type size_type;
873 std::vector<std::string> values(m * n);
874 std::ostringstream oss;
875 std::ostringstream ossFixed;
876 std::ios_base::fmtflags original_flags = oss.flags();
879 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
881 size_type maxBefore = 0;
882 size_type maxAfter = 0;
884 for (
unsigned int j = 0; j < n; ++j) {
887 if (oss.str().find(
"e") != std::string::npos) {
889 ossFixed << (*this)[j];
890 oss.str(ossFixed.str());
893 values[j] = oss.str();
894 size_type thislen = values[j].size();
895 size_type p = values[j].find(
'.');
897 if (p == std::string::npos) {
906 size_type totalLength = length;
910 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
919 s <<
"[" << m <<
"," << n <<
"]=\n";
922 for (
unsigned int j = 0; j < n; j++) {
923 size_type p = values[j].find(
'.');
924 s.setf(std::ios::right, std::ios::adjustfield);
925 s.width((std::streamsize)maxBefore);
926 s << values[j].substr(0, p).c_str();
929 s.setf(std::ios::left, std::ios::adjustfield);
930 if (p != std::string::npos) {
931 s.width((std::streamsize)maxAfter);
932 s << values[j].substr(p, maxAfter).c_str();
934 assert(maxAfter > 1);
935 s.width((std::streamsize)maxAfter);
944 s.flags(original_flags);
946 return (
int)(maxBefore + maxAfter);
968 for (
unsigned int j = 0; j <
colNum; j++) {
983 double sum_square = 0.0;
985 for (
unsigned int j = 0; j <
colNum; j++) {
1001 for (
unsigned int i = 0; i <
dsize; i++) {
1002 double x = *(
data + i);
1046 unsigned int cncols = c + ncols;
1054 for (
unsigned int i = 0; i < ncols; i++)
1055 (*
this)[i] = v[i + c];
1090 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1092 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1094 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1096 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1097 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1098 << (
unsigned int)((
unsigned char *)&((*this)[j]))[k] <<
"; " << std::endl;
1102 std::cout << std::endl;
1132 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1134 if (!(j == (this->
getCols() - 1)))
1166 os <<
"([ " << std::endl;
1168 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1169 os << (*this)[j] <<
", ";
1171 os <<
"]," << std::endl;
1172 os <<
"])" << std::endl;
1209 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1210 os << (*this)[j] <<
", ";
1212 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)
std::vector< double > toStdVector()
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
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