Skip to content

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 ​

cpp
typedef Eigen::Map<Eigen::Matrix<double, -1, 1>> EigenVecn

Mutable Eigen view type returned by e().

ConstEigenVecn ​

cpp
typedef Eigen::Map<const Eigen::Matrix<double, -1, 1>> ConstEigenVecn

Read-only Eigen view type returned by e() const.

Constructors & destructor ​

VecDyn ​

cpp
VecDyn() = default
cpp
VecDyn(size_t size)

Allocates size uninitialized elements.

Parameters

ParameterDescription
size (in)number of elements
cpp
VecDyn(const VecDyn &vec)

Deep copy.

Parameters

ParameterDescription
vec (in)vector to copy

Public member functions ​

operator() ​

cpp
double operator()(size_t i, size_t j) const

Parameters

ParameterDescription
i (in)element index
j (in)ignored (2D access for a column vector)

Returns element i.

cpp
double &operator()(size_t i, size_t j)

Parameters

ParameterDescription
i (in)element index
j (in)ignored (2D access for a column vector)

Returns reference to element i.

size ​

cpp
size_t size() const

Returns number of elements.

rows ​

cpp
size_t rows() const

Returns number of rows, equal to size().

cols ​

cpp
size_t cols() const

Returns 1.

sum ​

cpp
double sum() const

Returns sum of all elements.

resize ​

cpp
void resize(size_t size)

Reallocates to size elements. The previous contents are discarded and the new elements are uninitialized.

Parameters

ParameterDescription
size (in)new number of elements

squaredNorm ​

cpp
double squaredNorm() const

Returns sum of the squared elements.

norm ​

cpp
double norm() const

Returns Euclidean norm.

e ​

cpp
EigenVecn e()

Returns Eigen map aliasing this vector's memory (writes go to this vector).

cpp
const ConstEigenVecn e() const

Returns read-only Eigen map aliasing this vector's memory.

operator/= ​

cpp
void operator/=(double val)

Divides every element by val.

Parameters

ParameterDescription
val (in)divisor

operator*= ​

cpp
void operator*=(double val)

Multiplies every element by val.

Parameters

ParameterDescription
val (in)scale factor

operator= ​

cpp
VecDyn &operator=(const VecDyn &rhs)

Deep copy; resizes this vector if the sizes differ.

Parameters

ParameterDescription
rhs (in)vector to copy

Returns *this

cpp
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

ParameterDescription
rhs (in)vector to copy

Returns *this

cpp
VecDyn &operator=(const Eigen::Matrix<double, -1, 1> &rhs)

Copies an Eigen dynamic column vector, resizing this vector if needed.

Parameters

ParameterDescription
rhs (in)vector to copy

Returns *this

cpp
template <size_t size>
VecDyn &operator=(const Vec<size> &rhs)

Copies a fixed-size Vec, resizing this vector if needed.

Parameters

ParameterDescription
rhs (in)vector to copy

Returns *this

operator-= ​

cpp
VecDyn &operator-=(const VecDyn &rhs)

Element-wise subtraction.

Parameters

ParameterDescription
rhs (in)vector with at least size() elements (not checked)

Returns *this

operator+= ​

cpp
VecDyn &operator+=(const VecDyn &rhs)

Element-wise addition.

Parameters

ParameterDescription
rhs (in)vector with at least size() elements (not checked)

Returns *this

fillSegment ​

cpp
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

ParameterDescription
rhs (in)source vector
startingIdx (in)index of the first element to write
cpp
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

ParameterDescription
rhs (in)source vector
startingIdx (in)index of the first element to write

setZero ​

cpp
void setZero()

Sets all elements to zero.

cpp
void setZero(size_t cols)

Resizes to cols elements (discarding the contents) and sets them to zero.

Parameters

ParameterDescription
cols (in)new number of elements

setConstant ​

cpp
void setConstant(double c)

Sets all elements to c.

Parameters

ParameterDescription
c (in)value

Public attributes ​

n ​

cpp
size_t n

Number of elements. Use resize() instead of writing it directly.

Inherited members ​

From raisim::DynamicArray: data, operator[], ptr, v

RaiSim — physics for robotics and AI.