raisim::VecDyn
class · #include <raisim/math.hpp>
Inherits: raisim::DynamicArray
Dynamically sized column vector of doubles (heap storage, see DynamicArray).
n is the number of elements. resize() reallocates and does not preserve the contents; newly allocated elements are uninitialized. e() returns an Eigen map that aliases the same memory.
Public types
EigenVecn
typedef Eigen::Map<Eigen::Matrix<double, -1, 1>> EigenVecnMutable Eigen view type returned by e().
ConstEigenVecn
typedef Eigen::Map<const Eigen::Matrix<double, -1, 1>> ConstEigenVecnRead-only Eigen view type returned by e() const.
Constructors & destructor
VecDyn
VecDyn() = defaultVecDyn(size_t size)Allocates size uninitialized elements.
Parameters
| Parameter | Description |
|---|---|
size (in) | number of elements |
VecDyn(const VecDyn &vec)Deep copy.
Parameters
| Parameter | Description |
|---|---|
vec (in) | vector to copy |
Public member functions
operator()
double operator()(size_t i, size_t j) constParameters
| Parameter | Description |
|---|---|
i (in) | element index |
j (in) | ignored (2D access for a column vector) |
Returns element i.
double &operator()(size_t i, size_t j)Parameters
| Parameter | Description |
|---|---|
i (in) | element index |
j (in) | ignored (2D access for a column vector) |
Returns reference to element i.
size
size_t size() constReturns number of elements.
rows
size_t rows() constReturns number of rows, equal to size().
cols
size_t cols() constReturns 1.
sum
double sum() constReturns sum of all elements.
resize
void resize(size_t size)Reallocates to size elements. The previous contents are discarded and the new elements are uninitialized.
Parameters
| Parameter | Description |
|---|---|
size (in) | new number of elements |
squaredNorm
double squaredNorm() constReturns sum of the squared elements.
norm
double norm() constReturns Euclidean norm.
e
EigenVecn e()Returns Eigen map aliasing this vector's memory (writes go to this vector).
const ConstEigenVecn e() constReturns read-only Eigen map aliasing this vector's memory.
operator/=
void operator/=(double val)Divides every element by val.
Parameters
| Parameter | Description |
|---|---|
val (in) | divisor |
operator*=
void operator*=(double val)Multiplies every element by val.
Parameters
| Parameter | Description |
|---|---|
val (in) | scale factor |
operator=
VecDyn &operator=(const VecDyn &rhs)Deep copy; resizes this vector if the sizes differ.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector to copy |
Returns *this
template <int rows, int cols>
VecDyn &operator=(const Eigen::Matrix<double, rows, cols> &rhs)Copies an Eigen column vector, resizing this vector if needed. A dynamic column count is accepted at compile time, but a source with more or fewer than one column is fatal.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector to copy |
Returns *this
VecDyn &operator=(const Eigen::Matrix<double, -1, 1> &rhs)Copies an Eigen dynamic column vector, resizing this vector if needed.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector to copy |
Returns *this
template <size_t size>
VecDyn &operator=(const Vec<size> &rhs)Copies a fixed-size Vec, resizing this vector if needed.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector to copy |
Returns *this
operator-=
VecDyn &operator-=(const VecDyn &rhs)Element-wise subtraction.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector with at least size() elements (not checked) |
Returns *this
operator+=
VecDyn &operator+=(const VecDyn &rhs)Element-wise addition.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | vector with at least size() elements (not checked) |
Returns *this
fillSegment
void fillSegment(const VecDyn &rhs, size_t startingIdx)Copies rhs into the elements [startingIdx, startingIdx + rhs.size()). It is fatal if the segment does not fit. The source may overlap this vector.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | source vector |
startingIdx (in) | index of the first element to write |
template <size_t size>
void fillSegment(const Vec<size> &rhs, size_t startingIdx)Copies rhs into the elements [startingIdx, startingIdx + size). It is fatal if the segment does not fit.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | source vector |
startingIdx (in) | index of the first element to write |
setZero
void setZero()Sets all elements to zero.
void setZero(size_t cols)Resizes to cols elements (discarding the contents) and sets them to zero.
Parameters
| Parameter | Description |
|---|---|
cols (in) | new number of elements |
setConstant
void setConstant(double c)Sets all elements to c.
Parameters
| Parameter | Description |
|---|---|
c (in) | value |
Public attributes
n
size_t nNumber of elements. Use resize() instead of writing it directly.
Inherited members
From raisim::DynamicArray: data, operator[], ptr, v