19 #include <type_traits> 72 void realloc(
const size_t new_len,
bool newElementsToZero =
false)
75 if (new_len == old_len)
return;
77 if (newElementsToZero && new_len > old_len)
79 if constexpr (std::is_trivial_v<T>)
80 ::memset(&
m_data[old_len], 0,
sizeof(T) * (new_len - old_len));
82 for (
size_t k = old_len; k < new_len; k++)
m_data[k] = T();
102 template <std::
size_t ROWS>
118 typename ARRAY,
typename = std::enable_if_t<std::is_array_v<ARRAY>>>
122 ASSERTMSG_(N != 0,
"CVectorDynamic ctor: Empty array!");
124 for (
size_t i = 0; i < N; i++) m_data[i] = static_cast<T>(
data[i]);
128 template <
class Derived>
146 void setSize(
size_t row,
size_t col,
bool zeroNewElements =
false)
151 void resize(std::size_t N,
bool zeroNewElements =
false)
153 setSize(N, 1, zeroNewElements);
162 for (
Index r = 0; r <
rows(); r++) (*
this)[r] = m(r, 0);
168 template <
typename U>
178 template <
class Derived>
188 template <std::
size_t ROWS>
208 for (
int i = 0; i < LEN; i++) v[i] =
m_data[start + i];
218 for (
int i = 0; i < LEN; i++) v[i] =
m_data[start + i];
226 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 229 "Indexes (%lu,%lu) out of range. Vector is %lux%lu",
230 static_cast<unsigned long>(row),
231 static_cast<unsigned long>(col),
233 static_cast<unsigned long>(1)));
242 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 245 "Indexes (%lu,%lu) out of range. Vector is %lux%lu",
246 static_cast<unsigned long>(row),
247 static_cast<unsigned long>(col),
249 static_cast<unsigned long>(1)));
260 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 263 "Index %u out of range!", static_cast<unsigned>(ith));
271 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 274 "Index %u out of range!", static_cast<unsigned>(ith));
281 typename EIGEN_VECTOR =
eigen_t,
298 template <
typename T2>
319 template <
typename T>
typename vec_t::iterator iterator
A compile-time fixed-size numeric matrix container.
CVectorDynamic & operator=(const CMatrixDynamic< U > &m)
Assignment operator from another matrix (possibly of a different type)
iteratorImpl< T, const T *, const T &> const_iterator
Template for column vectors of dynamic size, compatible with Eigen.
#define THROW_EXCEPTION(msg)
std::string std::string format(std::string_view fmt, ARGS &&... args)
size_t size(const MATRIXLIKE &m, const int dim)
CVectorDynamic< T2 > cast() const
size_type cols() const
Number of columns in the matrix (always 1)
Eigen::Matrix< T, -1, 1, 0, -1, 1 > eigen_t
CVectorDynamic & operator=(const Eigen::MatrixBase< Derived > &m)
Assignment from an Eigen matrix.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
static constexpr int is_mrpt_type
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 ith)
Subscript operator to get/set an individual element from a row or column matrix.
std::ptrdiff_t difference_type
CVectorDynamic(const ARRAY &data)
Constructor from a given size and a C array.
void push_back(const T &val)
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
const_iterator end() const
CVectorDynamic(const CMatrixFixed< T, ROWS, 1 > &v)
Ctor from a fixed-size vector.
#define ASSERT_(f)
Defines an assertion mechanism.
EIGEN_MAP asEigen() const
CVectorDynamic & operator=(const CMatrixFixed< T, ROWS, 1 > &v)
Assignment from a fixed-size vector.
This base provides a set of functions for maths stuff.
const T & operator()(size_t row, size_t col) const
Subscript operator to get individual elements.
iterator begin() noexcept
const_iterator begin() const
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
static constexpr int RowsAtCompileTime
const_iterator cbegin() const
CVectorDynamic(const Eigen::MatrixBase< Derived > &m)
Convert from Eigen matrix.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
typename vec_t::const_iterator const_iterator
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 pos...
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
size_type rows() const
Number of rows in the vector.
void swap(CVectorDynamic< T > &o)
const_iterator cend() const
const KFTYPE & const_reference
CVectorDynamic(const CVectorDynamic< U > &m)
Copy (casting from if needed) from another matrix.
KFTYPE value_type
The type of the matrix elements.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void fromVectorLike(const MAT &m)
Virtual base class for "archives": classes abstracting I/O streams.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
T & operator()(size_t row, size_t col)
Subscript operator to get/set individual elements.
Base CRTP class for all MRPT vectors and matrices.
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
void resize(std::size_t N, bool zeroNewElements=false)
static constexpr size_t small_size
const_reference back() const
CVectorDynamic(size_t N, bool initZero=true)
Initializes to a vector of "N" zeros.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
This template class provides the basic functionality for a general 2D any-size, resizable container o...
const T & operator[](size_t ith) const
static constexpr int ColsAtCompileTime
iteratorImpl< T, T *, T &> iterator
CMatrixFixed< Scalar, LEN, 1 > segmentCopy(int start=0) const
const segmentCopy(): Returns a copy of the given vector segment
static struct FontData data