SpatialMatrix

Spatial matrix with bounded maximum dimensions.

Defined in Rodin/Math/SpatialMatrix.h

template <
  class ScalarType>
class SpatialMatrix;
Template parameters
ScalarType The element type

A dynamic-size matrix with maximum dimensions bounded by RODIN_MAXIMAL_SPACE_DIMENSION. Used for geometric transformations, Jacobians, and other spatial operators to optimize memory allocation.

Typical uses:

  • Jacobian matrices: $ J = \frac{\partial \mathbf{f}}{\partial \mathbf{x}} $
  • Metric tensors
  • Local coordinate transformations

Public types

using Scalar = ScalarType
The element scalar type.
using Data = Eigen::Matrix3<ScalarType>
Underlying fixed-capacity Eigen storage type.

Public static variables

static std::uint8_t MaxSize constexpr
Maximum storable dimension (RODIN_MAXIMAL_SPACE_DIMENSION, fixed at 3).

Public static functions

static auto Identity(std::uint8_t rows, std::uint8_t cols) -> SpatialMatrix constexpr
Returns an identity matrix of the given dimensions.

Constructors, destructors, conversion operators

SpatialMatrix() constexpr noexcept
Constructs an empty (0-by-0) spatial matrix.
SpatialMatrix(std::uint8_t rows, std::uint8_t cols) constexpr
Constructs a zero-initialized spatial matrix of the given dimensions.
SpatialMatrix(const SpatialVector<Scalar>& vec) constexpr
Constructs a single-column matrix from a spatial vector.
SpatialMatrix(const SpatialMatrix& other) defaulted constexpr
Copy constructor.
SpatialMatrix(SpatialMatrix&& other) defaulted constexpr
Move constructor.
template<class EigenDerived>
SpatialMatrix(const Eigen::MatrixBase<EigenDerived>& other) constexpr
Constructs a spatial matrix from an Eigen matrix expression.

Public functions

auto operator=(const SpatialMatrix& other) -> SpatialMatrix& defaulted constexpr
Copy assignment operator.
auto operator=(SpatialMatrix&& other) -> SpatialMatrix& defaulted constexpr
Move assignment operator.
template<class EigenDerived>
auto operator=(const Eigen::ArrayBase<EigenDerived>& other) -> SpatialMatrix& constexpr
Assigns from an Eigen array expression, resizing to match.
template<class EigenDerived>
auto operator=(const Eigen::MatrixBase<EigenDerived>& other) -> SpatialMatrix& constexpr
Assigns from an Eigen matrix expression, resizing to match.
auto operator+=(const SpatialMatrix& other) -> SpatialMatrix& constexpr
Adds another spatial matrix componentwise in place.
auto rows() const -> std::uint8_t constexpr noexcept
Returns the number of rows.
auto cols() const -> std::uint8_t constexpr noexcept
Returns the number of columns.
void resize(std::uint8_t r, std::uint8_t c) constexpr
Sets the logical dimensions (each must not exceed MaxSize).
auto operator()(std::uint8_t i, std::uint8_t j) -> ScalarType& constexpr
Returns a reference to entry (i, j).
auto operator()(std::uint8_t i, std::uint8_t j) const -> const ScalarType& constexpr
Returns a const reference to entry (i, j).
void setZero() constexpr noexcept
Sets all entries to zero.
void setConstant(const ScalarType& value) constexpr noexcept
Sets all entries to the given value.
void setIdentity() constexpr noexcept
Sets this matrix to the identity.
auto squaredNorm() const -> Eigen::NumTraits<ScalarType>::Real constexpr noexcept
Returns the squared Frobenius norm.
auto norm() const -> Eigen::NumTraits<ScalarType>::Real constexpr noexcept
Returns the Frobenius norm.
template<class OtherScalar>
auto dot(const SpatialMatrix<OtherScalar>& other) const -> auto constexpr noexcept
Contracts active entries, conjugating the right operand.
template<class EigenDerived>
auto dot(const Eigen::MatrixBase<EigenDerived>& other) const -> auto constexpr noexcept
Contracts an Eigen matrix, conjugating the right operand.
auto transpose() const -> SpatialMatrix<ScalarType> constexpr noexcept
Returns the transpose.
auto conjugate() const -> SpatialMatrix<ScalarType> constexpr noexcept
Returns the elementwise complex conjugate.
auto adjoint() const -> SpatialMatrix<ScalarType> constexpr noexcept
Returns the conjugate transpose (adjoint).
auto trace() const -> ScalarType constexpr noexcept
Returns the trace (sum of the diagonal entries; requires a square matrix).
auto value() const -> ScalarType constexpr noexcept
Returns the (0, 0) entry (for 1-by-1 matrices used as scalars).
auto solve(const SpatialVector<ScalarType>& b) const -> SpatialVector<ScalarType> noexcept
Solves the linear system $ Ax = b $ .
auto determinant() const -> ScalarType constexpr noexcept
Returns the determinant (specialized for 1x1, 2x2 and 3x3).
auto inverse() const -> SpatialMatrix<ScalarType> constexpr noexcept
Returns the matrix inverse (specialized for 1x1, 2x2 and 3x3).
auto row(std::uint8_t i) const -> SpatialVector<Scalar> constexpr noexcept
Extracts the $ i $ -th row as a SpatialVector.
auto col(std::uint8_t j) const -> SpatialVector<Scalar> constexpr noexcept
Extracts the $ j $ -th column as a SpatialVector.
auto pseudoInverse() const -> SpatialMatrix constexpr noexcept
Computes the Moore-Penrose pseudo-inverse.
auto operator*=(Scalar s) -> SpatialMatrix& constexpr noexcept
Scales all elements by a scalar.
auto operator-() const -> SpatialMatrix constexpr noexcept
Returns the componentwise additive inverse of this matrix.
auto operator*=(const SpatialMatrix& rhs) -> SpatialMatrix& constexpr noexcept
In-place matrix multiplication.
auto getData() -> auto& constexpr noexcept
Returns a reference to the underlying Eigen storage.
auto getData() const -> const auto& constexpr noexcept
Returns a const reference to the underlying Eigen storage.

Function documentation

static SpatialMatrix Identity(std::uint8_t rows, std::uint8_t cols) constexpr

Returns an identity matrix of the given dimensions.

Parameters
rows Number of rows.
cols Number of columns.
Returns An identity matrix of the given dimensions.

SpatialMatrix(std::uint8_t rows, std::uint8_t cols) constexpr

Constructs a zero-initialized spatial matrix of the given dimensions.

Parameters
rows Number of rows.
cols Number of columns.

SpatialMatrix(const SpatialVector<Scalar>& vec) constexpr

Constructs a single-column matrix from a spatial vector.

Parameters
vec Vector used to initialize the matrix.

SpatialMatrix(const SpatialMatrix& other) defaulted constexpr

Copy constructor.

Parameters
other Object to copy from.

SpatialMatrix(SpatialMatrix&& other) defaulted constexpr

Move constructor.

Parameters
other Object to move from.

template<class ScalarType> template<class EigenDerived>
SpatialMatrix(const Eigen::MatrixBase<EigenDerived>& other) constexpr

Constructs a spatial matrix from an Eigen matrix expression.

Parameters
other Object to copy from.

SpatialMatrix& operator=(const SpatialMatrix& other) defaulted constexpr

Copy assignment operator.

Parameters
other Object to copy from.
Returns Reference to this object after the operation.

SpatialMatrix& operator=(SpatialMatrix&& other) defaulted constexpr

Move assignment operator.

Parameters
other Object to move from.
Returns Reference to this object after the operation.

template<class ScalarType> template<class EigenDerived>
SpatialMatrix& operator=(const Eigen::ArrayBase<EigenDerived>& other) constexpr

Assigns from an Eigen array expression, resizing to match.

Parameters
other Object to copy from.
Returns Reference to this object after the operation.

The expression is copied into fixed-capacity storage before the active entries and shape are replaced, including when it references this matrix.

template<class ScalarType> template<class EigenDerived>
SpatialMatrix& operator=(const Eigen::MatrixBase<EigenDerived>& other) constexpr

Assigns from an Eigen matrix expression, resizing to match.

Parameters
other Object to copy from.
Returns Reference to this object after the operation.

The expression is copied into fixed-capacity storage before the active entries and shape are replaced, including when it references this matrix.

SpatialMatrix& operator+=(const SpatialMatrix& other) constexpr

Adds another spatial matrix componentwise in place.

Parameters
other Other operand.
Returns Reference to this object after the operation.

std::uint8_t rows() const constexpr noexcept

Returns the number of rows.

Returns The number of rows.

std::uint8_t cols() const constexpr noexcept

Returns the number of columns.

Returns The number of columns.

void resize(std::uint8_t r, std::uint8_t c) constexpr

Sets the logical dimensions (each must not exceed MaxSize).

Parameters
r Number of rows.
c Number of columns.

ScalarType& operator()(std::uint8_t i, std::uint8_t j) constexpr

Returns a reference to entry (i, j).

Parameters
i Index of the requested entry.
j Index of the second coordinate.
Returns Reference to the entry at the supplied indices.

const ScalarType& operator()(std::uint8_t i, std::uint8_t j) const constexpr

Returns a const reference to entry (i, j).

Parameters
i Index of the requested entry.
j Index of the second coordinate.
Returns Reference to the entry at the supplied indices.

void setConstant(const ScalarType& value) constexpr noexcept

Sets all entries to the given value.

Parameters
value Value to store or assign.

Eigen::NumTraits<ScalarType>::Real squaredNorm() const constexpr noexcept

Returns the squared Frobenius norm.

Returns The squared Frobenius norm.

Eigen::NumTraits<ScalarType>::Real norm() const constexpr noexcept

Returns the Frobenius norm.

Returns The Frobenius norm.

template<class ScalarType> template<class OtherScalar>
auto dot(const SpatialMatrix<OtherScalar>& other) const constexpr noexcept

Contracts active entries, conjugating the right operand.

Template parameters
OtherScalar Right operand's scalar type.
Parameters
other Right operand.
Returns Right-conjugating Frobenius contraction with scalar promotion.

Computes $\sum_{ij}A_{ij}\overline{B_{ij}}$ , as does Math::dot.

template<class ScalarType> template<class EigenDerived>
auto dot(const Eigen::MatrixBase<EigenDerived>& other) const constexpr noexcept

Contracts an Eigen matrix, conjugating the right operand.

Template parameters
EigenDerived Right Eigen matrix expression type.
Parameters
other Right operand.
Returns Right-conjugating Frobenius contraction with scalar promotion.

SpatialMatrix<ScalarType> transpose() const constexpr noexcept

Returns the transpose.

Returns The transpose.

SpatialMatrix<ScalarType> conjugate() const constexpr noexcept

Returns the elementwise complex conjugate.

Returns The elementwise complex conjugate.

SpatialMatrix<ScalarType> adjoint() const constexpr noexcept

Returns the conjugate transpose (adjoint).

Returns The conjugate transpose (adjoint).

ScalarType trace() const constexpr noexcept

Returns the trace (sum of the diagonal entries; requires a square matrix).

Returns The trace (sum of the diagonal entries; requires a square matrix).

ScalarType value() const constexpr noexcept

Returns the (0, 0) entry (for 1-by-1 matrices used as scalars).

Returns The (0, 0) entry (for 1-by-1 matrices used as scalars).

SpatialVector<ScalarType> solve(const SpatialVector<ScalarType>& b) const noexcept

Solves the linear system $ Ax = b $ .

Parameters
b in Right-hand side vector
Returns Solution vector $ x = A^{-1} b $

Uses Cramer's rule for small systems (1×1, 2×2, 3×3). The matrix must be square and non-singular.

ScalarType determinant() const constexpr noexcept

Returns the determinant (specialized for 1x1, 2x2 and 3x3).

Returns The determinant (specialized for 1x1, 2x2 and 3x3).

Small matrices use specialized formulas; larger matrices use a generic fallback.

SpatialMatrix<ScalarType> inverse() const constexpr noexcept

Returns the matrix inverse (specialized for 1x1, 2x2 and 3x3).

Returns The matrix inverse (specialized for 1x1, 2x2 and 3x3).

Small matrices use specialized formulas; larger matrices use a generic fallback. The returned matrix has the same runtime dimensions.

SpatialVector<Scalar> row(std::uint8_t i) const constexpr noexcept

Extracts the $ i $ -th row as a SpatialVector.

Parameters
i in Row index (0-based)
Returns Row vector of length cols()

SpatialVector<Scalar> col(std::uint8_t j) const constexpr noexcept

Extracts the $ j $ -th column as a SpatialVector.

Parameters
j in Column index (0-based)
Returns Column vector of length rows()

SpatialMatrix pseudoInverse() const constexpr noexcept

Computes the Moore-Penrose pseudo-inverse.

Returns The pseudo-inverse $ A^+ $

For full column rank matrices ( $ m \geq n $ ), computes $ A^+ = (A^* A)^{-1} A^* $ . For full row rank matrices ( $ m < n $ ), computes $ A^+ = A^* (A A^*)^{-1} $ .

The matrices are assumed to have full rank. Here $ A^* $ denotes the conjugate transpose, including for complex scalar fields.

SpatialMatrix& operator*=(Scalar s) constexpr noexcept

Scales all elements by a scalar.

Parameters
s in Scalar multiplier
Returns Reference to $ *this $ after scaling

SpatialMatrix operator-() const constexpr noexcept

Returns the componentwise additive inverse of this matrix.

Returns Difference of the operands, or the negated operand for the unary overload.

SpatialMatrix& operator*=(const SpatialMatrix& rhs) constexpr noexcept

In-place matrix multiplication.

Parameters
rhs in Right-hand side matrix
Returns Reference to $ *this $ after multiplication

Replaces $ *this $ with $ (*this) \cdot rhs $ . Requires cols() == rhs.rows(). Handles self-multiplication safely.

auto& getData() constexpr noexcept

Returns a reference to the underlying Eigen storage.

Returns A reference to the underlying Eigen storage.

const auto& getData() const constexpr noexcept

Returns a const reference to the underlying Eigen storage.

Returns A const reference to the underlying Eigen storage.