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);
168 template <
typename U>
178 template <
class Derived>
188 template <std::
size_t ROWS>
207 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 210 "Indexes (%lu,%lu) out of range. Vector is %lux%lu",
211 static_cast<unsigned long>(
row),
212 static_cast<unsigned long>(col),
214 static_cast<unsigned long>(1)));
223 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 226 "Indexes (%lu,%lu) out of range. Vector is %lux%lu",
227 static_cast<unsigned long>(
row),
228 static_cast<unsigned long>(col),
230 static_cast<unsigned long>(1)));
241 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 244 "Index %u out of range!", static_cast<unsigned>(ith));
252 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG_MATRICES) 255 "Index %u out of range!", static_cast<unsigned>(ith));
262 typename EIGEN_VECTOR =
eigen_t,
279 template <
typename T2>
300 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)
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
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)
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.
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
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.
GLdouble GLdouble GLdouble r
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
GLenum GLenum GLvoid * row
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...
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLubyte GLubyte GLubyte a
const T & operator[](size_t ith) const
static constexpr int ColsAtCompileTime
iteratorImpl< T, T *, T &> iterator