Template Class MatrixVectorBase

Inheritance Relationships

Derived Types

Class Documentation

template<typename Scalar, class Derived>
class MatrixVectorBase

Base CRTP class for all MRPT vectors and matrices.

Template methods whose implementation is not in this header file are explicitly instantiated and exported for these derived types:

See also

CMatrixFixed

Subclassed by mrpt::math::MatrixBase< T, CMatrixDynamic< T > >, mrpt::math::MatrixBase< T, CMatrixFixed< T, ROWS, COLS > >, mrpt::math::MatrixBase< Scalar, Derived >

Initialization methods

inline void fill(const Scalar &val)

Fill all the elements with a given value (Note: named “fillAll” since “fill” will be used by child classes)

inline void setConstant(const Scalar value)
inline void setConstant(matrix_dim_t nrows, matrix_dim_t ncols, const Scalar value)
inline void setConstant(matrix_dim_t nrows, const Scalar value)
inline void assign(const matrix_dim_t N, const Scalar value)
inline void setZero()
inline void setZero(matrix_dim_t nrows, matrix_dim_t ncols)
inline void setZero(matrix_dim_t nrows)
static inline Derived Constant(const Scalar value)
static inline Derived Constant(matrix_dim_t nrows, matrix_dim_t ncols, const Scalar value)
static inline Derived Zero()
static inline Derived Zero(matrix_dim_t nrows, matrix_dim_t ncols)

Operations that DO require <tt>\#include \<Eigen/Dense\></tt> in user code

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

non-const block(): Returns an Eigen::Block reference to the block

inline auto block(matrix_index_t start_row, matrix_index_t start_col, matrix_dim_t BLOCK_ROWS, matrix_dim_t BLOCK_COLS)
inline auto block(matrix_index_t start_row, matrix_index_t start_col, matrix_dim_t BLOCK_ROWS, matrix_dim_t BLOCK_COLS) const
inline auto transpose()
inline auto transpose() const
inline auto array()
inline auto array() const
inline auto operator-() const
template<typename S2, class D2>
inline auto operator+(const MatrixVectorBase<S2, D2> &m2) const
template<typename S2, class D2>
inline void operator+=(const MatrixVectorBase<S2, D2> &m2)
template<typename S2, class D2>
inline auto operator-(const MatrixVectorBase<S2, D2> &m2) const
template<typename S2, class D2>
inline void operator-=(const MatrixVectorBase<S2, D2> &m2)
template<typename S2, class D2>
inline auto operator*(const MatrixVectorBase<S2, D2> &m2) const
inline auto operator*(const Scalar s) const
template<matrix_dim_t N>
inline CMatrixFixed<Scalar, N, 1> tail() const
template<matrix_dim_t N>
inline CMatrixFixed<Scalar, N, 1> head() const

Standalone operations (do NOT require <tt>\#include \<Eigen/Dense\></tt>)

inline Scalar &coeffRef(matrix_index_t r, matrix_index_t c)
inline const Scalar &coeff(matrix_index_t r, matrix_index_t c) const
Scalar minCoeff() const

Minimum value in the matrix/vector

Scalar minCoeff(matrix_index_t &outIndexOfMin) const
Scalar minCoeff(matrix_index_t &rowIdx, matrix_index_t &colIdx) const
Scalar maxCoeff() const

Maximum value in the matrix/vector

Scalar maxCoeff(matrix_index_t &outIndexOfMax) const
Scalar maxCoeff(matrix_index_t &rowIdx, matrix_index_t &colIdx) const
inline bool isSquare() const

returns true if matrix is NxN

inline bool empty() const

returns true if matrix/vector has size=0

Scalar norm_inf() const

Compute the norm-infinite of a vector (

\[ ||\mathbf{v}||_\infnty \]
), ie the maximum absolute value of the elements.

Scalar norm() const

Compute the L2 norm of a vector/array/matrix (the Euclidean distance to the origin, taking all the elements as a single vector).

See also

norm

void operator+=(Scalar s)
void operator-=(Scalar s)
void operator*=(Scalar s)
CMatrixDynamic<Scalar> operator*(const CMatrixDynamic<Scalar> &v)
inline Derived operator+(const Derived &m2) const
inline void operator+=(const Derived &m2)
inline Derived operator-(const Derived &m2) const
inline void operator-=(const Derived &m2)
Derived operator*(const Derived &m2) const
Scalar dot(const CVectorDynamic<Scalar> &v) const

dot product of this \cdot v

Scalar dot(const MatrixVectorBase<Scalar, Derived> &v) const
void matProductOf_Ab(const CMatrixDynamic<Scalar> &A, const CVectorDynamic<Scalar> &b)

this = A * b , with A and b a dynamic matrix & vector

void matProductOf_Atb(const CMatrixDynamic<Scalar> &A, const CVectorDynamic<Scalar> &b)

this = AT * b , with A and b a dynamic matrix & vector

Scalar sum() const

Sum of all elements in matrix/vector.

Scalar sum_abs() const

Sum of the absolute value of all elements in matrix/vector.

std::string asString() const

Returns a string representation of the vector/matrix, using Eigen’s default settings.

bool fromMatlabStringFormat(const std::string &s, mrpt::optional_ref<std::ostream> dump_errors_here = std::nullopt)

Reads a matrix from a string in Matlab-like format, for example: “[1 0 2; 0 4 -1]” The string must start with ‘[’ and end with ‘]’. Rows are separated by semicolons ‘;’ and columns in each row by one or more whitespaces ‘ ‘ or tabs ‘\t’. Commas ‘,’ between elements are NOT allowed.

This format is also used for CConfigFile::read_matrix.

See also

inMatlabFormat, CConfigFile::read_matrix

Returns:

true on success. false if the string is malformed, and then the matrix will be resized to 0x0.

std::string inMatlabFormat(const std::size_t decimal_digits = 6) const

Exports the matrix as a string compatible with Matlab/Octave.

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

Saves the vector/matrix to a file compatible with MATLAB/Octave text format.

Parameters:
  • file – The target filename.

  • fileFormat – See TMatrixTextFileFormat. The format of the numbers in the text file.

  • appendMRPTHeader

    Insert this header to the file “% File generated

    by MRPT. Load with MATLAB with: VAR=load(FILENAME);”

  • userHeader – Additional text to be written at the head of the file. Typically MALAB comments “% This file blah blah”. Final end-of-line is not needed.

void loadFromTextFile(std::istream &f)

Loads a vector/matrix from a text file, compatible with MATLAB text format. Lines starting with ‘’ or ‘#’ are interpreted as comments and ignored.

Throws:

std::runtime_error – On format error.

void loadFromTextFile(const std::string &file)

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

template<typename OTHERMATVEC>
inline bool operator==(const OTHERMATVEC &o) const
template<typename OTHERMATVEC>
inline bool operator!=(const OTHERMATVEC &o) const

Public Functions

inline Derived &mvbDerived()
inline const Derived &mvbDerived() const