raisim::MatDyn
class · #include <raisim/math.hpp>
Inherits: raisim::DynamicArray
Dynamically sized matrix of doubles, stored column-major: element (i, j) is v[i + j *rows()].
n is the number of rows and m the number of columns. resize() reallocates and does not preserve the contents; newly allocated elements are uninitialized. e() returns an Eigen map that aliases the same memory.
Constructors & destructor
MatDyn
MatDyn() = defaultMatDyn(size_t rows, size_t cols)Allocates a rows x cols matrix with uninitialized elements.
Parameters
| Parameter | Description |
|---|---|
rows (in) | number of rows |
cols (in) | number of columns |
MatDyn(const MatDyn &mat)Deep copy.
Parameters
| Parameter | Description |
|---|---|
mat (in) | matrix to copy |
Public member functions
size
size_t size() constReturns number of elements, rows() * cols().
rows
size_t rows() constReturns number of rows.
cols
size_t cols() constReturns number of columns.
e
Eigen::Map<Eigen::Matrix<double, -1, -1>> e()Returns Eigen map aliasing this matrix's memory (writes go to this matrix).
const Eigen::Map<const Eigen::Matrix<double, -1, -1>> e() constReturns read-only Eigen map aliasing this matrix's memory.
operator()
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).
resize
void resize(size_t rows, size_t cols)Reallocates to rows x cols. The previous contents are discarded and the new elements are uninitialized.
Parameters
| Parameter | Description |
|---|---|
rows (in) | number of rows |
cols (in) | number of columns |
fillSub
template <size_t j, size_t k>
void fillSub(size_t startRow, size_t startColumn, const Mat<j, k> &in)Copies in into a block of this matrix. Bounds are checked only in debug (RSDEBUG) builds.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startColumn (in) | column of the block's top-left element |
in (in) | block values |
template <size_t j>
void fillSub(size_t startRow, size_t startColumn, const Vec<j> &in)Copies in into a column segment of this matrix. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the first element |
startColumn (in) | column to write |
in (in) | segment values |
fillSubSkewSym
void fillSubSkewSym(size_t startRow, size_t startColumn, const Vec<3> &in)Writes the skew-symmetric (cross-product) matrix of in, [in]x with [in]x * a = in x a, into the 3x3 block at (startRow, startColumn). Only the six off-diagonal entries are written; the block's diagonal is left untouched. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startColumn (in) | column of the block's top-left element |
in (in) | 3D vector |
fillSubSkewSymTransposed
void fillSubSkewSymTransposed(
size_t startRow,
size_t startColumn,
Vec<3> &in)Like fillSubSkewSym() but writes the transpose, -[in]x. The block's diagonal is left untouched. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startColumn (in) | column of the block's top-left element |
in (in) | 3D vector |
fillSubTransposed
template <size_t j, size_t k>
void fillSubTransposed(
size_t startRow,
size_t startColumn,
const Mat<j, k> &in)Copies the transpose of in into a block of this matrix. Bounds are checked only in debug builds.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row of the block's top-left element |
startColumn (in) | column of the block's top-left element |
in (in) | matrix whose transpose is written |
template <size_t j>
void fillSubTransposed(
size_t startRow,
size_t startColumn,
const Vec<j> &in)Copies in into a row segment of this matrix. No bounds check.
Parameters
| Parameter | Description |
|---|---|
startRow (in) | row to write |
startColumn (in) | column of the first element |
in (in) | segment values |
setIdentity
void setIdentity()Sets ones on the main diagonal and zeros elsewhere (also valid for non-square matrices).
setZero
void setZero()Sets all elements to zero.
void setZero(size_t rows, size_t cols)Resizes to rows x cols (discarding the contents) and sets all elements to zero.
Parameters
| Parameter | Description |
|---|---|
rows (in) | number of rows |
cols (in) | number of columns |
setConstant
void setConstant(double cValue)Sets all elements to cValue.
Parameters
| Parameter | Description |
|---|---|
cValue (in) | value |
sum
double sum() constReturns sum of all elements.
operator=
template <size_t rows, size_t cols>
MatDyn &operator=(const Mat<rows, cols> &rhs)Copies a fixed-size Mat, resizing this matrix if needed.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | matrix to copy |
Returns *this
template <int rows, int cols>
MatDyn &operator=(const Eigen::Matrix<double, rows, cols> &rhs)Copies an Eigen matrix, resizing this matrix if needed.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | matrix to copy |
Returns *this
MatDyn &operator=(const MatDyn &rhs)Deep copy; resizes this matrix if the dimensions differ.
Parameters
| Parameter | Description |
|---|---|
rhs (in) | matrix to copy |
Returns *this
operator*=
void operator*=(double val)Multiplies every element by val.
Parameters
| Parameter | Description |
|---|---|
val (in) | scale factor |
Public attributes
n
size_t nNumber of rows. Use resize() instead of writing it directly.
m
size_t mNumber of columns. Use resize() instead of writing it directly.
Inherited members
From raisim::DynamicArray: data, operator[], ptr, v