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>
77 unsigned int k = v.colNum;
119 unsigned int v_size =
static_cast<unsigned int>(v.size());
121 for (
unsigned int i = 0; i < v_size; ++i) {
131 unsigned int v_size =
static_cast<unsigned int>(v.size());
133 for (
unsigned int i = 0; i < v_size; ++i) {
134 (*this)[i] =
static_cast<float>(v[i]);
142 for (
unsigned int i = 0; i <
rowNum; ++i) {
143 for (
unsigned int j = 0; j <
colNum; ++j) {
150#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
181 resize(1,
static_cast<unsigned int>(list.size()),
false);
182 std::copy(list.begin(), list.end(),
data);
193 for (
unsigned int i = 0; i <
colNum; ++i) {
194 if (!
vpMath::equal(
data[i], v.data[i], std::numeric_limits<double>::epsilon())) {
220 unsigned int nelements = x.getRows();
228 for (
unsigned int i = 0; i < nelements; ++i) {
229 scalar += (*this)[i] * x[i];
259 for (
unsigned int i = 0; i <
colNum; ++i) {
261 unsigned int m_cols = M.
getCols();
262 for (
unsigned int j = 0; j < m_cols; ++j) {
263 c[j] += bi * M[i][j];
296 for (
unsigned int i = 0; i <
colNum; ++i) {
322 for (
unsigned int i = 0; i <
colNum; ++i) {
354 for (
unsigned int i = 0; i <
colNum; ++i) {
381 for (
unsigned int i = 0; i <
colNum; ++i) {
404 for (
unsigned int i = 0; i <
colNum; ++i) {
425 for (
unsigned int i = 0; i <
colNum; ++i) {
426 v[i] = (*this)[i] - m[i];
437 if (
getCols() != v.getCols()) {
444 for (
unsigned int i = 0; i <
colNum; ++i) {
445 r[i] = (*this)[i] + v[i];
457 if (
getCols() != v.getCols()) {
462 for (
unsigned int i = 0; i <
colNum; ++i) {
475 if (
getCols() != v.getCols()) {
480 for (
unsigned int i = 0; i <
colNum; ++i) {
537 memcpy(v.data,
data,
colNum *
sizeof(
double));
558 unsigned int m_cols = M.
getCols();
559 for (
unsigned int j = 0; j < m_cols; ++j) {
560 (*this)[j] = M[i][j];
573 throw(vpException(vpException::dimensionError,
"Cannot construct a (1x%d) row vector from a (%dx%d) matrix",
574 M.getCols(), M.getRows(), M.getCols()));
576 unsigned int m_cols = M.
getCols();
577 for (
unsigned int j = 0; j < m_cols; ++j) {
578 (*this)[j] = M[0][j];
587 unsigned int v_size =
static_cast<unsigned int>(v.size());
588 for (
unsigned int j = 0; j < v_size; ++j) {
598 unsigned int v_size =
static_cast<unsigned int>(v.size());
599 for (
unsigned int j = 0; j < v_size; ++j) {
600 (*this)[j] =
static_cast<double>(v[j]);
622#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
638 x = x / sqrt(x.sumSquare());
654 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
655 *
this /= sqrt(sum_square);
729 if (
dsize != (nrows * ncols)) {
741 for (
unsigned int i = 0; i < nrows; ++i) {
742 for (
unsigned int j = 0; j < ncols; ++j) {
743 M[i][j] =
data[(i * ncols) + j];
786 if ((i + v.size()) > this->size()) {
788 "Unable to insert (1x%d) row vector in (1x%d) row "
789 "vector at position (%d)",
792 unsigned int v_size = v.size();
793 for (
unsigned int j = 0; j < v_size; ++j) {
794 (*this)[i + j] = v[j];
804 std::vector<double> v(this->
size());
806 unsigned int this_size = this->
size();
807 for (
unsigned int i = 0; i < this_size; ++i) {
905 unsigned int nrA = A.
getCols();
906 unsigned int nrB = B.
getCols();
908 if ((nrA == 0) && (nrB == 0)) {
926 for (
unsigned int i = 0; i < nrA; ++i) {
930 for (
unsigned int i = 0; i < nrB; ++i) {
940 if ((v.data ==
nullptr) || (v.size() == 0)) {
946 unsigned int v_col = v.getCols();
947 for (
unsigned int i = 0; i < v_col; ++i) {
951 return mean / v.getCols();
959 if ((v.data ==
nullptr) || (v.size() == 0)) {
963 std::vector<double> vectorOfDoubles(v.data, v.data + v.colNum);
973 if ((v.data ==
nullptr) || (v.size() == 0)) {
977 double mean_value =
mean(v);
978 double sum_squared_diff = 0.0;
979 unsigned int v_size = v.size();
980 for (
unsigned int i = 0; i < v_size; ++i) {
981 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
984 double divisor =
static_cast<double>(v.size());
985 if (useBesselCorrection && (v.size() > 1)) {
986 divisor = divisor - 1;
989 return std::sqrt(sum_squared_diff / divisor);
1013 typedef std::string::size_type size_type;
1018 std::vector<std::string> values(m * n);
1019 std::ostringstream oss;
1020 std::ostringstream ossFixed;
1021 std::ios_base::fmtflags original_flags = oss.flags();
1024 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1026 size_type maxBefore = 0;
1027 size_type maxAfter = 0;
1029 for (
unsigned int j = 0; j < n; ++j) {
1032 if (oss.str().find(
"e") != std::string::npos) {
1034 ossFixed << (*this)[j];
1035 oss.str(ossFixed.str());
1038 values[j] = oss.str();
1039 size_type thislen = values[j].size();
1040 size_type p = values[j].find(
'.');
1042 if (p == std::string::npos) {
1052 size_type totalLength = length;
1056 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1057 if (maxAfter == 1) {
1067 s <<
"[" << m <<
"," << n <<
"]=\n";
1070 for (
unsigned int j = 0; j < n; ++j) {
1071 size_type p = values[j].find(
'.');
1072 s.setf(std::ios::right, std::ios::adjustfield);
1073 s.width(
static_cast<std::streamsize
>(maxBefore));
1074 s << values[j].substr(0, p).c_str();
1077 s.setf(std::ios::left, std::ios::adjustfield);
1078 if (p != std::string::npos) {
1079 s.width(
static_cast<std::streamsize
>(maxAfter));
1080 s << values[j].substr(p, maxAfter).c_str();
1083 assert(maxAfter > 1);
1084 s.width(
static_cast<std::streamsize
> (maxAfter));
1093 s.flags(original_flags);
1095 return static_cast<int>(maxBefore + maxAfter);
1107 for (
unsigned int j = 0; j <
colNum; ++j) {
1122 double sum_square = 0.0;
1124 for (
unsigned int j = 0; j <
colNum; ++j) {
1126 sum_square += x * x;
1144#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1198 unsigned int cncols = c + ncols;
1200 if (cncols > v.getCols()) {
1202 cncols, v.getCols()));
1205 if (this->
rowPtrs ==
nullptr) {
1208 for (
unsigned int i = 0; i < ncols; ++i) {
1209 (*this)[i] = v[i + c];
1248 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1250 unsigned int this_cols = this->
getCols();
1251 for (
unsigned int j = 0; j < this_cols; ++j) {
1253 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1256 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1257 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1258 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[j]))[k]) <<
"; " << std::endl;
1262 std::cout << std::endl;
1296 unsigned int this_cols = this->
getCols();
1297 for (
unsigned int j = 0; j < this_cols; ++j) {
1299 if (!(j == (this->
getCols() - 1))) {
1336 os <<
"([ " << std::endl;
1338 unsigned int this_cols = this->
getCols();
1339 for (
unsigned int j = 0; j < this_cols; ++j) {
1340 os << (*this)[j] <<
", ";
1342 os <<
"]," << std::endl;
1343 os <<
"])" << std::endl;
1385 unsigned int this_cols = this->
getCols();
1386 for (
unsigned int j = 0; j < this_cols; ++j) {
1387 os << (*this)[j] <<
", ";
1389 os <<
"]" << std::endl;
1405 if ((v.getRows() !=
rowNum) || (v.getCols() !=
colNum)) {
1411#if defined(VISP_HAVE_SIMDLIB)
1414 for (
unsigned int i = 0; i <
dsize; ++i) {
unsigned int getCols() const
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
static vpArray2D< Type > view(const vpArray2D< Type > &A)
Creates a view of the Matrix A. A view shares the same underlying memory as the original array....
unsigned int size() const
unsigned int getRows() const
Implementation of column vector and the associated operations.
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)
static vpRowVector view(double *raw_data, unsigned int ncols)
Create a row vector view of a raw data array. The view can modify the contents of the raw data array,...
double frobeniusNorm() const
int print(std::ostream &s, unsigned int length, char const *intro=nullptr) 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.
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)
VP_DEPRECATED void init()
std::ostream & matlabPrint(std::ostream &os) const
vpRowVector hadamard(const vpRowVector &v) const