Skip to content

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 ​

cpp
MatDyn() = default
cpp
MatDyn(size_t rows, size_t cols)

Allocates a rows x cols matrix with uninitialized elements.

Parameters

ParameterDescription
rows (in)number of rows
cols (in)number of columns
cpp
MatDyn(const MatDyn &mat)

Deep copy.

Parameters

ParameterDescription
mat (in)matrix to copy

Public member functions ​

size ​

cpp
size_t size() const

Returns number of elements, rows() * cols().

rows ​

cpp
size_t rows() const

Returns number of rows.

cols ​

cpp
size_t cols() const

Returns number of columns.

e ​

cpp
Eigen::Map<Eigen::Matrix<double, -1, -1>> e()

Returns Eigen map aliasing this matrix's memory (writes go to this matrix).

cpp
const Eigen::Map<const Eigen::Matrix<double, -1, -1>> e() const

Returns read-only Eigen map aliasing this matrix's memory.

operator() ​

cpp
double operator()(size_t i, size_t j) const

Parameters

ParameterDescription
i (in)row index
j (in)column index

Returns element (i, j) (no bounds check).

cpp
double &operator()(size_t i, size_t j)

Parameters

ParameterDescription
i (in)row index
j (in)column index

Returns reference to element (i, j) (no bounds check).

resize ​

cpp
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

ParameterDescription
rows (in)number of rows
cols (in)number of columns

fillSub ​

cpp
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

ParameterDescription
startRow (in)row of the block's top-left element
startColumn (in)column of the block's top-left element
in (in)block values
cpp
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

ParameterDescription
startRow (in)row of the first element
startColumn (in)column to write
in (in)segment values

fillSubSkewSym ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
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 ​

cpp
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

ParameterDescription
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
cpp
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

ParameterDescription
startRow (in)row to write
startColumn (in)column of the first element
in (in)segment values

setIdentity ​

cpp
void setIdentity()

Sets ones on the main diagonal and zeros elsewhere (also valid for non-square matrices).

setZero ​

cpp
void setZero()

Sets all elements to zero.

cpp
void setZero(size_t rows, size_t cols)

Resizes to rows x cols (discarding the contents) and sets all elements to zero.

Parameters

ParameterDescription
rows (in)number of rows
cols (in)number of columns

setConstant ​

cpp
void setConstant(double cValue)

Sets all elements to cValue.

Parameters

ParameterDescription
cValue (in)value

sum ​

cpp
double sum() const

Returns sum of all elements.

operator= ​

cpp
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

ParameterDescription
rhs (in)matrix to copy

Returns *this

cpp
template <int rows, int cols>
MatDyn &operator=(const Eigen::Matrix<double, rows, cols> &rhs)

Copies an Eigen matrix, resizing this matrix if needed.

Parameters

ParameterDescription
rhs (in)matrix to copy

Returns *this

cpp
MatDyn &operator=(const MatDyn &rhs)

Deep copy; resizes this matrix if the dimensions differ.

Parameters

ParameterDescription
rhs (in)matrix to copy

Returns *this

operator*= ​

cpp
void operator*=(double val)

Multiplies every element by val.

Parameters

ParameterDescription
val (in)scale factor

Public attributes ​

n ​

cpp
size_t n

Number of rows. Use resize() instead of writing it directly.

m ​

cpp
size_t m

Number of columns. Use resize() instead of writing it directly.

Inherited members ​

From raisim::DynamicArray: data, operator[], ptr, v

RaiSim — physics for robotics and AI.