template class mrpt::math::CMatrixFixed
Overview
A compile-time fixed-size numeric matrix container.
It uses a RowMajor element memory layout.
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
See also:
CMatrixDynamic (for dynamic-size matrices)
#include <mrpt/math/CMatrixFixed.h> template <typename T, matrix_dim_t ROWS, matrix_dim_t COLS> class CMatrixFixed: public mrpt::math::MatrixBase { public: // typedefs typedef T value_type; // construction CMatrixFixed(); CMatrixFixed(TConstructorFlags_Matrices); template <size_t N> CMatrixFixed(const T(&) vals [N]); CMatrixFixed(const T* data); template <class Derived> CMatrixFixed(const Eigen::MatrixBase<Derived>& m); template <typename LHS, typename RHS, int Option> CMatrixFixed(const Eigen::Product<LHS, RHS, Option>& p); template <typename Op, typename Lhs, typename Rhs> CMatrixFixed(const Eigen::CwiseBinaryOp<Op, Lhs, Rhs>& p); template <typename VectorType, int Size> CMatrixFixed(const Eigen::VectorBlock<VectorType, Size>& m); CMatrixFixed(const size_type rows, const size_type cols); // methods template <class Derived> CMatrixFixed& operator = (const Eigen::MatrixBase<Derived>& m); template <typename VectorType, int Size> CMatrixFixed& operator = (const Eigen::VectorBlock<VectorType, Size>& m); template <typename U> CMatrixFixed& operator = (const CMatrixDynamic<U>& m); void loadFromRawPointer(const T* data); void setSize(size_type row, size_type col, ] bool zeroNewElements = false); void resize(const matrix_size_t& siz, ] bool zeroNewElements = false); constexpr size_type rows() const; constexpr size_type cols() const; constexpr matrix_size_t size() const; template < typename EIGEN_MATRIX = eigen_t, typename EIGEN_MAP = Eigen::Map<EIGEN_MATRIX, EIGEN_MAP_ALIGN_BYTES, Eigen::InnerStride<1>> > EIGEN_MAP asEigen(); const T* data() const; T* data(); T& operator () (Index row, Index col); T& operator () (Index i); T& operator [] (Index i); CMatrixFixed<T, ROWS, 1> llt_solve(const CMatrixFixed<T, ROWS, 1>& b) const; CMatrixFixed<T, ROWS, 1> lu_solve(const CMatrixFixed<T, ROWS, 1>& b) const; void sum_At(const CMatrixFixed<Scalar, ROWS, COLS>& A); }; // direct descendants template <class T> class CQuaternion;
Inherited Members
public: // typedefs typedef matrix_index_t Index_t; typedef matrix_dim_t size_type_t; // methods void setConstant(const Scalar value); void setConstant(matrix_dim_t nrows, matrix_dim_t ncols, const Scalar value); void setConstant(matrix_dim_t nrows, const Scalar value); void assign(const matrix_dim_t N, const Scalar value); void setZero(); void setZero(matrix_dim_t nrows, matrix_dim_t ncols); void setZero(matrix_dim_t nrows); static Derived Constant(const Scalar value); static Derived Constant(matrix_dim_t nrows, matrix_dim_t ncols, const Scalar value); static Derived Zero(); static Derived Zero(matrix_dim_t nrows, matrix_dim_t ncols); auto block(matrix_index_t start_row, matrix_index_t start_col, matrix_dim_t BLOCK_ROWS, matrix_dim_t BLOCK_COLS); auto block(matrix_index_t start_row, matrix_index_t start_col, matrix_dim_t BLOCK_ROWS, matrix_dim_t 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 <matrix_dim_t N> CMatrixFixed<Scalar, N, 1> tail() const; template <matrix_dim_t N> CMatrixFixed<Scalar, N, 1> head() const; Scalar& coeffRef(matrix_index_t r, matrix_index_t c); const Scalar& coeff(matrix_index_t r, matrix_index_t c) const; Scalar minCoeff(matrix_index_t& outIndexOfMin) const; Scalar minCoeff(matrix_index_t& rowIdx, matrix_index_t& colIdx) const; Scalar maxCoeff(matrix_index_t& outIndexOfMax) const; Scalar maxCoeff(matrix_index_t& rowIdx, matrix_index_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; auto col(Index_t colIdx); auto col(Index_t colIdx) const; auto row(Index_t rowIdx); auto row(Index_t rowIdx) const; template <typename VectorLike> void extractRow(Index_t rowIdx, VectorLike& v) const; template <typename VectorLike> VectorLike extractRow(Index_t rowIdx) const; template <typename VectorLike> void extractColumn(Index_t colIdx, VectorLike& v) const; template <typename VectorLike> VectorLike extractColumn(Index_t colIdx) const; template <size_type_t BLOCK_ROWS, size_type_t BLOCK_COLS> CMatrixFixed<Scalar, BLOCK_ROWS, BLOCK_COLS> extractMatrix( const Index_t start_row = 0, const Index_t start_col = 0 ) const; CMatrixDynamic<Scalar> extractMatrix( const size_type_t BLOCK_ROWS, const size_type_t BLOCK_COLS, const Index_t start_row, const Index_t start_col ) const; Derived& mbDerived(); const Derived& mbDerived() const; void setIdentity(); void setIdentity(const size_type_t N); static Derived Identity(); static Derived Identity(const size_type_t N);
Typedefs
typedef T value_type
The type of the matrix elements.
Construction
CMatrixFixed()
Default constructor, initializes all elements to zero.
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> CMatrixFixed(const T(&) vals [N])
Initializes from a C array with RowMajor values.
CMatrixFixed(const T* data)
Initializes from a plain buffer with RowMajor values.
template <class Derived> CMatrixFixed(const Eigen::MatrixBase<Derived>& m)
Convert from Eigen matrix.
template <typename LHS, typename RHS, int Option> CMatrixFixed(const Eigen::Product<LHS, RHS, Option>& p)
Convert from Eigen product.
template <typename Op, typename Lhs, typename Rhs> CMatrixFixed(const Eigen::CwiseBinaryOp<Op, Lhs, Rhs>& p)
Convert from Eigen binary op.
template <typename VectorType, int Size> CMatrixFixed(const Eigen::VectorBlock<VectorType, Size>& m)
Convert from Eigen block.
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.
Methods
template <class Derived> CMatrixFixed& operator = (const Eigen::MatrixBase<Derived>& m)
Assignment from an Eigen matrix.
template <typename VectorType, int Size> CMatrixFixed& operator = (const Eigen::VectorBlock<VectorType, Size>& m)
Assignment from an Eigen vector block.
template <typename U> CMatrixFixed& operator = (const CMatrixDynamic<U>& m)
Assignment from a Dynamic matrix.
void loadFromRawPointer(const T* data)
Initializes from a plain buffer with RowMajor values.
Unsafe, prefer loadFromArray() wherever possible, to ensure buffer length checks.
void setSize(size_type row, size_type col, ] bool zeroNewElements = false)
Throws if size does not match with the fixed matrix size.
void resize(const matrix_size_t& siz, ] bool zeroNewElements = false)
Throws if size does not match with the fixed matrix size.
constexpr size_type rows() const
Number of rows in the matrix.
See also:
constexpr size_type cols() const
Number of columns in the matrix.
See also:
constexpr matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
template < typename EIGEN_MATRIX = eigen_t, typename EIGEN_MAP = Eigen::Map<EIGEN_MATRIX, EIGEN_MAP_ALIGN_BYTES, Eigen::InnerStride<1>> > EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object
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.
T* data()
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
T& operator () (Index row, Index col)
Access (row,col), without out-of-bounds check (except in Debug builds)
T& operator () (Index i)
Access the i-th element, Row-Major order, without out-of-bounds check (except in Debug builds)
T& operator [] (Index i)
Access the [i-th] element (for 1xN or Nx1 matrices)
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:
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:
void sum_At(const CMatrixFixed<Scalar, ROWS, COLS>& A)
this += A T