45 #include <visp3/core/vpArray2D.h>
46 #include <visp3/core/vpColVector.h>
47 #include <visp3/core/vpException.h>
48 #include <visp3/core/vpMatrix.h>
49 #include <visp3/core/vpRowVector.h>
51 #if defined(VISP_HAVE_SIMDLIB)
52 #include <Simd/SimdLib.h>
101 unsigned int v_size =
static_cast<unsigned int>(v.size());
103 for (
unsigned int i = 0; i < v_size; ++i) {
113 unsigned int v_size =
static_cast<unsigned int>(v.size());
115 for (
unsigned int i = 0; i < v_size; ++i) {
116 (*this)[i] =
static_cast<float>(v[i]);
124 for (
unsigned int i = 0; i <
rowNum; ++i) {
125 for (
unsigned int j = 0; j <
colNum; ++j) {
132 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
135 if (
this != &other) {
147 other.rowPtrs =
nullptr;
149 other.data =
nullptr;
179 resize(1,
static_cast<unsigned int>(list.size()),
false);
180 std::copy(list.begin(), list.end(),
data);
191 for (
unsigned int i = 0; i <
colNum; ++i) {
218 unsigned int nelements = x.
getRows();
226 for (
unsigned int i = 0; i < nelements; ++i) {
227 scalar += (*this)[i] * x[i];
257 for (
unsigned int i = 0; i <
colNum; ++i) {
259 unsigned int m_cols = M.
getCols();
260 for (
unsigned int j = 0; j < m_cols; ++j) {
261 c[j] += bi * M[i][j];
294 for (
unsigned int i = 0; i <
colNum; ++i) {
295 *(vd++) = (*d++) * x;
319 for (
unsigned int i = 0; i <
colNum; ++i) {
351 for (
unsigned int i = 0; i <
colNum; ++i) {
352 *(vd++) = (*d++) / x;
377 for (
unsigned int i = 0; i <
colNum; ++i) {
400 for (
unsigned int i = 0; i <
colNum; ++i) {
420 for (
unsigned int i = 0; i <
colNum; ++i) {
421 v[i] = (*this)[i] - m[i];
439 for (
unsigned int i = 0; i <
colNum; ++i) {
440 r[i] = (*this)[i] + v[i];
457 for (
unsigned int i = 0; i <
colNum; ++i) {
475 for (
unsigned int i = 0; i <
colNum; ++i) {
553 unsigned int m_cols = M.
getCols();
554 for (
unsigned int j = 0; j < m_cols; ++j) {
555 (*this)[j] = M[i][j];
571 unsigned int m_cols = M.
getCols();
572 for (
unsigned int j = 0; j < m_cols; ++j) {
573 (*this)[j] = M[0][j];
582 unsigned int v_size =
static_cast<unsigned int>(v.size());
583 for (
unsigned int j = 0; j < v_size; ++j) {
593 unsigned int v_size =
static_cast<unsigned int>(v.size());
594 for (
unsigned int j = 0; j < v_size; ++j) {
595 (*this)[j] =
static_cast<double>(v[j]);
617 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
661 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
662 *
this /= sqrt(sum_square);
736 if (
dsize != (nrows * ncols)) {
748 for (
unsigned int i = 0; i < nrows; ++i) {
749 for (
unsigned int j = 0; j < ncols; ++j) {
750 M[i][j] =
data[(i * ncols) + j];
793 if ((i + v.
size()) > this->size()) {
795 "Unable to insert (1x%d) row vector in (1x%d) row "
796 "vector at position (%d)",
799 unsigned int v_size = v.
size();
800 for (
unsigned int j = 0; j < v_size; ++j) {
801 (*this)[i + j] = v[j];
811 std::vector<double> v(this->
size());
813 unsigned int this_size = this->
size();
814 for (
unsigned int i = 0; i < this_size; ++i) {
912 unsigned int nrA = A.
getCols();
913 unsigned int nrB = B.
getCols();
915 if ((nrA == 0) && (nrB == 0)) {
933 for (
unsigned int i = 0; i < nrA; ++i) {
937 for (
unsigned int i = 0; i < nrB; ++i) {
947 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
953 unsigned int v_col = v.
getCols();
954 for (
unsigned int i = 0; i < v_col; ++i) {
966 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
980 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
984 double mean_value =
mean(v);
985 double sum_squared_diff = 0.0;
986 unsigned int v_size = v.
size();
987 for (
unsigned int i = 0; i < v_size; ++i) {
988 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
991 double divisor =
static_cast<double>(v.
size());
992 if (useBesselCorrection && (v.
size() > 1)) {
993 divisor = divisor - 1;
996 return std::sqrt(sum_squared_diff / divisor);
1020 typedef std::string::size_type size_type;
1025 std::vector<std::string> values(m * n);
1026 std::ostringstream oss;
1027 std::ostringstream ossFixed;
1028 std::ios_base::fmtflags original_flags = oss.flags();
1031 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1033 size_type maxBefore = 0;
1034 size_type maxAfter = 0;
1036 for (
unsigned int j = 0; j < n; ++j) {
1039 if (oss.str().find(
"e") != std::string::npos) {
1041 ossFixed << (*this)[j];
1042 oss.str(ossFixed.str());
1045 values[j] = oss.str();
1046 size_type thislen = values[j].size();
1047 size_type p = values[j].find(
'.');
1049 if (p == std::string::npos) {
1059 size_type totalLength = length;
1063 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1064 if (maxAfter == 1) {
1074 s <<
"[" << m <<
"," << n <<
"]=\n";
1077 for (
unsigned int j = 0; j < n; ++j) {
1078 size_type p = values[j].find(
'.');
1079 s.setf(std::ios::right, std::ios::adjustfield);
1080 s.width(
static_cast<std::streamsize
>(maxBefore));
1081 s << values[j].substr(0, p).c_str();
1084 s.setf(std::ios::left, std::ios::adjustfield);
1085 if (p != std::string::npos) {
1086 s.width(
static_cast<std::streamsize
>(maxAfter));
1087 s << values[j].substr(p, maxAfter).c_str();
1090 assert(maxAfter > 1);
1091 s.width(
static_cast<std::streamsize
> (maxAfter));
1100 s.flags(original_flags);
1102 return static_cast<int>(maxBefore + maxAfter);
1114 for (
unsigned int j = 0; j <
colNum; ++j) {
1129 double sum_square = 0.0;
1131 for (
unsigned int j = 0; j <
colNum; ++j) {
1133 sum_square += x * x;
1151 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1161 double vpRowVector::euclideanNorm()
const {
return frobeniusNorm(); }
1205 unsigned int cncols = c + ncols;
1212 if (this->
rowPtrs ==
nullptr) {
1215 for (
unsigned int i = 0; i < ncols; ++i) {
1216 (*this)[i] = v[i + c];
1255 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1257 unsigned int this_cols = this->
getCols();
1258 for (
unsigned int j = 0; j < this_cols; ++j) {
1260 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1263 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1264 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1265 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[j]))[k]) <<
"; " << std::endl;
1269 std::cout << std::endl;
1303 unsigned int this_cols = this->
getCols();
1304 for (
unsigned int j = 0; j < this_cols; ++j) {
1306 if (!(j == (this->
getCols() - 1))) {
1343 os <<
"([ " << std::endl;
1345 unsigned int this_cols = this->
getCols();
1346 for (
unsigned int j = 0; j < this_cols; ++j) {
1347 os << (*this)[j] <<
", ";
1349 os <<
"]," << std::endl;
1350 os <<
"])" << std::endl;
1392 unsigned int this_cols = this->
getCols();
1393 for (
unsigned int j = 0; j < this_cols; ++j) {
1394 os << (*this)[j] <<
", ";
1396 os <<
"]" << std::endl;
1418 #if defined(VISP_HAVE_SIMDLIB)
1421 for (
unsigned int i = 0; i <
dsize; ++i) {
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=(const vpRowVector &v)
Copy operator. Allow operation such as A = v.
vpRowVector & operator/=(double x)
double frobeniusNorm() 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
void init(const vpRowVector &v, unsigned int c, unsigned int ncols)
vpRowVector operator+(const vpRowVector &v) const
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
vpRowVector hadamard(const vpRowVector &v) const