template class mrpt::math::CVectorDynamic
Template for column vectors of dynamic size, compatible with Eigen.
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
See also:
CVectorDynamic, CMatrixFixed, CVectorFixed
#include <mrpt/math/CVectorDynamic.h> template <class T> class CVectorDynamic: public mrpt::math::MatrixVectorBase { public: // typedefs typedef T value_type; typedef T Scalar; typedef int Index; typedef T& reference; typedef const T& const_reference; typedef int size_type; typedef std::ptrdiff_t difference_type; typedef Eigen::Matrix<T, -1, 1, 0, -1, 1> eigen_t; typedef typename vec_t::iterator iterator; typedef typename vec_t::const_iterator const_iterator; // fields static constexpr int RowsAtCompileTime = -1; static constexpr int ColsAtCompileTime = 1; static constexpr int is_mrpt_type = 1; // construction CVectorDynamic(); CVectorDynamic(size_t N, bool initZero = true); template <typename U> CVectorDynamic(const CVectorDynamic<U>& m); template <std::size_t ROWS> CVectorDynamic(const CMatrixFixed<T, ROWS, 1>& v); template <typename ARRAY, typename = std::enable_if_t<std::is_array_v<ARRAY>>> CVectorDynamic(const ARRAY& data); template <class Derived> CVectorDynamic(const Eigen::MatrixBase<Derived>& m); // methods iterator begin(); iterator end(); const_iterator begin() const; const_iterator end() const; const_iterator cbegin() const; const_iterator cend() const; void realloc(const size_t new_len, bool newElementsToZero = false); void swap(CVectorDynamic<T>& o); size_type rows() const; size_type cols() const; size_type size() const; bool empty() const; void setSize(size_t row, size_t col, bool zeroNewElements = false); void resize( std::size_t N, bool zeroNewElements = false ); template <class MAT> void fromVectorLike(const MAT& m); template <typename U> CVectorDynamic& operator = (const CMatrixDynamic<U>& m); template <class Derived> CVectorDynamic& operator = (const Eigen::MatrixBase<Derived>& m); template <std::size_t ROWS> CVectorDynamic& operator = (const CMatrixFixed<T, ROWS, 1>& v); void push_back(const T& val); template <int LEN> CMatrixFixed<Scalar, LEN, 1> segmentCopy(int start = 0) const; CVectorDynamic<Scalar> segmentCopy(int start, int LEN) const; T& operator () (size_t row, size_t col); const T& operator () (size_t row, size_t col) const; T& operator [] (size_t ith); const T& operator [] (size_t ith) const; template < typename EIGEN_VECTOR = eigen_t, typename EIGEN_MAP = Eigen::Map<EIGEN_VECTOR, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>> > EIGEN_MAP asEigen(); 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>> > EIGEN_MAP asEigen() const; template <typename T2> CVectorDynamic<T2> cast() const; };
Inherited Members
public: // methods void setConstant(const Scalar value); void setConstant(size_t nrows, size_t ncols, const Scalar value); void setConstant(size_t nrows, const Scalar value); void assign(const std::size_t N, const Scalar value); void setZero(); void setZero(size_t nrows, size_t ncols); void setZero(size_t nrows); static Derived Constant(const Scalar value); static Derived Constant(size_t nrows, size_t ncols, const Scalar value); static Derived Zero(); static Derived Zero(size_t nrows, size_t ncols); auto block(int start_row, int start_col, int BLOCK_ROWS, int BLOCK_COLS); auto block(int start_row, int start_col, int BLOCK_ROWS, int BLOCK_COLS) const; auto transpose(); auto transpose() const; auto array(); auto array() const; auto operator - () const; template <typename S2, class D2> auto operator + (const MatrixVectorBase<S2, D2>& m2) const; template <typename S2, class D2> void operator += (const MatrixVectorBase<S2, D2>& m2); template <typename S2, class D2> auto operator - (const MatrixVectorBase<S2, D2>& m2) const; template <typename S2, class D2> void operator -= (const MatrixVectorBase<S2, D2>& m2); template <typename S2, class D2> auto operator * (const MatrixVectorBase<S2, D2>& m2) const; auto operator * (const Scalar s) const; template <int N> CMatrixFixed<Scalar, N, 1> tail() const; template <int N> CMatrixFixed<Scalar, N, 1> head() const; Scalar& coeffRef(int r, int c); const Scalar& coeff(int r, int c) const; Scalar minCoeff(std::size_t& outIndexOfMin) const; Scalar minCoeff(std::size_t& rowIdx, std::size_t& colIdx) const; Scalar maxCoeff(std::size_t& outIndexOfMax) const; Scalar maxCoeff(std::size_t& rowIdx, std::size_t& colIdx) const; void operator += (Scalar s); void operator -= (Scalar s); void operator *= (Scalar s); CMatrixDynamic<Scalar> operator * (const CMatrixDynamic<Scalar>& v); Derived operator + (const Derived& m2) const; void operator += (const Derived& m2); Derived operator - (const Derived& m2) const; void operator -= (const Derived& m2); Derived operator * (const Derived& m2) const; Scalar dot(const MatrixVectorBase<Scalar, Derived>& v) const; template <typename OTHERMATVEC> bool operator == (const OTHERMATVEC& o) const; template <typename OTHERMATVEC> bool operator != (const OTHERMATVEC& o) const; Derived& mvbDerived(); const Derived& mvbDerived() const;
Typedefs
typedef T value_type
The type of the matrix elements.
Construction
CVectorDynamic(size_t N, bool initZero = true)
Initializes to a vector of “N” zeros.
template <typename U> CVectorDynamic(const CVectorDynamic<U>& m)
Copy (casting from if needed) from another matrix.
template <std::size_t ROWS> 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>>> 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> CVectorDynamic(const Eigen::MatrixBase<Derived>& m)
Convert from Eigen matrix.
Methods
void realloc(const size_t new_len, bool newElementsToZero = false)
Internal use only: It reallocs the memory for the 2D matrix, maintaining the previous contents if posible.
size_type rows() const
Number of rows in the vector.
size_type cols() const
Number of columns in the matrix (always 1)
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
void setSize(size_t row, size_t col, bool zeroNewElements = false)
Changes the size of matrix, maintaining the previous contents.
template <typename U> CVectorDynamic& operator = (const CMatrixDynamic<U>& m)
Assignment operator from another matrix (possibly of a different type)
template <class Derived> CVectorDynamic& operator = (const Eigen::MatrixBase<Derived>& m)
Assignment from an Eigen matrix.
template <std::size_t ROWS> CVectorDynamic& operator = (const CMatrixFixed<T, ROWS, 1>& v)
Assignment from a fixed-size vector.
template <int LEN> CMatrixFixed<Scalar, LEN, 1> segmentCopy(int start = 0) const
const segmentCopy() : Returns a copy of the given vector segment
CVectorDynamic<Scalar> segmentCopy(int start, int LEN) const
const segmentCopy() : Returns a copy of the given vector segment (non templated version, dynamic length)
T& operator () (size_t row, size_t col)
Subscript operator to get/set individual elements.
const T& operator () (size_t row, size_t col) const
Subscript operator to get individual elements.
T& operator [] (size_t ith)
Subscript operator to get/set an individual element from a row or column matrix.
Parameters:
std::exception |
If the object is not a column or row matrix. |
const T& operator [] (size_t 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>> > 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>> > EIGEN_MAP asEigen() const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.