26 template <
typename T, std::
size_t ROWS, std::
size_t COLS>
29 template <
typename DER>
55 template <
typename Scalar,
class Derived>
59 Derived&
mvbDerived() {
return static_cast<Derived&
>(*this); }
62 return static_cast<const Derived&
>(*this);
84 Derived::ColsAtCompileTime == 1,
85 "setConstant(n) can be used only for vectors, not matrices");
92 Derived::RowsAtCompileTime > 0 && Derived::ColsAtCompileTime > 0,
93 "Constant() without arguments can be used only for fixed-size " 102 m.setConstant(nrows, ncols, value);
113 inline void setZero(
size_t nrows,
size_t ncols)
120 Derived::ColsAtCompileTime == 1,
121 "setZero(n) can be used only for vectors, not matrices");
126 static Derived
Zero(
size_t nrows,
size_t ncols)
137 template <
int BLOCK_ROWS,
int BLOCK_COLS>
138 auto block(
int start_row,
int start_col)
140 internalAssertEigenDefined<Derived>();
141 return mvbDerived().asEigen().template block<BLOCK_ROWS, BLOCK_COLS>(
142 start_row, start_col);
145 auto block(
int start_row,
int start_col,
int BLOCK_ROWS,
int BLOCK_COLS)
147 internalAssertEigenDefined<Derived>();
149 start_row, start_col, BLOCK_ROWS, BLOCK_COLS);
152 int start_row,
int start_col,
int BLOCK_ROWS,
int BLOCK_COLS)
const 154 internalAssertEigenDefined<Derived>();
156 start_row, start_col, BLOCK_ROWS, BLOCK_COLS);
161 internalAssertEigenDefined<Derived>();
166 internalAssertEigenDefined<Derived>();
172 internalAssertEigenDefined<Derived>();
177 internalAssertEigenDefined<Derived>();
183 internalAssertEigenDefined<Derived>();
187 template <
typename S2,
class D2>
190 internalAssertEigenDefined<Derived>();
193 template <
typename S2,
class D2>
196 internalAssertEigenDefined<Derived>();
200 template <
typename S2,
class D2>
203 internalAssertEigenDefined<Derived>();
206 template <
typename S2,
class D2>
209 internalAssertEigenDefined<Derived>();
213 template <
typename S2,
class D2>
216 internalAssertEigenDefined<Derived>();
221 internalAssertEigenDefined<Derived>();
282 Derived::RowsAtCompileTime == Derived::ColsAtCompileTime ||
283 Derived::ColsAtCompileTime == 1 || Derived::ColsAtCompileTime == -1)
289 throw std::runtime_error(
290 "Explicit instantiation not provided for this matrix size: use " 297 Derived::RowsAtCompileTime == Derived::ColsAtCompileTime ||
298 Derived::ColsAtCompileTime == 1 || Derived::ColsAtCompileTime == -1)
304 throw std::runtime_error(
305 "Explicit instantiation not provided for this matrix size: use " 312 Derived::RowsAtCompileTime == Derived::ColsAtCompileTime ||
313 Derived::ColsAtCompileTime == 1 || Derived::ColsAtCompileTime == -1)
319 throw std::runtime_error(
320 "Explicit instantiation not provided for this matrix size: use " 327 Derived::RowsAtCompileTime == Derived::ColsAtCompileTime ||
328 Derived::ColsAtCompileTime == 1 || Derived::ColsAtCompileTime == -1)
334 throw std::runtime_error(
335 "Explicit instantiation not provided for this matrix size: use " 339 Derived
operator*(
const Derived& m2)
const;
383 const std::string& s,
389 std::string
inMatlabFormat(
const std::size_t decimal_digits = 6)
const;
404 const std::string& file,
407 bool appendMRPTHeader =
false,
408 const std::string& userHeader = std::string())
const;
421 template <
typename OTHERMATVEC>
425 if (d.cols() != o.cols() || d.rows() != o.rows())
return false;
426 for (
typename OTHERMATVEC::Index r = 0; r < d.rows(); r++)
427 for (
typename OTHERMATVEC::Index c = 0; c < d.cols(); c++)
428 if (d(r, c) != o(r, c))
return false;
431 template <
typename OTHERMATVEC>
434 return !(*
this == o);
442 template <
typename DER>
445 if constexpr (!mrpt::is_defined_v<typename DER::eigen_t>)
448 mrpt::is_defined_v<typename DER::eigen_t>,
449 "Using this method requires including `<Eigen/Dense>` in the " 457 typename Scalar,
class Derived,
458 typename = std::enable_if_t<
459 Derived::RowsAtCompileTime == Derived::ColsAtCompileTime ||
460 (Derived::ColsAtCompileTime == 1)>>
461 std::ostream&
operator<<(
Scalar maxCoeff() const
Maximum value in the matrix/vector.
void operator-=(const Derived &m2)
Scalar norm_inf() const
Compute the norm-infinite of a vector ($f[ ||{v}||_ $f]), ie the maximum absolute value of the elemen...
void impl_op_selfsubs(const Derived &m2)
auto operator*(const MatrixVectorBase< S2, D2 > &m2) const
A compile-time fixed-size numeric matrix container.
CMatrixFixed< Scalar, N, 1 > head() const
std::string asString() const
Returns a string representation of the vector/matrix, using Eigen's default settings.
Template for column vectors of dynamic size, compatible with Eigen.
bool empty() const
returns true if matrix/vector has size=0
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).
void fill(const Scalar &val)
engineering format 'e'
const Derived & mvbDerived() const
bool isSquare() const
returns true if matrix is NxN
CMatrixFixed< Scalar, N, 1 > tail() const
auto operator-(const MatrixVectorBase< S2, D2 > &m2) const
std::optional< std::reference_wrapper< T > > optional_ref
Shorter name for std::optional<std::reference_wrapper<T>>
void operator+=(const Derived &m2)
void setZero(size_t nrows)
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.
Derived operator-(const Derived &m2) const
void setConstant(size_t nrows, const Scalar value)
void operator*=(Scalar s)
This base provides a set of functions for maths stuff.
auto block(int start_row, int start_col, int BLOCK_ROWS, int BLOCK_COLS) const
bool operator!=(const OTHERMATVEC &o) const
Scalar dot(const CVectorDynamic< Scalar > &v) const
dot product of this \cdot v
Derived operator+(const Derived &m2) const
auto block(int start_row, int start_col)
non-const block(): Returns an Eigen::Block reference to the block
static Derived Constant(size_t nrows, size_t ncols, const Scalar value)
bool operator==(const OTHERMATVEC &o) const
Derived impl_op_subs(const Derived &m2) const
void assign(const std::size_t N, const Scalar value)
void matProductOf_Ab(const CMatrixDynamic< Scalar > &A, const CVectorDynamic< Scalar > &b)
this = A * b , with A and b a dynamic matrix & vector
void operator+=(const MatrixVectorBase< S2, D2 > &m2)
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
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 st...
void setConstant(const Scalar value)
static Derived Zero(size_t nrows, size_t ncols)
void setZero(size_t nrows, size_t ncols)
const Scalar & coeff(int r, int c) const
Scalar sum_abs() const
Sum of the absolute value of all elements in matrix/vector.
auto operator+(const MatrixVectorBase< S2, D2 > &m2) const
fixed floating point 'f'
const_iterator end() const
auto operator*(const Scalar s) const
const_iterator begin() const
void operator-=(const MatrixVectorBase< S2, D2 > &m2)
Scalar sum() const
Sum of all elements in matrix/vector.
Derived impl_op_add(const Derived &m2) const
void impl_op_selfadd(const Derived &m2)
std::string inMatlabFormat(const std::size_t decimal_digits=6) const
Exports the matrix as a string compatible with Matlab/Octave.
Scalar minCoeff() const
Minimum value in the matrix/vector.
auto block(int start_row, int start_col, int BLOCK_ROWS, int BLOCK_COLS)
Base CRTP class for all MRPT vectors and matrices.
void matProductOf_Atb(const CMatrixDynamic< Scalar > &A, const CVectorDynamic< Scalar > &b)
this = AT * b , with A and b a dynamic matrix & vector
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void setConstant(size_t nrows, size_t ncols, const Scalar value)
void internalAssertEigenDefined()
Issues a static_assert() error if trying to compile a method that requires Eigen headers, without including them.
static Derived Constant(const Scalar value)
Scalar & coeffRef(int r, int c)
void loadFromTextFile(std::istream &f)
Loads a vector/matrix from a text file, compatible with MATLAB text format.