Template Class CMatrixDynamic
Defined in File CMatrixDynamic.h
Inheritance Relationships
Base Type
public mrpt::math::MatrixBase< T, CMatrixDynamic< T > >(Template Class MatrixBase)
Derived Types
public mrpt::math::CMatrixB(Class CMatrixB)public mrpt::math::CMatrixF(Class CMatrixF)
Class Documentation
-
template<class T>
class CMatrixDynamic : public mrpt::math::MatrixBase<T, CMatrixDynamic<T>> This template class provides the basic functionality for a general 2D any-size, resizable container of numerical or non-numerical elements. Notes:
This class is not serializable since it is a template. For using serialization, see mrpt::math::CMatrixD.
First row or column index is “0”.
This class includes range checks with ASSERT_() if compiling with “_DEBUG” or “MRPT_ALWAYS_CHECKS_DEBUG_MATRICES=1”.
Use asEigen() to get an
Eigen::Map<>object and to access full Algebra functionality.
See also
Subclassed by mrpt::math::CMatrixB, mrpt::math::CMatrixF
Matrix type definitions
-
using Index = matrix_index_t
-
using size_type = matrix_dim_t
-
using difference_type = std::ptrdiff_t
-
using eigen_t = Eigen::Matrix<T, RowsAtCompileTime, ColsAtCompileTime, StorageOrder, RowsAtCompileTime, ColsAtCompileTime>
-
static constexpr int RowsAtCompileTime = -1
-
static constexpr int ColsAtCompileTime = -1
-
static constexpr int SizeAtCompileTime = -1
-
static constexpr int is_mrpt_type = 1
-
static constexpr int StorageOrder = 1
Iterators interface
-
using iterator = typename vec_t::iterator
-
using const_iterator = typename vec_t::const_iterator
-
inline const_iterator begin() const
-
inline const_iterator end() const
-
inline const_iterator cbegin() const
-
inline const_iterator cend() const
Public Functions
-
inline void swap(CMatrixDynamic<T> &o)
Swap with another matrix very efficiently (just swaps a pointer and two integer values).
-
inline CMatrixDynamic(const CMatrixDynamic &m)
Constructors
-
template<typename U>
inline explicit CMatrixDynamic(const CMatrixDynamic<U> &m) Copy (casting from if needed) from another matrix
-
template<class Derived>
inline explicit CMatrixDynamic(const Eigen::MatrixBase<Derived> &m) Convert from Eigen matrix
-
template<typename LHS, typename RHS, int Option>
inline explicit CMatrixDynamic(const Eigen::Product<LHS, RHS, Option> &p) Convert from Eigen product
-
template<typename Op, typename Lhs, typename Rhs>
inline explicit CMatrixDynamic(const Eigen::CwiseBinaryOp<Op, Lhs, Rhs> &p) Convert from Eigen binary op
-
inline CMatrixDynamic(const CMatrixDynamic &m, size_type cropRowCount, size_type cropColCount)
Copy constructor & crop from another matrix
-
template<size_type ROWS, size_type COLS>
inline explicit CMatrixDynamic(const CMatrixFixed<T, ROWS, COLS> &o) Constructor from fixed-size matrix:
-
template<typename V, std::size_t N>
inline CMatrixDynamic(size_type row, size_type col, V (&theArray)[N]) Constructor from a given size and a C array. The array length must match cols x row.
const double numbers[] = { 1,2,3, 4,5,6 }; CMatrixDouble M(3,2, numbers);
-
template<typename V>
inline CMatrixDynamic(size_type row, size_type col, const V &theVector) Constructor from a given size and a STL container (std::vector, std::list,…) with the initial values. The vector length must match cols x row.
-
virtual ~CMatrixDynamic() = default
-
CMatrixDynamic &operator=(const CMatrixDynamic<T> &m) = default
-
template<typename U>
inline CMatrixDynamic &operator=(const CMatrixDynamic<U> &m) Assignment operator from another matrix (possibly of a different type)
-
template<class Derived>
inline CMatrixDynamic &operator=(const Eigen::MatrixBase<Derived> &m) Assignment from an Eigen matrix
-
template<size_type ROWS, size_type COLS>
inline CMatrixDynamic &operator=(const CMatrixFixed<T, ROWS, COLS> &m) Assignment from a fixed matrix
-
template<typename V, size_t N>
inline CMatrixDynamic &operator=(V (&theArray)[N]) Assignment operator for initializing from a C array (The matrix must be set to the correct size before invoking this assignment)
Refer also to the constructor with initialization data CMatrixDynamic::CMatrixDynamicCMatrixDouble M(3,2); const double numbers[] = { 1,2,3, 4,5,6 }; M = numbers;
-
inline CMatrixDynamic(CMatrixDynamic &&m)
Move ctor
-
inline CMatrixDynamic &operator=(CMatrixDynamic &&m)
Move operator
-
inline matrix_size_t size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
-
inline void setSize(size_type row, size_type col, bool zeroNewElements = false)
Changes the size of matrix, maintaining the previous contents.
-
inline void resize(const matrix_size_t &siz, bool zeroNewElements = false)
Resize the matrix
-
inline CMatrixDynamic &derived()
-
inline const CMatrixDynamic &derived() 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 const T &operator()(Index row, Index col) const
Subscript operator to get individual elements
-
inline T &operator[](Index ith)
Subscript operator to get/set an individual element from a row or column matrix.
- Throws:
std::exception – If the object is not a column or row matrix.
-
inline const T &operator[](Index ith) const
Subscript operator to get/set an individual element from a row or column matrix. For non-vectors (NxM matrices), it returns the i-th matrix element, in RowMajor order.
- Throws:
std::exception – If the object is not a column or row matrix.
-
template<typename VECTOR>
inline void appendRow(const VECTOR &in) Appends a new row to the MxN matrix from a 1xN vector. The length of the vector must match the width of the matrix, unless it’s empty: in that case the matrix is resized to 1xN.
CMatrixDouble M(0,0); CVectorDouble v(7),w(7); // ... M.appendRow(v); M.appendRow(w);
See also
extractRow
See also
- Throws:
std::exception – On incorrect vector length.
-
template<typename VECTOR>
inline void appendCol(const VECTOR &in) Appends a new column to the matrix from a vector. The length of the vector must match the number of rows of the matrix, unless it is (0,0).
See also
extractCol
See also
- Throws:
std::exception – On size mismatch.
-
template<typename VECTOR>
inline void asVector(VECTOR &out) const Returns a vector containing the matrix’s values.
-
template<typename EIGEN_MATRIX = eigen_t, typename EIGEN_MAP = Eigen::Map<EIGEN_MATRIX, MRPT_MAX_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_ALIGN_BYTES, Eigen::InnerStride<1>>>
inline EIGEN_MAP asEigen() const
-
CMatrixDynamic<float> cast_float() const
-
CMatrixDynamic<double> cast_double() const
-
CVectorDynamic<Scalar> llt_solve(const CVectorDynamic<Scalar> &b) const
Solves the linear system Ax=b, returns x, with A this symmetric matrix.
See also
-
CVectorDynamic<Scalar> lu_solve(const CVectorDynamic<Scalar> &b) const
Solves the linear system Ax=b, returns x, with A this asymmetric matrix.
See also