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;
170 resize(1,
static_cast<unsigned int>(list.size()),
false);
171 std::copy(list.begin(), list.end(),
data);
181 for (
unsigned int i = 0; i <
colNum; i++) {
207 unsigned int nelements = x.
getRows();
215 for (
unsigned int i = 0; i < nelements; i++) {
216 scalar += (*this)[i] * x[i];
246 for (
unsigned int i = 0; i <
colNum; i++) {
248 for (
unsigned int j = 0; j < M.
getCols(); j++) {
249 c[j] += bi * M[i][j];
282 for (
unsigned int i = 0; i <
colNum; i++)
283 *(vd++) = (*d++) * x;
306 for (
unsigned int i = 0; i <
colNum; i++)
337 for (
unsigned int i = 0; i <
colNum; i++)
338 *(vd++) = (*d++) / x;
362 for (
unsigned int i = 0; i <
colNum; i++)
384 for (
unsigned int i = 0; i <
colNum; i++)
403 for (
unsigned int i = 0; i <
colNum; i++)
404 v[i] = (*
this)[i] - m[i];
421 for (
unsigned int i = 0; i <
colNum; i++)
422 r[i] = (*
this)[i] + v[i];
438 for (
unsigned int i = 0; i <
colNum; i++)
455 for (
unsigned int i = 0; i <
colNum; i++)
528 for (
unsigned int j = 0; j < M.
getCols(); j++)
529 (*
this)[j] = M[i][j];
544 for (
unsigned int j = 0; j < M.
getCols(); j++)
545 (*
this)[j] = M[0][j];
553 for (
unsigned int j = 0; j < v.size(); j++)
561 for (
unsigned int j = 0; j < v.size(); j++)
562 (*
this)[j] = (double)(v[j]);
583 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
627 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
628 *
this /= sqrt(sum_square);
698 if (
dsize != nrows * ncols) {
708 for (
unsigned int i = 0; i < nrows; i++)
709 for (
unsigned int j = 0; j < ncols; j++)
710 M[i][j] =
data[i * ncols + j];
746 if (i + v.
size() > this->size())
748 "Unable to insert (1x%d) row vector in (1x%d) row "
749 "vector at position (%d)",
751 for (
unsigned int j = 0; j < v.
size(); j++)
752 (*
this)[i + j] = v[j];
761 std::vector<double> v(this->
size());
763 for (
unsigned int i = 0; i < this->
size(); i++)
860 unsigned int nrA = A.
getCols();
861 unsigned int nrB = B.
getCols();
863 if (nrA == 0 && nrB == 0) {
881 for (
unsigned int i = 0; i < nrA; i++)
884 for (
unsigned int i = 0; i < nrB; i++)
893 if (v.
data == NULL || v.
size() == 0) {
899 for (
unsigned int i = 0; i < v.
getCols(); i++)
910 if (v.
data == NULL || v.
size() == 0) {
924 if (v.
data == NULL || v.
size() == 0) {
928 double mean_value =
mean(v);
929 double sum_squared_diff = 0.0;
930 for (
unsigned int i = 0; i < v.
size(); i++) {
931 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
934 double divisor = (double)v.
size();
935 if (useBesselCorrection && v.
size() > 1) {
936 divisor = divisor - 1;
939 return std::sqrt(sum_squared_diff / divisor);
963 typedef std::string::size_type size_type;
968 std::vector<std::string> values(m * n);
969 std::ostringstream oss;
970 std::ostringstream ossFixed;
971 std::ios_base::fmtflags original_flags = oss.flags();
974 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
976 size_type maxBefore = 0;
977 size_type maxAfter = 0;
979 for (
unsigned int j = 0; j < n; ++j) {
982 if (oss.str().find(
"e") != std::string::npos) {
984 ossFixed << (*this)[j];
985 oss.str(ossFixed.str());
988 values[j] = oss.str();
989 size_type thislen = values[j].size();
990 size_type p = values[j].find(
'.');
992 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();
1029 assert(maxAfter > 1);
1030 s.width((std::streamsize)maxAfter);
1039 s.flags(original_flags);
1041 return (
int)(maxBefore + maxAfter);
1063 for (
unsigned int j = 0; j <
colNum; j++) {
1078 double sum_square = 0.0;
1080 for (
unsigned int j = 0; j <
colNum; j++) {
1082 sum_square += x * x;
1148 unsigned int cncols = c + ncols;
1156 for (
unsigned int i = 0; i < ncols; i++)
1157 (*
this)[i] = v[i + c];
1192 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1194 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1196 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1198 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1199 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1200 << (
unsigned int)((
unsigned char *)&((*this)[j]))[k] <<
"; " << std::endl;
1204 std::cout << std::endl;
1234 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1236 if (!(j == (this->
getCols() - 1)))
1268 os <<
"([ " << std::endl;
1270 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1271 os << (*this)[j] <<
", ";
1273 os <<
"]," << std::endl;
1274 os <<
"])" << std::endl;
1311 for (
unsigned int j = 0; j < this->
getCols(); ++j) {
1312 os << (*this)[j] <<
", ";
1314 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