32 template <
typename T, std::
size_t ROWS, std::
size_t COLS>
37 using vec_t = std::array<T, ROWS * COLS>;
56 (ROWS != 1 && COLS == 1) ? 0 : 1 ;
95 template <
class Derived>
101 template <
typename _Lhs,
typename _Rhs,
int Option>
107 template <
typename Op,
typename Lhs,
typename Rhs>
114 template <
typename VectorType,
int Size>
142 template <
class Derived>
151 template <
typename VectorType,
int Size>
161 template <
typename U>
170 template <
typename VECTOR>
176 for (
size_t r = 0, i = 0;
r < ROWS;
r++)
177 for (
size_t c = 0;
c < COLS;
c++)
m_data[
r * COLS +
c] = vals[i++];
185 for (
size_t r = 0, i = 0;
r < ROWS;
r++)
191 size_t row,
size_t col, [[maybe_unused]]
bool zeroNewElements =
false)
216 const matrix_size_t& siz, [[maybe_unused]]
bool zeroNewElements =
false)
248 typename EIGEN_MATRIX =
eigen_t,
254 std::is_same_v<EIGEN_MATRIX, eigen_t>,
255 "Please, do not override the default template arguments of this " 257 return EIGEN_MAP(&
m_data[0], ROWS, COLS);
262 typename EIGEN_MATRIX =
eigen_t,
264 const EIGEN_MATRIX, MRPT_MAX_STATIC_ALIGN_BYTES,
269 std::is_same_v<EIGEN_MATRIX, eigen_t>,
270 "Please, do not override the default template arguments of this " 272 return EIGEN_MAP(&
m_data[0], ROWS, COLS);
295 ASSERTDEB_(static_cast<std::size_t>(i) < ROWS * COLS);
300 ASSERTDEB_(static_cast<std::size_t>(i) < ROWS * COLS);
307 ASSERT_(ROWS == 1 || COLS == 1);
308 ASSERTDEB_(static_cast<std::size_t>(i) < ROWS * COLS);
313 ASSERT_(ROWS == 1 || COLS == 1);
314 ASSERTDEB_(static_cast<std::size_t>(i) < ROWS * COLS);
332 if constexpr (ROWS == COLS)
336 (*
this)(
r,
c) +=
A(
c,
r);
340 throw std::runtime_error(
"sum_At(): matrix must be square.");
395 template <
typename T, std::
size_t N, std::
size_t M>
398 constexpr
static auto get()
T & operator()(int row, int col)
Access (row,col), without out-of-bounds check (except in Debug builds)
CMatrixFixed()
Default constructor, initializes all elements to zero.
A compile-time fixed-size numeric matrix container.
static constexpr int StorageOrder
TConstructorFlags_Matrices
For usage in one of the constructors of CMatrixFixed or CMatrixDynamic (and derived classes)...
EIGEN_MAP asEigen() const
constexpr matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
#define THROW_EXCEPTION(msg)
const_iterator cbegin() const
const CMatrixFixed & derived() const
static constexpr int SizeAtCompileTime
void conservativeResize(size_t row, size_t col)
CMatrixFixed(const Eigen::CwiseBinaryOp< Op, Lhs, Rhs > &p)
Convert from Eigen binary op.
void resize(const matrix_size_t &siz, [[maybe_unused]] bool zeroNewElements=false)
Throws if size does not match with the fixed matrix size.
T & operator[](int i)
Access the [i-th] element (for 1xN or Nx1 matrices)
const T & operator()(int i) const
static constexpr int is_mrpt_type
CMatrixFixed(TConstructorFlags_Matrices)
Constructor which leaves the matrix uninitialized.
T & operator()(int i)
Access the i-th element, Row-Major order, without out-of-bounds check (except in Debug builds) ...
CMatrixFixed(const size_type rows, const size_type cols)
Convenient ctor from size: in this class, it throws if size does not match compile-time size...
CMatrixFixed< T, ROWS, 1 > llt_solve(const CMatrixFixed< T, ROWS, 1 > &b) const
Solves the linear system Ax=b, returns x, with A this symmetric matrix.
#define ASSERT_(f)
Defines an assertion mechanism.
void loadFromArray(const VECTOR &vals)
void resize(size_t row, size_t col)
This base provides a set of functions for maths stuff.
typename vec_t::const_iterator const_iterator
CMatrixFixed(const Eigen::Product< _Lhs, _Rhs, Option > &p)
Convert from Eigen product.
CMatrixFixed< T, ROWS, 1 > lu_solve(const CMatrixFixed< T, ROWS, 1 > &b) const
Solves the linear system Ax=b, returns x, with A this asymmetric matrix.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
void setFromMatrixLike(const MAT &m)
void sum_At(const CMatrixFixed< Scalar, ROWS, COLS > &A)
this += AT
CMatrixFixed & operator=(const Eigen::VectorBlock< VectorType, Size > &m)
Assignment from an Eigen vector block.
std::array< double, ROWS *COLS > vec_t
RowMajor matrix data.
Eigen::Matrix< T, ROWS, COLS, StorageOrder, ROWS, COLS > eigen_t
const double & const_reference
const_iterator end() const
static constexpr int ColsAtCompileTime
CMatrixFixed & operator=(const Eigen::MatrixBase< Derived > &m)
Assignment from an Eigen matrix.
const T & operator()(int row, int col) const
double value_type
The type of the matrix elements.
CMatrixFixed(const T *data)
Initializes from a plain buffer with RowMajor values.
CMatrixFixed(const T(&vals)[N])
Initializes from a C array with RowMajor values.
constexpr size_type rows() const
Number of rows in the matrix.
const_iterator cend() const
Base CRTP class for all MRPT matrices.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CMatrixFixed & operator=(const CMatrixDynamic< U > &m)
Assignment from a Dynamic matrix.
GLdouble GLdouble GLdouble r
const T & operator[](int i) const
CMatrixFixed< float, ROWS, COLS > cast_float() const
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
GLenum GLenum GLvoid * row
CMatrixFixed(const Eigen::MatrixBase< Derived > &m)
Convert from Eigen matrix.
CMatrixFixed(const Eigen::VectorBlock< VectorType, Size > &m)
Convert from Eigen block.
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
#define MRPT_MATRIX_CONSTRUCTORS_FROM_POSES(_CLASS_)
constexpr size_type cols() const
Number of columns in the matrix.
std::ptrdiff_t difference_type
void swap(CMatrixFixed &o)
typename vec_t::iterator iterator
This template class provides the basic functionality for a general 2D any-size, resizable container o...
GLsizei GLsizei GLenum GLenum const GLvoid * data
CMatrixFixed< double, ROWS, COLS > cast_double() const
Auxiliary class used in CMatrixDynamic:size(), CMatrixDynamic::resize(), CMatrixFixed::size(), CMatrixFixed::resize(), to mimic the behavior of STL-containers.
void setSize(size_t row, size_t col, [[maybe_unused]] bool zeroNewElements=false)
Throws if size does not match with the fixed matrix size.
void loadFromRawPointer(const T *data)
Initializes from a plain buffer with RowMajor values.
static constexpr int RowsAtCompileTime
const_iterator begin() const