template class mrpt::math::CMatrixDynamic

Overview

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:

CMatrixFixed

#include <mrpt/math/CMatrixDynamic.h>

template <class T>
class CMatrixDynamic: public mrpt::math::MatrixBase
{
public:
    // construction

    CMatrixDynamic(const CMatrixDynamic& m);

    CMatrixDynamic(
        size_type row = 0,
        size_type col = 0
        );

    template <typename U>
    CMatrixDynamic(const CMatrixDynamic<U>& m);

    template <class Derived>
    CMatrixDynamic(const Eigen::MatrixBase<Derived>& m);

    template <typename LHS, typename RHS, int Option>
    CMatrixDynamic(const Eigen::Product<LHS, RHS, Option>& p);

    template <typename Op, typename Lhs, typename Rhs>
    CMatrixDynamic(const Eigen::CwiseBinaryOp<Op, Lhs, Rhs>& p);

    CMatrixDynamic(const CMatrixDynamic& m, size_type cropRowCount, size_type cropColCount);

    template <size_type ROWS, size_type COLS>
    CMatrixDynamic(const CMatrixFixed<T, ROWS, COLS>& o);

    template <typename V, std::size_t N>
    CMatrixDynamic(size_type row, size_type col, V(&) theArray [N]);

    template <typename V>
    CMatrixDynamic(size_type row, size_type col, const V& theVector);

    CMatrixDynamic(CMatrixDynamic&& m);

    // methods

    CMatrixDynamic& operator = (const CMatrixDynamic<T>& m);

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

    template <class Derived>
    CMatrixDynamic& operator = (const Eigen::MatrixBase<Derived>& m);

    template <size_type ROWS, size_type COLS>
    CMatrixDynamic& operator = (const CMatrixFixed<T, ROWS, COLS>& m);

    template <typename V, size_t N>
    CMatrixDynamic& operator = (V(&) theArray [N]);

    CMatrixDynamic& operator = (CMatrixDynamic&& m);
};

// direct descendants

class CMatrixB;
class CMatrixF;

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);

Construction

CMatrixDynamic(const CMatrixDynamic& m)

Constructors.

template <typename U>
CMatrixDynamic(const CMatrixDynamic<U>& m)

Copy (casting from if needed) from another matrix

template <class Derived>
CMatrixDynamic(const Eigen::MatrixBase<Derived>& m)

Convert from Eigen matrix.

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

Convert from Eigen product.

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

Convert from Eigen binary op.

CMatrixDynamic(const CMatrixDynamic& m, size_type cropRowCount, size_type cropColCount)

Copy constructor & crop from another matrix.

template <size_type ROWS, size_type COLS>
CMatrixDynamic(const CMatrixFixed<T, ROWS, COLS>& o)

Constructor from fixed-size matrix:

template <typename V, std::size_t N>
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>
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.

CMatrixDynamic(CMatrixDynamic&& m)

Move ctor.

Methods

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

Assignment operator from another matrix (possibly of a different type)

template <class Derived>
CMatrixDynamic& operator = (const Eigen::MatrixBase<Derived>& m)

Assignment from an Eigen matrix.

template <size_type ROWS, size_type COLS>
CMatrixDynamic& operator = (const CMatrixFixed<T, ROWS, COLS>& m)

Assignment from a fixed matrix.

template <typename V, size_t N>
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)

   CMatrixDouble   M(3,2);
const double numbers[] = {
  1,2,3,
  4,5,6 };
M = numbers;

Refer also to the constructor with initialization data CMatrixDynamic::CMatrixDynamic

CMatrixDynamic& operator = (CMatrixDynamic&& m)

Move operator.