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++) {
127 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 130 if (
this != &other) {
142 other.rowPtrs = NULL;
171 resize(1, static_cast<unsigned int>(list.size()),
false);
172 std::copy(list.begin(), list.end(),
data);
182 for (
unsigned int i = 0; i <
colNum; i++) {
191 return !(*
this == v);
210 unsigned int nelements = x.
getRows();
218 for (
unsigned int i = 0; i < nelements; i++) {
219 scalar += (*this)[i] * x[i];
249 for (
unsigned int i = 0; i <
colNum; i++) {
251 for (
unsigned int j = 0; j < M.
getCols(); j++) {
252 c[j] += bi * M[i][j];
285 for (
unsigned int i = 0; i <
colNum; i++)
286 *(vd++) = (*d++) * x;
309 for (
unsigned int i = 0; i <
colNum; i++)
340 for (
unsigned int i = 0; i <
colNum; i++)
341 *(vd++) = (*d++) / x;
365 for (
unsigned int i = 0; i <
colNum; i++)
387 for (
unsigned int i = 0; i <
colNum; i++)
406 for (
unsigned int i = 0; i <
colNum; i++)
407 v[i] = (*
this)[i] - m[i];
424 for (
unsigned int i = 0; i <
colNum; i++)
425 r[i] = (*
this)[i] + v[i];
441 for (
unsigned int i = 0; i <
colNum; i++)
458 for (
unsigned int i = 0; i <
colNum; i++)
531 for (
unsigned int j = 0; j < M.
getCols(); j++)
532 (*
this)[j] = M[i][j];
547 for (
unsigned int j = 0; j < M.
getCols(); j++)
548 (*
this)[j] = M[0][j];
556 for (
unsigned int j = 0; j < v.size(); j++)
564 for (
unsigned int j = 0; j < v.size(); j++)
565 (*
this)[j] = (double)(v[j]);
586 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 630 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
631 *
this /= sqrt(sum_square);
701 if (
dsize != nrows * ncols) {
711 for (
unsigned int i = 0; i < nrows; i++)
712 for (
unsigned int j = 0; j < ncols; j++)
713 M[i][j] =
data[i * ncols + j];
751 "Unable to insert (1x%d) row vector in (1x%d) row " 752 "vector at position (%d)",
754 for (
unsigned int j = 0; j < v.
size(); j++)
755 (*
this)[i + j] = v[j];
764 std::vector<double> v(this->
size());
766 for (
unsigned int i = 0; i < this->
size(); i++)
863 unsigned int nrA = A.
getCols();
864 unsigned int nrB = B.
getCols();
866 if (nrA == 0 && nrB == 0) {
884 for (
unsigned int i = 0; i < nrA; i++)
887 for (
unsigned int i = 0; i < nrB; i++)
896 if (v.
data == NULL || v.
size() == 0) {
902 for (
unsigned int i = 0; i < v.
getCols(); i++)
913 if (v.
data == NULL || v.
size() == 0) {
927 if (v.
data == NULL || v.
size() == 0) {
931 double mean_value =
mean(v);
932 double sum_squared_diff = 0.0;
933 for (
unsigned int i = 0; i < v.
size(); i++) {
934 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
937 double divisor = (double)v.
size();
938 if (useBesselCorrection && v.
size() > 1) {
939 divisor = divisor - 1;
942 return std::sqrt(sum_squared_diff / divisor);
966 typedef std::string::size_type size_type;
971 std::vector<std::string> values(m * n);
972 std::ostringstream oss;
973 std::ostringstream ossFixed;
974 std::ios_base::fmtflags original_flags = oss.flags();
977 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
979 size_type maxBefore = 0;
980 size_type maxAfter = 0;
982 for (
unsigned int j = 0; j < n; ++j) {
985 if (oss.str().find(
"e") != std::string::npos) {
987 ossFixed << (*this)[j];
988 oss.str(ossFixed.str());
991 values[j] = oss.str();
992 size_type thislen = values[j].size();
993 size_type p = values[j].find(
'.');
995 if (p == std::string::npos) {
1004 size_type totalLength = length;
1008 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1017 s <<
"[" << m <<
"," << n <<
"]=\n";
1020 for (
unsigned int j = 0; j < n; j++) {
1021 size_type p = values[j].find(
'.');
1022 s.setf(std::ios::right, std::ios::adjustfield);
1023 s.width((std::streamsize)maxBefore);
1024 s << values[j].substr(0, p).c_str();
1027 s.setf(std::ios::left, std::ios::adjustfield);
1028 if (p != std::string::npos) {
1029 s.width((std::streamsize)maxAfter);
1030 s << values[j].substr(p, maxAfter).c_str();
1032 assert(maxAfter > 1);
1033 s.width((std::streamsize)maxAfter);
1042 s.flags(original_flags);
1044 return (
int)(maxBefore + maxAfter);
1066 for (
unsigned int j = 0; j <
colNum; j++) {
1081 double sum_square = 0.0;
1083 for (
unsigned int j = 0; j <
colNum; j++) {
1085 sum_square += x * x;
1154 unsigned int cncols = c + ncols;
1162 for (
unsigned int i = 0; i < ncols; i++)
1163 (*
this)[i] = v[i + c];
1198 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1200 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1202 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1204 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1205 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1206 << (
unsigned int)((
unsigned char *)&((*this)[j]))[k] <<
"; " << std::endl;
1210 std::cout << std::endl;
1240 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1242 if (!(j == (this->
getCols() - 1)))
1274 os <<
"([ " << std::endl;
1276 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1277 os << (*this)[j] <<
", ";
1279 os <<
"]," << std::endl;
1280 os <<
"])" << std::endl;
1317 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1318 os << (*this)[j] <<
", ";
1320 os <<
"]" << std::endl;
vpRowVector & operator/=(double x)
Implementation of a matrix and operations on matrices.
vpRowVector & normalize()
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
static double median(const vpRowVector &v)
Implementation of row vector and the associated operations.
static double getMedian(const std::vector< double > &v)
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
std::vector< double > toStdVector()
static bool equal(double x, double y, double s=0.001)
error that can be emited by ViSP classes.
static double mean(const vpRowVector &v)
vpRowVector operator+(const vpRowVector &v) const
vp_deprecated void init()
double * data
Address of the first element of the data array.
Implementation of a generic 2D array used as base class for matrices and vectors. ...
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
static double stdev(const vpRowVector &v, bool useBesselCorrection=false)
static Type maximum(const Type &a, const Type &b)
vpColVector transpose() const
unsigned int rowNum
Number of rows in the array.
std::ostream & matlabPrint(std::ostream &os) const
vp_deprecated double euclideanNorm() const
double operator*(const vpColVector &x) const
vpRowVector & operator-=(vpRowVector v)
unsigned int getRows() const
double frobeniusNorm() const
std::ostream & maplePrint(std::ostream &os) const
vpRowVector operator-() const
unsigned int colNum
Number of columns in the array.
vpRowVector & operator+=(vpRowVector v)
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
std::ostream & csvPrint(std::ostream &os) const
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)
vpRowVector operator/(double x) const
void resize(unsigned int i, bool flagNullify=true)
double ** rowPtrs
Address of the first element of each rows.
bool operator==(const vpRowVector &v) const
Comparison operator.
vpRowVector & operator,(double val)
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
void insert(unsigned int i, const vpRowVector &v)
bool operator!=(const vpRowVector &v) const