Template Class CMatrixFixed

Inheritance Relationships

Base Type

Derived Type

Class Documentation

template<typename T, matrix_dim_t ROWS, matrix_dim_t COLS>
class CMatrixFixed : public mrpt::math::MatrixBase<T, CMatrixFixed<T, ROWS, COLS>>

A compile-time fixed-size numeric matrix container. It uses a RowMajor element memory layout.

See also

CMatrixDynamic (for dynamic-size matrices)

Note

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

Subclassed by mrpt::math::CQuaternion< T >

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, ROWS, COLS, StorageOrder, ROWS, COLS>
static constexpr int RowsAtCompileTime = ROWS
static constexpr int ColsAtCompileTime = COLS
static constexpr int SizeAtCompileTime = ROWS * COLS
static constexpr int is_mrpt_type = 1
static constexpr int StorageOrder = (ROWS != 1 && COLS == 1) ? 0 : 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

Constructors, assignment operators, initializers

inline CMatrixFixed()

Default constructor, initializes all elements to zero

inline CMatrixFixed(TConstructorFlags_Matrices)

Constructor which leaves the matrix uninitialized. Example of usage: CMatrixFixed<double,3,2> M(mrpt::math::UNINITIALIZED_MATRIX);

template<size_t N>
inline explicit CMatrixFixed(const T (&vals)[N])

Initializes from a C array with RowMajor values

inline explicit CMatrixFixed(const T *data)

Initializes from a plain buffer with RowMajor values

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

Convert from Eigen matrix

template<typename LHS, typename RHS, int Option>
inline explicit CMatrixFixed(const Eigen::Product<LHS, RHS, Option> &p)

Convert from Eigen product

template<typename Op, typename Lhs, typename Rhs>
inline explicit CMatrixFixed(const Eigen::CwiseBinaryOp<Op, Lhs, Rhs> &p)

Convert from Eigen binary op

template<typename VectorType, int Size>
inline explicit CMatrixFixed(const Eigen::VectorBlock<VectorType, Size> &m)

Convert from Eigen block

inline 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. It is provided for the sake of offering a uniform API with CMatrixDynamic.

template<class MAT>
inline void setFromMatrixLike(const MAT &m)
template<class Derived>
inline CMatrixFixed &operator=(const Eigen::MatrixBase<Derived> &m)

Assignment from an Eigen matrix

template<typename VectorType, int Size>
inline CMatrixFixed &operator=(const Eigen::VectorBlock<VectorType, Size> &m)

Assignment from an Eigen vector block

template<typename U>
inline CMatrixFixed &operator=(const CMatrixDynamic<U> &m)

Assignment from a Dynamic matrix

template<typename VECTOR>
inline void loadFromArray(const VECTOR &vals)
inline void loadFromRawPointer(const T *data)

Initializes from a plain buffer with RowMajor values. Unsafe, prefer loadFromArray() wherever possible, to ensure buffer length checks.

inline void setSize(size_type row, size_type col, [[maybe_unused]] bool zeroNewElements = false)

Throws if size does not match with the fixed matrix size

inline void swap(CMatrixFixed &o)
inline CMatrixFixed &derived()
inline const CMatrixFixed &derived() const
inline void conservativeResize(size_type row, size_type col)
inline void resize(size_type n)
inline void resize(const matrix_size_t &siz, [[maybe_unused]] bool zeroNewElements = false)

Throws if size does not match with the fixed matrix size

inline void resize(size_type row, size_type col)
inline constexpr size_type rows() const

Number of rows in the matrix

See also

rows()

inline constexpr size_type cols() const

Number of columns in the matrix

See also

rows()

inline constexpr matrix_size_t size() const

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

Matrix element access & modifiers

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

Get as an Eigen-compatible Eigen::Map object

template<typename EIGEN_MATRIX = eigen_t, typename EIGEN_MAP = Eigen::Map<const EIGEN_MATRIX, MRPT_MAX_STATIC_ALIGN_BYTES, Eigen::InnerStride<1>>>
inline EIGEN_MAP asEigen() const
inline const T *data() const

Return raw pointer to row-major data buffer. All matrix cells can be assumed to be stored contiguously in memory, i.e. row stride = column count.

inline T *data()

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

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

Access (row,col), without out-of-bounds check (except in Debug builds)

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

Access the i-th element, Row-Major order, without out-of-bounds check (except in Debug builds)

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

Access the [i-th] element (for 1xN or Nx1 matrices)

inline const T &operator[](Index i) const
CMatrixFixed<float, ROWS, COLS> cast_float() const
CMatrixFixed<double, ROWS, COLS> cast_double() const
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.

See also

lu_solve()

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.

See also

llt_solve()

inline void sum_At(const CMatrixFixed<Scalar, ROWS, COLS> &A)

this += AT