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>
99 unsigned int v_size = v.
size();
101 for (
unsigned int i = 0; i < v_size; ++i) {
111 unsigned int v_size = v.
size();
113 for (
unsigned int i = 0; i < v_size; ++i) {
114 (*this)[i] =
static_cast<float>(v[i]);
122 for (
unsigned int i = 0; i <
rowNum; ++i) {
123 for (
unsigned int j = 0; j <
colNum; ++j) {
130 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
133 if (
this != &other) {
145 other.rowPtrs =
nullptr;
147 other.data =
nullptr;
173 resize(1,
static_cast<unsigned int>(list.size()),
false);
174 std::copy(list.begin(), list.end(),
data);
185 for (
unsigned int i = 0; i <
colNum; ++i) {
212 unsigned int nelements = x.
getRows();
220 for (
unsigned int i = 0; i < nelements; ++i) {
221 scalar += (*this)[i] * x[i];
251 for (
unsigned int i = 0; i <
colNum; ++i) {
253 unsigned int m_cols = M.
getCols();
254 for (
unsigned int j = 0; j < m_cols; ++j) {
255 c[j] += bi * M[i][j];
288 for (
unsigned int i = 0; i <
colNum; ++i) {
289 *(vd++) = (*d++) * x;
313 for (
unsigned int i = 0; i <
colNum; ++i) {
345 for (
unsigned int i = 0; i <
colNum; ++i) {
346 *(vd++) = (*d++) / x;
371 for (
unsigned int i = 0; i <
colNum; ++i) {
394 for (
unsigned int i = 0; i <
colNum; ++i) {
414 for (
unsigned int i = 0; i <
colNum; ++i) {
415 v[i] = (*this)[i] - m[i];
433 for (
unsigned int i = 0; i <
colNum; ++i) {
434 r[i] = (*this)[i] + v[i];
451 for (
unsigned int i = 0; i <
colNum; ++i) {
469 for (
unsigned int i = 0; i <
colNum; ++i) {
543 unsigned int m_cols = M.
getCols();
544 for (
unsigned int j = 0; j < m_cols; ++j) {
545 (*this)[j] = M[i][j];
560 unsigned int m_cols = M.
getCols();
561 for (
unsigned int j = 0; j < m_cols; ++j) {
562 (*this)[j] = M[0][j];
571 unsigned int v_size = v.
size();
572 for (
unsigned int j = 0; j < v_size; ++j) {
581 unsigned int v_size = v.
size();
582 for (
unsigned int j = 0; j < v_size; ++j) {
583 (*this)[j] =
static_cast<double>(v[j]);
605 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
649 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
650 *
this /= sqrt(sum_square);
720 if (
dsize != (nrows * ncols)) {
732 for (
unsigned int i = 0; i < nrows; ++i) {
733 for (
unsigned int j = 0; j < ncols; ++j) {
734 M[i][j] =
data[(i * ncols) + j];
772 if ( (i + v.
size()) > this->size()) {
774 "Unable to insert (1x%d) row vector in (1x%d) row "
775 "vector at position (%d)",
778 unsigned int v_size = v.
size();
779 for (
unsigned int j = 0; j < v_size; ++j) {
780 (*this)[i + j] = v[j];
790 std::vector<double> v(this->
size());
792 unsigned int this_size = this->
size();
793 for (
unsigned int i = 0; i < this_size; ++i) {
891 unsigned int nrA = A.
getCols();
892 unsigned int nrB = B.
getCols();
894 if ((nrA == 0) && (nrB == 0)) {
912 for (
unsigned int i = 0; i < nrA; ++i) {
916 for (
unsigned int i = 0; i < nrB; ++i) {
926 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
932 unsigned int v_col = v.
getCols();
933 for (
unsigned int i = 0; i < v_col; ++i) {
945 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
959 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
963 double mean_value =
mean(v);
964 double sum_squared_diff = 0.0;
965 unsigned int v_size = v.
size();
966 for (
unsigned int i = 0; i < v_size; ++i) {
967 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
970 double divisor =
static_cast<double>(v.
size());
971 if (useBesselCorrection && (v.
size() > 1)) {
972 divisor = divisor - 1;
975 return std::sqrt(sum_squared_diff / divisor);
999 typedef std::string::size_type size_type;
1004 std::vector<std::string> values(m * n);
1005 std::ostringstream oss;
1006 std::ostringstream ossFixed;
1007 std::ios_base::fmtflags original_flags = oss.flags();
1010 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1012 size_type maxBefore = 0;
1013 size_type maxAfter = 0;
1015 for (
unsigned int j = 0; j < n; ++j) {
1018 if (oss.str().find(
"e") != std::string::npos) {
1020 ossFixed << (*this)[j];
1021 oss.str(ossFixed.str());
1024 values[j] = oss.str();
1025 size_type thislen = values[j].size();
1026 size_type p = values[j].find(
'.');
1028 if (p == std::string::npos) {
1038 size_type totalLength = length;
1042 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1043 if (maxAfter == 1) {
1053 s <<
"[" << m <<
"," << n <<
"]=\n";
1056 for (
unsigned int j = 0; j < n; ++j) {
1057 size_type p = values[j].find(
'.');
1058 s.setf(std::ios::right, std::ios::adjustfield);
1059 s.width(
static_cast<std::streamsize
>(maxBefore));
1060 s << values[j].substr(0, p).c_str();
1063 s.setf(std::ios::left, std::ios::adjustfield);
1064 if (p != std::string::npos) {
1065 s.width(
static_cast<std::streamsize
>(maxAfter));
1066 s << values[j].substr(p, maxAfter).c_str();
1069 assert(maxAfter > 1);
1070 s.width(
static_cast<std::streamsize
> (maxAfter));
1079 s.flags(original_flags);
1081 return static_cast<int>(maxBefore + maxAfter);
1103 for (
unsigned int j = 0; j <
colNum; ++j) {
1118 double sum_square = 0.0;
1120 for (
unsigned int j = 0; j <
colNum; ++j) {
1122 sum_square += x * x;
1140 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1190 unsigned int cncols = c + ncols;
1197 if (this->
rowPtrs ==
nullptr) {
1200 for (
unsigned int i = 0; i < ncols; ++i) {
1201 (*this)[i] = v[i + c];
1237 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1239 unsigned int this_cols = this->
getCols();
1240 for (
unsigned int j = 0; j < this_cols; ++j) {
1242 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1245 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1246 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1247 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[j]))[k]) <<
"; " << std::endl;
1251 std::cout << std::endl;
1281 unsigned int this_cols = this->
getCols();
1282 for (
unsigned int j = 0; j < this_cols; ++j) {
1284 if (!(j == (this->
getCols() - 1))) {
1317 os <<
"([ " << std::endl;
1319 unsigned int this_cols = this->
getCols();
1320 for (
unsigned int j = 0; j < this_cols; ++j) {
1321 os << (*this)[j] <<
", ";
1323 os <<
"]," << std::endl;
1324 os <<
"])" << std::endl;
1362 unsigned int this_cols = this->
getCols();
1363 for (
unsigned int j = 0; j < this_cols; ++j) {
1364 os << (*this)[j] <<
", ";
1366 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.
vpColVector operator*(const double &x, const vpColVector &v)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
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