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];
749 if (i + v.
size() > this->size())
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;
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
double * data
Address of the first element of the data array.
double ** rowPtrs
Address of the first element of each rows.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int rowNum
Number of rows in the array.
unsigned int dsize
Current array size (rowNum * colNum)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
unsigned int colNum
Number of columns in the array.
Implementation of column vector and the associated operations.
error that can be emited by ViSP classes.
@ dimensionError
Bad dimension.
VISP_EXPORT vpImagePoint operator*(const vpImagePoint &ip1, double scale)
static double getMedian(const std::vector< double > &v)
static Type maximum(const Type &a, const Type &b)
static bool equal(double x, double y, double s=0.001)
Implementation of a matrix and operations on matrices.
Implementation of row vector and the associated operations.
bool operator==(const vpRowVector &v) const
Comparison operator.
vpRowVector & operator/=(double x)
double frobeniusNorm() const
vp_deprecated double euclideanNorm() const
void resize(unsigned int i, bool flagNullify=true)
vpRowVector & operator+=(vpRowVector v)
bool operator!=(const vpRowVector &v) const
vpRowVector operator-() const
static double mean(const vpRowVector &v)
void insert(unsigned int i, const vpRowVector &v)
vpRowVector & operator,(double val)
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
vpColVector transpose() const
vpRowVector operator+(const vpRowVector &v) const
vpRowVector & operator=(const vpRowVector &v)
Copy operator. Allow operation such as A = v.
vp_deprecated void init()
std::ostream & maplePrint(std::ostream &os) const
double operator*(const vpColVector &x) const
std::ostream & cppPrint(std::ostream &os, const std::string &matrixName="A", bool octet=false) const
vpRowVector & operator*=(double x)
vpRowVector & normalize()
std::ostream & csvPrint(std::ostream &os) const
vpRowVector operator/(double x) const
void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols)
static double median(const vpRowVector &v)
std::vector< double > toStdVector() const
vpRowVector & operator<<(const vpRowVector &v)
static double stdev(const vpRowVector &v, bool useBesselCorrection=false)
vpRowVector & operator-=(vpRowVector v)
int print(std::ostream &s, unsigned int length, char const *intro=0) const
std::ostream & matlabPrint(std::ostream &os) const