class mrpt::math::CMatrixF

Overview

This class is a “CSerializable” wrapper for “CMatrixFloat”.

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

#include <mrpt/math/CMatrixF.h>

class CMatrixF:
    public mrpt::serialization::CSerializable,
    public mrpt::math::CMatrixDynamic
{
public:
    // typedefs

    typedef std::shared_ptr<mrpt::math ::CMatrixF> Ptr;
    typedef std::shared_ptr<const mrpt::math ::CMatrixF> ConstPtr;
    typedef std::unique_ptr<mrpt::math ::CMatrixF> UniquePtr;
    typedef std::unique_ptr<const mrpt::math ::CMatrixF> ConstUniquePtr;

    // fields

    static constexpr const char* className = "mrpt::math" "::" "CMatrixF";

    // construction

    CMatrixF();
    CMatrixF(matrix_dim_t row, matrix_dim_t col);
    CMatrixF(const CMatrixFloat& m);
    CMatrixF(const CMatrixDynamic<double>& m);

    template <typename OtherDerived>
    CMatrixF(const Eigen::MatrixBase<OtherDerived>& other);

    // methods

    static constexpr auto getClassName();
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    static std::shared_ptr<CObject> CreateObject();

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename Alloc, typename... Args>
    static Ptr CreateAlloc(
        const Alloc& alloc,
        Args&&... args
        );

    template <typename... Args>
    static UniquePtr CreateUnique(Args&&... args);

    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual mrpt::rtti::CObject* clone() const;

    template <class OTHERMAT>
    CMatrixF& operator = (const OTHERMAT& m);

    template <typename OtherDerived>
    CMatrixF& operator = (const Eigen::MatrixBase<OtherDerived>& other);
};

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<CObject> Ptr;
    typedef std::shared_ptr<const CObject> ConstPtr;
    typedef std::unique_ptr<CObject> UniquePtr;
    typedef std::unique_ptr<const CObject> ConstUniquePtr;
    typedef std::shared_ptr<CSerializable> Ptr;
    typedef std::shared_ptr<const CSerializable> ConstPtr;
    typedef matrix_index_t Index_t;
    typedef matrix_dim_t size_type_t;
    typedef T value_type;
    typedef T Scalar;
    typedef matrix_index_t Index;
    typedef T& reference;
    typedef const T& const_reference;
    typedef matrix_dim_t size_type;
    typedef std::ptrdiff_t difference_type;
    typedef Eigen::Matrix<T, RowsAtCompileTime, ColsAtCompileTime, StorageOrder, RowsAtCompileTime, ColsAtCompileTime> eigen_t;
    typedef typename vec_t::iterator iterator;
    typedef typename vec_t::const_iterator const_iterator;

    // fields

    static constexpr static int RowsAtCompileTime = -1;
    static constexpr static int ColsAtCompileTime = -1;
    static constexpr static int SizeAtCompileTime = -1;
    static constexpr static int is_mrpt_type = 1;
    static constexpr static int StorageOrder = 1;

    // methods

    mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual CObject* clone() const = 0;
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    void fill(const Scalar& val);
    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);

    template <matrix_dim_t BLOCK_ROWS, matrix_dim_t BLOCK_COLS>
    auto block(
        matrix_index_t start_row,
        matrix_index_t start_col
        );

    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() const;
    Scalar minCoeff(matrix_index_t& outIndexOfMin) const;
    Scalar minCoeff(matrix_index_t& rowIdx, matrix_index_t& colIdx) const;
    Scalar maxCoeff() const;
    Scalar maxCoeff(matrix_index_t& outIndexOfMax) const;
    Scalar maxCoeff(matrix_index_t& rowIdx, matrix_index_t& colIdx) const;
    bool isSquare() const;
    bool empty() const;
    Scalar norm_inf() const;
    Scalar norm() 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 CVectorDynamic<Scalar>& v) const;
    Scalar dot(const MatrixVectorBase<Scalar, Derived>& v) const;
    void matProductOf_Ab(const CMatrixDynamic<Scalar>& A, const CVectorDynamic<Scalar>& b);
    void matProductOf_Atb(const CMatrixDynamic<Scalar>& A, const CVectorDynamic<Scalar>& b);
    Scalar sum() const;
    Scalar sum_abs() const;
    std::string asString() const;
    bool fromMatlabStringFormat(const std::string& s, mrpt::optional_ref<std::ostream> dump_errors_here = std::nullopt);
    std::string inMatlabFormat(const std::size_t decimal_digits = 6) const;

    void saveToTextFile(
        const std::string& file,
        mrpt::math::TMatrixTextFileFormat fileFormat = mrpt::math::MATRIX_FORMAT_ENG,
        bool appendMRPTHeader = false,
        const std::string& userHeader = std::string()
        ) const;

    void loadFromTextFile(std::istream& f);
    void loadFromTextFile(const std::string& file);

    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;

    Scalar det() const;
    Derived inverse() const;
    Derived inverse_LLt() const;
    matrix_dim_t rank(Scalar threshold = 0) const;
    bool chol(Derived& U) const;
    bool eig(Derived& eVecs, std::vector<Scalar>& eVals, bool sorted = true) const;
    bool eig_symmetric(Derived& eVecs, std::vector<Scalar>& eVals, bool sorted = true) const;
    Scalar maximumDiagonal() const;
    Scalar minimumDiagonal() const;
    Scalar trace() const;
    void unsafeRemoveColumns(const std::vector<std::size_t>& idxs);
    void removeColumns(const std::vector<std::size_t>& idxsToRemove);
    void unsafeRemoveRows(const std::vector<std::size_t>& idxs);
    void removeRows(const std::vector<std::size_t>& idxsToRemove);

    template <typename OtherMatrixOrVector>
    void insertMatrix(
        const Index_t row_start,
        const Index_t col_start,
        const OtherMatrixOrVector& submat
        );

    template <typename OtherMatrixOrVector>
    void insertMatrixTransposed(
        const Index_t row_start,
        const Index_t col_start,
        const OtherMatrixOrVector& submat
        );

    template <size_type_t BLOCK_ROWS, size_type_t BLOCK_COLS>
    CMatrixFixed<Scalar, BLOCK_ROWS, BLOCK_COLS> blockCopy(
        Index_t start_row = 0,
        Index_t start_col = 0
        ) const;

    CMatrixDynamic<Scalar> blockCopy(Index_t start_row, Index_t start_col, size_type_t BLOCK_ROWS, size_type_t BLOCK_COLS) 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;

    template <typename MAT_A>
    void matProductOf_AAt(const MAT_A& A);

    template <typename MAT_A>
    void matProductOf_AtA(const MAT_A& A);

    Derived& mbDerived();
    const Derived& mbDerived() const;
    void setDiagonal(const size_type_t N, const Scalar value);
    void setDiagonal(const Scalar value);
    void setDiagonal(const std::vector<Scalar>& diags);
    void setIdentity();
    void setIdentity(const size_type_t N);
    void matProductOf_AB(const Derived& A, const Derived& B);
    static Derived Identity();
    static Derived Identity(const size_type_t N);
    iterator begin();
    iterator end();
    const_iterator begin() const;
    const_iterator end() const;
    const_iterator cbegin() const;
    const_iterator cend() const;
    void swap(CMatrixDynamic<T>& o);

    template <class MAT>
    void setFromMatrixLike(const MAT& m);

    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);
    size_type rows() const;
    size_type cols() const;
    matrix_size_t size() const;
    void setSize(size_type row, size_type col, bool zeroNewElements = false);
    void resize(size_type row, size_type col);
    void resize(size_type vectorLen);
    void resize(const matrix_size_t& siz, bool zeroNewElements = false);
    CMatrixDynamic& derived();
    const CMatrixDynamic& derived() const;
    void conservativeResize(size_type row, size_type col);
    const T* data() const;
    T* data();
    T& operator () (Index row, Index col);
    const T& operator () (Index row, Index col) const;
    T& operator [] (Index ith);
    const T& operator [] (Index ith) const;

    template <typename VECTOR>
    void appendRow(const VECTOR& in);

    template <typename VECTOR>
    void setRow(const Index row, const VECTOR& v);

    template <typename VECTOR>
    void setCol(const Index col, const VECTOR& v);

    template <typename VECTOR>
    void appendCol(const VECTOR& in);

    template <typename VECTOR>
    void asVector(VECTOR& out) const;

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

    template <
        typename EIGEN_MATRIX = eigen_t,
        typename EIGEN_MAP = Eigen::Map<const EIGEN_MATRIX, MRPT_MAX_ALIGN_BYTES, Eigen::InnerStride<1>>
        >
    EIGEN_MAP asEigen() const;

    CMatrixDynamic<float> cast_float() const;
    CMatrixDynamic<double> cast_double() const;
    CVectorDynamic<Scalar> llt_solve(const CVectorDynamic<Scalar>& b) const;
    CVectorDynamic<Scalar> lu_solve(const CVectorDynamic<Scalar>& b) const;

Typedefs

typedef std::shared_ptr<mrpt::math ::CMatrixF> Ptr

A type for the associated smart pointer.

Construction

CMatrixF()

Constructor

CMatrixF(matrix_dim_t row, matrix_dim_t col)

Constructor.

CMatrixF(const CMatrixFloat& m)

Copy constructor.

CMatrixF(const CMatrixDynamic<double>& m)

Copy constructor.

template <typename OtherDerived>
CMatrixF(const Eigen::MatrixBase<OtherDerived>& other)

Constructor from any other Eigen class.

Methods

virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const

Returns information about the class of an object in runtime.

virtual mrpt::rtti::CObject* clone() const

Returns a deep copy (clone) of the object, indepently of its class.

template <class OTHERMAT>
CMatrixF& operator = (const OTHERMAT& m)

Assignment operator for float matrixes.

template <typename OtherDerived>
CMatrixF& operator = (const Eigen::MatrixBase<OtherDerived>& other)

Assignment operator from any other Eigen class.