raisim::Mat
class · #include <raisim/math/Matrix.hpp>
Inherits: raisim::MatExpr< Mat< n, m > >
template <size_t n, size_t m>
class MatFixed-size n x m matrix of doubles, stored column-major: element (i, j) is v[i + j * n]. Vec<n> is the column-vector alias Mat<n, 1>.
The default constructor leaves the elements uninitialized. Arithmetic on Mat objects and other raisim matrix expressions (+, -, *, /, also with scalars) builds expression templates that hold their operands by reference and are evaluated when assigned, so do not store an expression that refers to temporaries (e.g. with auto). Assignment evaluates the expression element by element into the destination: element-wise expressions that read the destination (a = a + b) are fine, but a product or transpose that reads it (a = a * b, a = a.transpose()) gives wrong results; the 4x4 by 4x4 product is evaluated eagerly and is the exception. e() returns an Eigen map of the same memory.
In addition to the members listed here, Mat provides (through a shared macro that is not shown in this reference) norm(), sum(), squaredNorm(), dot(), setZero(), setConstant(), scalar *=, /=, += and -=, assignment from any matrix-like object of the same dimensions, cross() and skew() for 3D vectors, and an implicit conversion to double that returns element (0, 0).
Public types
EigenMat
typedef Eigen::Map<Eigen::Matrix<ScalarType, n, m>> EigenMatMutable Eigen map type returned by e().
ConstEigenMat
typedef Eigen::Map<const Eigen::Matrix<ScalarType, n, m>> ConstEigenMatRead-only Eigen map type returned by e() const.
SelfType
typedef Mat<n, m> SelfTypeThis type (used by the shared expression machinery).
Constructors & destructor
Mat
Mat() = defaultLeaves the elements uninitialized.
Mat(std::initializer_list<ScalarType> init)Constructs from values listed in column-major order. The list may not exceed n*m elements (fatal otherwise); missing trailing elements are zero-filled.
Parameters
| Parameter | Description |
|---|---|
init (in) | element values, column-major |
template <class scalarType>
Mat(const Eigen::Matrix<scalarType, n, m> &eigen)Copies an Eigen matrix with the same dimensions.
Parameters
| Parameter | Description |
|---|---|
eigen (in) | source matrix |
template <class T2>
Mat(const T2 &rhs)Constructs from any matrix-like object with rows(), cols() and operator()(i, j), such as a raisim matrix expression or an Eigen object. Mismatched dimensions are a compile-time error for raisim types and fatal at run time otherwise.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | source |
Public member functions
operator=
template <class T2>
Mat<n, m> &operator=(const MatExpr<T2> &expr)Evaluates an expression with identical dimensions into this matrix (see the class description for aliasing).
Parameters
| Parameter | Description |
|---|---|
expr (in) | expression to evaluate |
Returns *this
template <size_t n2, size_t m2>
Mat<n, m> &operator=(const Mat<n2, m2> &expr)Copies a Mat with identical dimensions (checked at compile time).
Parameters
| Parameter | Description |
|---|---|
expr (in) | matrix to copy |
Returns *this
ptr
ScalarType *ptr()Returns pointer to the first element.
const ScalarType *ptr() constReturns pointer to the first element.
data
ScalarType *data()Returns pointer to the first element (Eigen-compatible name).
const ScalarType *data() constReturns pointer to the first element (Eigen-compatible name).
operator[]
double operator[](size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | column-major linear index |
Returns element i (no bounds check)
double &operator[](size_t i)Parameters
| Parameter | Description |
|---|---|
i (in) | column-major linear index |
Returns reference to element i (no bounds check)
operator()
double operator()(size_t i) constParameters
| Parameter | Description |
|---|---|
i (in) | column-major linear index |
Returns element i (no bounds check)
double &operator()(size_t i)Parameters
| Parameter | Description |
|---|---|
i (in) | column-major linear index |
Returns reference to element i (no bounds check)
double operator()(size_t i, size_t j) constParameters
| Parameter | Description |
|---|---|
i (in) | row index |
j (in) | column index |
Returns element (i, j) (no bounds check)
double &operator()(size_t i, size_t j)Parameters
| Parameter | Description |
|---|---|
i (in) | row index |
j (in) | column index |
Returns reference to element (i, j) (no bounds check)
operator-
Mat<n, m> operator-()Returns the negated matrix.
e
EigenMat e()Returns Eigen map aliasing this matrix's memory (writes go to this matrix).
ConstEigenMat e() constReturns read-only Eigen map aliasing this matrix's memory.
operator<<
ElementRef<Mat<n, m>> operator<<(ScalarType a)Comma-initializer entry point (Eigen-style): v << 1.0, 2.0, 3.0;. Elements are written in column-major order; writing past the last element is fatal.
Parameters
| Parameter | Description |
|---|---|
a (in) | value of the first element |
Returns proxy that receives the following elements
normalize
void normalize()Eigen-like vector normalization (vectors only). A zero vector is left unchanged.
operator-=
void operator-=(const Mat<n, m> &val)Element-wise subtraction.
Parameters
| Parameter | Description |
|---|---|
val (in) | matrix to subtract |
operator+=
void operator+=(const Mat<n, m> &val)Element-wise addition.
Parameters
| Parameter | Description |
|---|---|
val (in) | matrix to add |
operator/=
void operator/=(const Mat<n, m> &val)Element-wise division.
Parameters
| Parameter | Description |
|---|---|
val (in) | element-wise divisors |
setIdentity
void setIdentity()Sets this square matrix to the identity.
determinant
ScalarType determinant() constReturns the determinant, computed by Eigen (square matrices only).
inverse
Mat<n, n> inverse() constReturns the inverse, computed by Eigen (square matrices only). Singularity is not checked.
transpose
Transpose<Mat<n, m>> transpose()Returns lazy transpose expression referencing this matrix.
const Transpose<Mat<n, m>> transpose() constReturns lazy transpose expression referencing this matrix.
row
RowRef<Mat<n, m>, m> row(size_t r)Parameters
| Parameter | Description |
|---|---|
r (in) | row index |
Returns proxy referencing row r; writes go to this matrix.
RowRef<const Mat<n, m>, m> row(size_t r) constParameters
| Parameter | Description |
|---|---|
r (in) | row index |
Returns read-only proxy referencing row r.
col
ColRef<Mat<n, m>, n> col(size_t r)Parameters
| Parameter | Description |
|---|---|
r (in) | column index |
Returns proxy referencing column r; writes go to this matrix.
ColRef<const Mat<n, m>, n> col(size_t r) constParameters
| Parameter | Description |
|---|---|
r (in) | column index |
Returns read-only proxy referencing column r.
segment
template <size_t sizeRow, size_t sizeCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> segment(
size_t startRow,
size_t startCol)Block of size sizeRow x sizeCol (template arguments) starting at a run-time position. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startCol (in) | column of the block's top-left element |
Returns proxy referencing the block; writes go to this matrix.
template <size_t sizeRow, size_t sizeCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> segment(
size_t startRow,
size_t startCol) constRead-only block of size sizeRow x sizeCol starting at a run-time position. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startCol (in) | column of the block's top-left element |
Returns read-only proxy referencing the block.
head
template <size_t sizeRow>
BlockRef<Mat<n, m>, sizeRow, 1> head()Returns proxy referencing the first sizeRow elements (vectors only).
template <size_t sizeRow>
BlockRef<const Mat<n, m>, sizeRow, 1> head() constReturns read-only proxy referencing the first sizeRow elements (vectors only).
tail
template <size_t sizeRow>
BlockRef<Mat<n, m>, sizeRow, 1> tail()Returns proxy referencing the last sizeRow elements (vectors only).
template <size_t sizeRow>
BlockRef<const Mat<n, m>, sizeRow, 1> tail() constReturns read-only proxy referencing the last sizeRow elements (vectors only).
topLeftCorner
template <size_t sizeRow, size_t sizeCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> topLeftCorner() constReturns read-only proxy referencing the top-left sizeRow x sizeCol block.
template <size_t sizeRow, size_t sizeCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> topLeftCorner()Returns proxy referencing the top-left sizeRow x sizeCol block.
topRightCorner
template <size_t sizeRow, size_t sizeCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> topRightCorner() constReturns read-only proxy referencing the top-right sizeRow x sizeCol block.
template <size_t sizeRow, size_t sizeCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> topRightCorner()Returns proxy referencing the top-right sizeRow x sizeCol block.
bottomRightCorner
template <size_t sizeRow, size_t sizeCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> bottomRightCorner() constReturns read-only proxy referencing the bottom-right sizeRow x sizeCol block.
template <size_t sizeRow, size_t sizeCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> bottomRightCorner()Returns proxy referencing the bottom-right sizeRow x sizeCol block.
bottomLeftCorner
template <size_t sizeRow, size_t sizeCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> bottomLeftCorner() constReturns read-only proxy referencing the bottom-left sizeRow x sizeCol block.
template <size_t sizeRow, size_t sizeCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> bottomLeftCorner()Returns proxy referencing the bottom-left sizeRow x sizeCol block.
block
template <size_t sizeRow, size_t sizeCol, size_t startRow, size_t startCol>
BlockRef<const Mat<n, m>, sizeRow, sizeCol> block() constReturns read-only proxy referencing the sizeRow x sizeCol block at (startRow, startCol), all given as template arguments.
template <size_t sizeRow, size_t sizeCol, size_t startRow, size_t startCol>
BlockRef<Mat<n, m>, sizeRow, sizeCol> block()Returns proxy referencing the sizeRow x sizeCol block at (startRow, startCol), all given as template arguments.
Static member functions
size static
static constexpr size_t size()Returns number of elements, n * m.
rows static
static constexpr size_t rows()Returns number of rows, n.
cols static
static constexpr size_t cols()Returns number of columns, m.
getIdentity static
static Mat<n, n> getIdentity()Returns the n x n identity matrix (square matrices only).
Identity static
static Mat<n, n> Identity()Returns the n x n identity matrix (Eigen-style name for getIdentity()).
getZeros static
static Mat<n, m> getZeros()Returns a matrix of zeros.
Zero static
static Mat<n, m> Zero()Returns a matrix of zeros (Eigen-style name for getZeros()).
Public attributes
alignment_only
std::aligned_storage<n *m *sizeof(ScalarType), 32> alignment_onlyv
double v[n *m](anonymous union)
An anonymous union: its members are listed with the other attributes and share storage.