DenseMatrix

template<typename T, Int ROWS, Int COLS = ROWS>
class DenseMatrix

Dense matrix with ROWS rows and COLS columns.

Entries are stored in row-major format

Template Parameters:
  • T – Data type of matrix entries

  • ROWS – Number of rows

  • COLS – Number of columns

Subclassed by godzilla::DenseVector< Real, DIM >

Public Functions

inline int get_num_rows() const

Get the number of rows.

Returns:

The number of rows

inline int get_num_cols() const

Get the number of columns.

Returns:

The number of columns

inline const T &get(Int row, Int col) const

Get entry at specified location for reading.

Parameters:
  • row – Row number

  • col – Column number

Returns:

Entry at the specified location

inline DenseMatrix<T, ROWS, 1> column(Int idx) const

Obtain a column from the matrix.

Parameters:

idx – Index of the column

Returns:

Column as a DenseVector

inline DenseMatrix<T, 1, COLS> row(Int idx) const

Obtain a column from the matrix.

Parameters:

idx – Index of the column

Returns:

Column as a DenseVector

inline T &set(Int row, Int col)

Get entry at specified location for writing.

Parameters:
  • row – Row number

  • col – Column number

Returns:

Entry at the specified location

inline void set(Int row, Int col, const T &val)

Set value at a specified location.

Parameters:
  • row – Row number

  • col – Column number

  • val – Value to set at position (row, col)

inline void set_row(Int row, const std::vector<T> &vals)

Set a matrix row at once.

This is a convenience method

Parameters:
  • row – Row number

  • vals – Values of the row. vals must have COLS values.

inline void set_row(Int row, const DenseVector<T, COLS> &vals)

Set a matrix row at once.

This is a convenience method

Parameters:
  • row – Row number

  • vals – Values of the row

inline void set_col(Int col, const DenseVector<T, ROWS> &vals)

Set a matrix column at once.

This is a convenience method

Parameters:
  • col – Column number

  • vals – Values of the column

inline void zero()

Set all matrix entries to zero, i.e. mat[i,j] = 0.

inline void set_values(const T &alpha)

Set alpha into all matrix entries, i.e.

mat[i, j] = alpha

Parameters:

alpha – Value to set into matrix entries

inline void scale(Real alpha)

Multiply all entries by a scalar value.

Parameters:

alpha – Value to multiple the matrix entries with

inline void add(const DenseMatrix<T, ROWS, COLS> &x)

Add matrix x to this matrix.

Parameters:

xMatrix to add

inline void add(const DenseMatrixSymm<T, ROWS> &x)

Add matrix x to this matrix.

Parameters:

xMatrix to add

inline void subtract(const DenseMatrix<T, ROWS, COLS> &x)

Subtract matrix x from this matrix.

Parameters:

xMatrix to subtract

inline void subtract(const DenseMatrixSymm<T, ROWS> &x)

Subtract matrix x from this matrix.

Parameters:

xMatrix to subtract

inline DenseVector<T, ROWS> mult(const DenseVector<T, COLS> &x) const

Multiply the matrix by a vector.

Vector size must be equal to the number of columns

Parameters:

xVector to multiply by

Returns:

Resulting vector

inline DenseMatrix<T, COLS, ROWS> transpose() const

Compute transpose.

Returns:

Transposed matrix

inline DenseVector<T, COLS> diagonal() const

Get diagonal of the matrix as a DenseVector.

Returns:

Matrix diagonal as a vector

inline const T &operator()(Int row, Int col) const

Get a value at position (row, col) for reading.

Parameters:
  • row – Row number

  • col – Col number

Returns:

Value at the position (row, col)

inline T &operator()(Int row, Int col)

Get a value at position (row, col) for writing.

Parameters:
  • row – Row number

  • col – Col number

Returns:

Value at position (row, col)

inline DenseMatrix<T, ROWS, COLS> operator+(const DenseMatrix<T, ROWS, COLS> &a) const

Add matrix a to this matrix and return the result.

Parameters:

aMatrix to add

Returns:

Resulting matrix

inline DenseMatrix<T, ROWS> operator+(const DenseMatrixSymm<T, ROWS> &a) const

Add matrix a to this matrix and return the result.

This matrix must be a square matrix

Parameters:

aMatrix to add

Returns:

Resulting matrix

inline DenseMatrix<T, ROWS, COLS> &operator+=(const DenseMatrix<T, ROWS, COLS> &a)

Add matrix to this matrix.

Parameters:

aMatrix to add

Returns:

Resulting matrix, i.e. this + a

inline DenseMatrix<T, ROWS, COLS> operator-(const DenseMatrix<T, ROWS, COLS> &a) const

Subtract matrix a from this matrix and return the result.

Parameters:

aMatrix to subtract

Returns:

Resulting matrix

inline DenseMatrix<T, ROWS> operator-(const DenseMatrixSymm<T, ROWS> &a) const

Subtract matrix a from this matrix and return the result.

This matrix must be a square matrix

Parameters:

aMatrix to subtract

Returns:

Resulting matrix

inline DenseMatrix<T, ROWS, COLS> operator*(Real alpha) const

Multiply this matrix with a scalar value.

Parameters:

alpha – Value to multiply with

Returns:

Resulting matrix

inline DenseVector<T, ROWS> operator*(const DenseVector<T, COLS> &rhs) const

Multiply this matrix with a vector.

Parameters:

rhsVector to multiply with

Returns:

Resulting vector

inline T *data()

Get access to the underlying data.

WARNING: Avoid using this API as much as you can

Returns:

Pointer to the underlying matrix entries

inline const T *data() const

Get access to the underlying data.

WARNING: Avoid using this API as much as you can

Returns:

Pointer to the underlying matrix entries

DynDenseMatrix

Warning

doxygenclass: Cannot find class “godzilla::DynDenseMatrix” in doxygen xml output for project “godzilla” from directory: /home/runner/work/godzilla/godzilla/build/docs/xml/