Template Class CVectorDynamic

Inheritance Relationships

Base Type

Class Documentation

template<class T>
class CVectorDynamic : public mrpt::math::MatrixVectorBase<T, CVectorDynamic<T>>

Template for column vectors of dynamic size, compatible with Eigen.

Note

For a complete introduction to Matrices and vectors in MRPT, see: http://www.mrpt.org/Matrices_vectors_arrays_and_Linear_Algebra_MRPT_and_Eigen_classes

Matrix type definitions

using value_type = T

The type of the matrix elements

using Scalar = T
using Index = matrix_index_t
using reference = T&
using const_reference = const T&
using size_type = matrix_dim_t
using difference_type = std::ptrdiff_t
using eigen_t = Eigen::Matrix<T, -1, 1, 0, -1, 1>
static constexpr int RowsAtCompileTime = -1
static constexpr int ColsAtCompileTime = 1
static constexpr int is_mrpt_type = 1

Iterators interface

using iterator = typename vec_t::iterator
using const_iterator = typename vec_t::const_iterator
inline iterator begin()
inline iterator end()
inline const_iterator begin() const
inline const_iterator end() const
inline const_iterator cbegin() const
inline const_iterator cend() const

Public Functions

inline void realloc(size_type new_len, bool newElementsToZero = false)

Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if possible.

inline void swap(CVectorDynamic<T> &o)
CVectorDynamic() = default
inline CVectorDynamic(size_type N, bool initZero = true)

Initializes to a vector of “N” zeros

template<typename U>
inline explicit CVectorDynamic(const CVectorDynamic<U> &m)

Copy (casting from if needed) from another matrix

template<size_type ROWS>
inline explicit CVectorDynamic(const CMatrixFixed<T, ROWS, 1> &v)

Ctor from a fixed-size vector

template<typename ARRAY, typename = std::enable_if_t<std::is_array_v<ARRAY>>>
inline CVectorDynamic(const ARRAY &data)

Constructor from a given size and a C array. The array length must match cols x row.

const double numbers[] = {
  1,2,3,
  4,5,6 };
CMatrixDouble   M(3,2, numbers);

template<class Derived>
inline explicit CVectorDynamic(const Eigen::MatrixBase<Derived> &m)

Convert from Eigen matrix

inline size_type rows() const

Number of rows in the vector

inline size_type cols() const

Number of columns in the matrix (always 1)

inline size_type size() const

Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))

inline bool empty() const
inline void setSize(size_type row, size_type col, bool zeroNewElements = false)

Changes the size of matrix, maintaining the previous contents.

inline void resize(size_type N, bool zeroNewElements = false)
template<class MAT>
inline void fromVectorLike(const MAT &m)
template<typename U>
inline CVectorDynamic &operator=(const CMatrixDynamic<U> &m)

Assignment operator from another matrix (possibly of a different type)

template<class Derived>
inline CVectorDynamic &operator=(const Eigen::MatrixBase<Derived> &m)

Assignment from an Eigen matrix

template<matrix_dim_t ROWS>
inline CVectorDynamic &operator=(const CMatrixFixed<T, ROWS, 1> &v)

Assignment from a fixed-size vector

inline void push_back(const T &val)
template<int LEN>
inline CMatrixFixed<Scalar, LEN, 1> segmentCopy(int start = 0) const

const segmentCopy(): Returns a copy of the given vector segment

inline CVectorDynamic<Scalar> segmentCopy(int start, int LEN) const

const segmentCopy(): Returns a copy of the given vector segment (non templated version, dynamic length)

inline T &operator()(Index row, Index col)

Subscript operator to get/set individual elements

inline const T &operator()(Index row, Index col) const

Subscript operator to get individual elements

inline T &operator[](Index ith)

Subscript operator to get/set an individual element from a row or column matrix.

Throws:

std::exception – If the object is not a column or row matrix.

inline const T &operator[](Index ith) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<typename EIGEN_VECTOR = eigen_t, typename EIGEN_MAP = Eigen::Map<EIGEN_VECTOR, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
inline EIGEN_MAP asEigen()

Get as an Eigen-compatible Eigen::Map object

template<typename EIGEN_VECTOR = Eigen::Matrix<T, -1, 1, 0, -1, 1>, typename EIGEN_MAP = Eigen::Map<const EIGEN_VECTOR, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>>
inline EIGEN_MAP asEigen() const
template<typename T2>
CVectorDynamic<T2> cast() const

Protected Types

using vec_t = mrpt::containers::vector_with_small_size_optimization<T, small_size, MRPT_MAX_STATIC_ALIGN_BYTES>

Protected Attributes

vec_t m_data

Protected Static Attributes

static constexpr size_t small_size = 16