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>
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) {
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];
444 for (
unsigned int i = 0; i <
colNum; ++i) {
445 r[i] = (*this)[i] + v[i];
462 for (
unsigned int i = 0; i <
colNum; ++i) {
480 for (
unsigned int i = 0; i <
colNum; ++i) {
558 unsigned int m_cols = M.
getCols();
559 for (
unsigned int j = 0; j < m_cols; ++j) {
560 (*this)[j] = M[i][j];
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)
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) {
959 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
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)
1154 double vpRowVector::euclideanNorm()
const {
return frobeniusNorm(); }
1198 unsigned int cncols = c + ncols;
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;
1411 #if defined(VISP_HAVE_SIMDLIB)
1414 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.
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 dsize
Current array size (rowNum * colNum)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
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
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
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)
static vpRowVector view(double *data, unsigned int cols)
Create a row vector view of a raw data array. The view can modify the contents of the raw data array,...
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