Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRowVector.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Operation on row vectors.
32 */
33
34#ifndef VP_ROW_VECTOR_H
35#define VP_ROW_VECTOR_H
36
37#include <vector>
38
39#include <visp3/core/vpConfig.h>
40#include <visp3/core/vpArray2D.h>
41#include <visp3/core/vpColVector.h>
42#include <visp3/core/vpMath.h>
43#include <visp3/core/vpMatrix.h>
44
46
47class vpMatrix;
48class vpColVector;
49
55
123class VISP_EXPORT vpRowVector : public vpArray2D<double>
124{
125public:
127 vpRowVector() : vpArray2D<double>() { }
130 VP_EXPLICIT vpRowVector(unsigned int n) : vpArray2D<double>(1, n) { }
132 vpRowVector(unsigned int n, double val) : vpArray2D<double>(1, n, val) { }
135 vpRowVector(const vpRowVector &v) : vpArray2D<double>(v) { }
136 vpRowVector(const vpRowVector &v, unsigned int c, unsigned int ncols);
137 VP_EXPLICIT vpRowVector(const vpMatrix &M);
138 vpRowVector(const vpMatrix &M, unsigned int i);
139 VP_EXPLICIT vpRowVector(const std::vector<double> &v);
140 VP_EXPLICIT vpRowVector(const std::vector<float> &v);
141#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
143 VP_EXPLICIT vpRowVector(const std::initializer_list<double> &list) : vpArray2D<double>(list) { }
144#endif
145
146 static vpRowVector view(double *raw_data, unsigned int ncols);
147
152 void clear()
153 {
154 if (!isMemoryOwner) {
155 throw vpException(vpException::fatalError, "Cannot clear a vector view");
156 }
157 if (data != nullptr) {
158 free(data);
159 data = nullptr;
160 }
161
162 if (rowPtrs != nullptr) {
163 free(rowPtrs);
164 rowPtrs = nullptr;
165 }
166 rowNum = 0;
167 colNum = 0;
168 dsize = 0;
169 }
170
171 std::ostream &cppPrint(std::ostream &os, const std::string &matrixName = "A", bool octet = false) const;
172 std::ostream &csvPrint(std::ostream &os) const;
173
178 inline void deg2rad()
179 {
180 double d2r = M_PI / 180.0;
181
182 (*this) *= d2r;
183 }
184
202 vpRowVector extract(unsigned int c, unsigned int rowsize) const
203 {
204 if ((c >= colNum) || ((c + rowsize) > colNum)) {
206 "Cannot extract a (1x%d) row vector from a (1x%d) "
207 "row vector starting at index %d",
208 rowsize, colNum, c));
209 }
210
211 return vpRowVector(*this, c, rowsize);
212 }
213
214 double frobeniusNorm() const;
215
223 vpRowVector hadamard(const vpRowVector &v) const;
224
225 void init(const vpRowVector &v, unsigned int c, unsigned int ncols);
226 void insert(unsigned int i, const vpRowVector &v);
227
228 std::ostream &maplePrint(std::ostream &os) const;
229 std::ostream &matlabPrint(std::ostream &os) const;
230
231 vpRowVector &normalize();
232 vpRowVector &normalize(vpRowVector &x) const;
233
235 inline double &operator[](unsigned int n) { return *(data + n); }
237 inline const double &operator[](unsigned int n) const { return *(data + n); }
238
241 vpRowVector &operator=(const vpMatrix &M);
242 vpRowVector &operator=(const std::vector<double> &v);
243 vpRowVector &operator=(const std::vector<float> &v);
244 vpRowVector &operator=(double x);
245#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
247 vpRowVector &operator=(const std::initializer_list<double> &list);
248#endif
250 bool operator==(const vpRowVector &v) const;
251 bool operator!=(const vpRowVector &v) const;
252
253 double operator*(const vpColVector &x) const;
254 vpRowVector operator*(const vpMatrix &M) const;
255 vpRowVector operator*(double x) const;
256 vpRowVector &operator*=(double x);
257
258 vpRowVector operator/(double x) const;
259 vpRowVector &operator/=(double x);
260
261 vpRowVector operator+(const vpRowVector &v) const;
262 vpRowVector &operator+=(vpRowVector v);
263
264 vpRowVector operator-(const vpRowVector &v) const;
265 vpRowVector &operator-=(vpRowVector v);
266 vpRowVector operator-() const;
267
269 vpRowVector &operator<<(double val);
270 vpRowVector &operator,(double val);
271
272 int print(std::ostream &s, unsigned int length, char const *intro = nullptr) const;
277 inline void rad2deg()
278 {
279 double r2d = 180.0 / M_PI;
280
281 (*this) *= r2d;
282 }
283
284 void reshape(vpMatrix &M, const unsigned int &nrows, const unsigned int &ncols);
285 vpMatrix reshape(unsigned int nrows, unsigned int ncols);
286
292 inline void resize(unsigned int i, bool flagNullify = true) { vpArray2D<double>::resize(1, i, flagNullify); }
293
304 void resize(unsigned int nrows, unsigned int ncols, bool flagNullify)
305 {
306 if (nrows != 1) {
308 "Cannot resize a row vector to a (%dx%d) dimension "
309 "vector that has more than one row",
310 nrows, ncols));
311 }
312 vpArray2D<double>::resize(nrows, ncols, flagNullify);
313 }
314
315 void stack(double d);
316 void stack(const vpRowVector &v);
317
318 double sum() const;
319 double sumSquare() const;
320 vpColVector t() const;
321 std::vector<double> toStdVector() const;
322 vpColVector transpose() const;
323 void transpose(vpColVector &v) const;
324
325 static double mean(const vpRowVector &v);
326 static double median(const vpRowVector &v);
327 static vpRowVector stack(const vpRowVector &A, const vpRowVector &B);
328 static void stack(const vpRowVector &A, const vpRowVector &B, vpRowVector &C);
329 static double stdev(const vpRowVector &v, bool useBesselCorrection = false);
330
331#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
336
340 VP_DEPRECATED void init() { }
344 VP_DEPRECATED void stackMatrices(const vpRowVector &r) { stack(r); }
349 VP_DEPRECATED static vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B) { return stack(A, B); }
354 VP_DEPRECATED static void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C)
355 {
356 stack(A, B, C);
357 }
358
362 VP_DEPRECATED void setIdentity(const double &val = 1.0);
363 VP_DEPRECATED double euclideanNorm() const;
365#endif
366};
367
368VISP_EXPORT vpRowVector operator*(const double &x, const vpRowVector &v);
369
370END_VISP_NAMESPACE
371#endif
vpArray2D< Type > & operator=(Type x)
Set all the elements of the array to x.
Definition vpArray2D.h:615
void insert(const vpArray2D< Type > &A, unsigned int r, unsigned int c)
Definition vpArray2D.h:586
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:448
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....
Definition vpArray2D.h:324
unsigned int rowNum
Definition vpArray2D.h:1201
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition vpArray2D.h:705
unsigned int dsize
Definition vpArray2D.h:1207
vpArray2D< Type > t() const
Compute the transpose of the array.
Definition vpArray2D.h:1273
bool operator!=(const vpArray2D< Type > &A) const
Definition vpArray2D.h:1458
vpArray2D< Type > hadamard(const vpArray2D< Type > &m) const
Definition vpArray2D.h:1257
void reshape(unsigned int nrows, unsigned int ncols)
Definition vpArray2D.h:545
unsigned int colNum
Definition vpArray2D.h:1203
bool operator==(const vpArray2D< Type > &A) const
Definition vpArray2D.h:1401
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
Implementation of row vector and the associated operations.
vpRowVector(const vpRowVector &v)
vpRowVector(unsigned int n, double val)
Construct a row vector of size n. Each element is set to val.
VP_DEPRECATED double euclideanNorm() const
void resize(unsigned int i, bool flagNullify=true)
void deg2rad()
void rad2deg()
VP_DEPRECATED void setIdentity(const double &val=1.0)
vpRowVector()
Basic constructor that creates an empty 0-size row vector.
void stack(double d)
static VP_DEPRECATED void stackMatrices(const vpRowVector &A, const vpRowVector &B, vpRowVector &C)
VP_DEPRECATED void stackMatrices(const vpRowVector &r)
VP_EXPLICIT vpRowVector(const std::initializer_list< double > &list)
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify)
VP_EXPLICIT vpRowVector(unsigned int n)
const double & operator[](unsigned int n) const
Operator that allows to get the value of an element : x = v[i].
double & operator[](unsigned int n)
Operator that allows to set a value of an element : v[i] = x.
VP_DEPRECATED void init()
vpRowVector extract(unsigned int c, unsigned int rowsize) const
static VP_DEPRECATED vpRowVector stackMatrices(const vpRowVector &A, const vpRowVector &B)