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) {
320 for (
unsigned int i = 0; i <
colNum; ++i) {
352 for (
unsigned int i = 0; i <
colNum; ++i) {
379 for (
unsigned int i = 0; i <
colNum; ++i) {
402 for (
unsigned int i = 0; i <
colNum; ++i) {
423 for (
unsigned int i = 0; i <
colNum; ++i) {
424 v[i] = (*this)[i] - m[i];
442 for (
unsigned int i = 0; i <
colNum; ++i) {
443 r[i] = (*this)[i] + v[i];
460 for (
unsigned int i = 0; i <
colNum; ++i) {
478 for (
unsigned int i = 0; i <
colNum; ++i) {
556 unsigned int m_cols = M.
getCols();
557 for (
unsigned int j = 0; j < m_cols; ++j) {
558 (*this)[j] = M[i][j];
574 unsigned int m_cols = M.
getCols();
575 for (
unsigned int j = 0; j < m_cols; ++j) {
576 (*this)[j] = M[0][j];
585 unsigned int v_size =
static_cast<unsigned int>(v.size());
586 for (
unsigned int j = 0; j < v_size; ++j) {
596 unsigned int v_size =
static_cast<unsigned int>(v.size());
597 for (
unsigned int j = 0; j < v_size; ++j) {
598 (*this)[j] =
static_cast<double>(v[j]);
620 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
664 if (std::fabs(sum_square) > std::numeric_limits<double>::epsilon()) {
665 *
this /= sqrt(sum_square);
739 if (
dsize != (nrows * ncols)) {
751 for (
unsigned int i = 0; i < nrows; ++i) {
752 for (
unsigned int j = 0; j < ncols; ++j) {
753 M[i][j] =
data[(i * ncols) + j];
796 if ((i + v.
size()) > this->size()) {
798 "Unable to insert (1x%d) row vector in (1x%d) row "
799 "vector at position (%d)",
802 unsigned int v_size = v.
size();
803 for (
unsigned int j = 0; j < v_size; ++j) {
804 (*this)[i + j] = v[j];
814 std::vector<double> v(this->
size());
816 unsigned int this_size = this->
size();
817 for (
unsigned int i = 0; i < this_size; ++i) {
915 unsigned int nrA = A.
getCols();
916 unsigned int nrB = B.
getCols();
918 if ((nrA == 0) && (nrB == 0)) {
936 for (
unsigned int i = 0; i < nrA; ++i) {
940 for (
unsigned int i = 0; i < nrB; ++i) {
950 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
956 unsigned int v_col = v.
getCols();
957 for (
unsigned int i = 0; i < v_col; ++i) {
969 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
983 if ((v.
data ==
nullptr) || (v.
size() == 0)) {
987 double mean_value =
mean(v);
988 double sum_squared_diff = 0.0;
989 unsigned int v_size = v.
size();
990 for (
unsigned int i = 0; i < v_size; ++i) {
991 sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value);
994 double divisor =
static_cast<double>(v.
size());
995 if (useBesselCorrection && (v.
size() > 1)) {
996 divisor = divisor - 1;
999 return std::sqrt(sum_squared_diff / divisor);
1023 typedef std::string::size_type size_type;
1028 std::vector<std::string> values(m * n);
1029 std::ostringstream oss;
1030 std::ostringstream ossFixed;
1031 std::ios_base::fmtflags original_flags = oss.flags();
1034 ossFixed.setf(std::ios::fixed, std::ios::floatfield);
1036 size_type maxBefore = 0;
1037 size_type maxAfter = 0;
1039 for (
unsigned int j = 0; j < n; ++j) {
1042 if (oss.str().find(
"e") != std::string::npos) {
1044 ossFixed << (*this)[j];
1045 oss.str(ossFixed.str());
1048 values[j] = oss.str();
1049 size_type thislen = values[j].size();
1050 size_type p = values[j].find(
'.');
1052 if (p == std::string::npos) {
1062 size_type totalLength = length;
1066 maxAfter = std::min<size_type>(maxAfter, totalLength - maxBefore);
1067 if (maxAfter == 1) {
1077 s <<
"[" << m <<
"," << n <<
"]=\n";
1080 for (
unsigned int j = 0; j < n; ++j) {
1081 size_type p = values[j].find(
'.');
1082 s.setf(std::ios::right, std::ios::adjustfield);
1083 s.width(
static_cast<std::streamsize
>(maxBefore));
1084 s << values[j].substr(0, p).c_str();
1087 s.setf(std::ios::left, std::ios::adjustfield);
1088 if (p != std::string::npos) {
1089 s.width(
static_cast<std::streamsize
>(maxAfter));
1090 s << values[j].substr(p, maxAfter).c_str();
1093 assert(maxAfter > 1);
1094 s.width(
static_cast<std::streamsize
> (maxAfter));
1103 s.flags(original_flags);
1105 return static_cast<int>(maxBefore + maxAfter);
1117 for (
unsigned int j = 0; j <
colNum; ++j) {
1132 double sum_square = 0.0;
1134 for (
unsigned int j = 0; j <
colNum; ++j) {
1136 sum_square += x * x;
1154 #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1164 double vpRowVector::euclideanNorm()
const {
return frobeniusNorm(); }
1208 unsigned int cncols = c + ncols;
1215 if (this->
rowPtrs ==
nullptr) {
1218 for (
unsigned int i = 0; i < ncols; ++i) {
1219 (*this)[i] = v[i + c];
1258 os <<
"vpRowVector " << matrixName <<
" (" << this->
getCols() <<
"); " << std::endl;
1260 unsigned int this_cols = this->
getCols();
1261 for (
unsigned int j = 0; j < this_cols; ++j) {
1263 os << matrixName <<
"[" << j <<
"] = " << (*this)[j] <<
"; " << std::endl;
1266 for (
unsigned int k = 0; k <
sizeof(double); ++k) {
1267 os <<
"((unsigned char*)&(" << matrixName <<
"[" << j <<
"]) )[" << k <<
"] = 0x" << std::hex
1268 <<
static_cast<unsigned int>(((
unsigned char *)&((*
this)[j]))[k]) <<
"; " << std::endl;
1272 std::cout << std::endl;
1306 unsigned int this_cols = this->
getCols();
1307 for (
unsigned int j = 0; j < this_cols; ++j) {
1309 if (!(j == (this->
getCols() - 1))) {
1346 os <<
"([ " << std::endl;
1348 unsigned int this_cols = this->
getCols();
1349 for (
unsigned int j = 0; j < this_cols; ++j) {
1350 os << (*this)[j] <<
", ";
1352 os <<
"]," << std::endl;
1353 os <<
"])" << std::endl;
1395 unsigned int this_cols = this->
getCols();
1396 for (
unsigned int j = 0; j < this_cols; ++j) {
1397 os << (*this)[j] <<
", ";
1399 os <<
"]" << std::endl;
1421 #if defined(VISP_HAVE_SIMDLIB)
1424 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