47 #include <visp3/core/vpArray2D.h>
48 #include <visp3/core/vpColVector.h>
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpException.h>
51 #include <visp3/core/vpMatrix.h>
52 #include <visp3/core/vpRowVector.h>
98 resize((
unsigned int)v.size());
99 for (
unsigned int i = 0; i < v.size(); i++)
108 resize((
unsigned int)v.size());
109 for (
unsigned int i = 0; i < v.size(); i++)
110 (*
this)[i] = (float)v[i];
117 for (
unsigned int i = 0; i <
rowNum; i++) {
118 for (
unsigned int j = 0; j <
colNum; j++) {
125 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
128 if (
this != &other) {
140 other.rowPtrs = NULL;
168 resize(1,
static_cast<unsigned int>(list.size()),
false);
169 std::copy(list.begin(), list.end(),
data);
179 for (
unsigned int i = 0; i <
colNum; i++) {
205 unsigned int nelements = x.
getRows();
213 for (
unsigned int i = 0; i < nelements; i++) {
214 scalar += (*this)[i] * x[i];
244 for (
unsigned int i = 0; i <
colNum; i++) {
246 for (
unsigned int j = 0; j < M.
getCols(); j++) {
247 c[j] += bi * M[i][j];
280 for (
unsigned int i = 0; i <
colNum; i++)
281 *(vd++) = (*d++) * x;
304 for (
unsigned int i = 0; i <
colNum; i++)
335 for (
unsigned int i = 0; i <
colNum; i++)
336 *(vd++) = (*d++) / x;
360 for (
unsigned int i = 0; i <
colNum; i++)
382 for (
unsigned int i = 0; i <
colNum; i++)
401 for (
unsigned int i = 0; i <
colNum; i++)
402 v[i] = (*
this)[i] - m[i];
419 for (
unsigned int i = 0; i <
colNum; i++)
420 r[i] = (*
this)[i] + v[i];
436 for (
unsigned int i = 0; i <
colNum; i++)
453 for (
unsigned int i = 0; i <
colNum; i++)
526 for (
unsigned int j = 0; j < M.
getCols(); j++)
527 (*
this)[j] = M[i][j];
542 for (
unsigned int j = 0; j < M.
getCols(); j++)
543 (*
this)[j] = M[0][j];
551 for (
unsigned int j = 0; j < v.size(); j++)
559 for (
unsigned int j = 0; j < v.size(); j++)
560 (*
this)[j] = (double)(v[j]);
581 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
625 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
626 *
this /= sqrt(sum_square);
696 if (
dsize != nrows * ncols) {
707 for (
unsigned int i = 0; i < nrows; i++)
708 for (
unsigned int j = 0; j < ncols; j++)
709 M[i][j] =
data[i * ncols + j];
745 if (i + v.
size() > this->size())
747 "Unable to insert (1x%d) row vector in (1x%d) row "
748 "vector at position (%d)",
750 for (
unsigned int j = 0; j < v.
size(); j++)
751 (*
this)[i + j] = v[j];
760 std::vector<double> v(this->
size());
762 for (
unsigned int i = 0; i < this->
size(); i++)
859 unsigned int nrA = A.
getCols();
860 unsigned int nrB = B.
getCols();
862 if (nrA == 0 && nrB == 0) {
880 for (
unsigned int i = 0; i < nrA; i++)
883 for (
unsigned int i = 0; i < nrB; i++)
892 if (v.
data == NULL || v.
size() == 0) {
898 for (
unsigned int i = 0; i < v.
getCols(); i++)
909 if (v.
data == NULL || v.
size() == 0) {
923 if (v.
data == NULL || v.
size() == 0) {
927 double mean_value =
mean(v);
928 double sum_squared_diff = 0.0;
929 for (
unsigned int i = 0; i < v.
size(); i++) {
930 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
933 double divisor = (double)v.
size();
934 if (useBesselCorrection && v.
size() > 1) {
935 divisor = divisor - 1;
938 return std::sqrt(sum_squared_diff / divisor);
962 typedef std::string::size_type size_type;
967 std::vector<std::string> values(m * n);
968 std::ostringstream oss;
969 std::ostringstream ossFixed;
970 std::ios_base::fmtflags original_flags = oss.flags();
973 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
975 size_type maxBefore = 0;
976 size_type maxAfter = 0;
978 for (
unsigned int j = 0; j < n; ++j) {
981 if (oss.str().find(
"e") != std::string::npos) {
983 ossFixed << (*this)[j];
984 oss.str(ossFixed.str());
987 values[j] = oss.str();
988 size_type thislen = values[j].size();
989 size_type p = values[j].find(
'.');
991 if (p == std::string::npos) {
1001 size_type totalLength = length;
1005 maxAfter = (std::min)(maxAfter, totalLength - maxBefore);
1014 s <<
"[" << m <<
"," << n <<
"]=\n";
1017 for (
unsigned int j = 0; j < n; j++) {
1018 size_type p = values[j].find(
'.');
1019 s.setf(std::ios::right, std::ios::adjustfield);
1020 s.width((std::streamsize)maxBefore);
1021 s << values[j].substr(0, p).c_str();
1024 s.setf(std::ios::left, std::ios::adjustfield);
1025 if (p != std::string::npos) {
1026 s.width((std::streamsize)maxAfter);
1027 s << values[j].substr(p, maxAfter).c_str();
1030 assert(maxAfter > 1);
1031 s.width((std::streamsize)maxAfter);
1040 s.flags(original_flags);
1042 return (
int)(maxBefore + maxAfter);
1064 for (
unsigned int j = 0; j <
colNum; j++) {
1079 double sum_square = 0.0;
1081 for (
unsigned int j = 0; j <
colNum; j++) {
1083 sum_square += x * x;
1101 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1151 unsigned int cncols = c + ncols;
1159 for (
unsigned int i = 0; i < ncols; i++)
1160 (*
this)[i] = v[i + c];
1195 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1197 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1199 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1202 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1203 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1204 << (
unsigned int)((
unsigned char *)&((*this)[j]))[k] <<
"; " << std::endl;
1208 std::cout << std::endl;
1238 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1240 if (!(j == (this->
getCols() - 1)))
1272 os <<
"([ " << std::endl;
1274 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1275 os << (*this)[j] <<
", ";
1277 os <<
"]," << std::endl;
1278 os <<
"])" << std::endl;
1315 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1316 os << (*this)[j] <<
", ";
1318 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 emitted 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 threshold=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