pbpt
|
A template class for RxC dimensional mathematical matrices. More...
#include <matrix.hpp>
Public Types | |
template<int ViewR, int ViewC> | |
using | MatView = MatrixView<T, R, C, ViewR, ViewC> |
Provides a view into a sub-region of the matrix. | |
using | RowView = VectorView<T, C> |
using | ColView = VectorView<T, R> |
Public Member Functions | |
constexpr | Matrix () noexcept=default |
Default constructor. Initializes a zero matrix. | |
template<typename... Vecs> requires (sizeof...(Vecs) == C && (std::is_same_v<Vector<T, R>, std::remove_cvref_t<Vecs>> && ...)) | |
constexpr | Matrix (Vecs &&... col_vecs) noexcept |
Constructs a matrix from a list of col vectors. | |
template<std::convertible_to< T >... Vals> requires (sizeof...(Vals) == R * C && (std::is_arithmetic_v<std::remove_cvref_t<Vals>> && ...)) | |
constexpr | Matrix (Vals &&... vals) noexcept |
Constructs a matrix from a list of values. | |
constexpr const T & | at (int r, int c) const |
Provides const access to matrix components by row and column. | |
constexpr RowView | operator[] (int r) |
Returns a non-owning, mutable view of a row. | |
constexpr const RowView | operator[] (int r) const |
Returns a non-owning, read-only view of a row. | |
constexpr RowView | row (int r) |
Returns a non-owning, mutable view of a row. | |
constexpr const RowView | row (int r) const |
Returns a non-owning, read-only view of a row. | |
constexpr ColView | col (int c) |
Returns a non-owning, mutable view of a column. | |
constexpr const ColView | col (int c) const |
Returns a non-owning, read-only view of a column. | |
constexpr int | row_dims () const noexcept |
Returns the number of rows. | |
constexpr int | col_dims () const noexcept |
Returns the number of columns. | |
const T * | data () const noexcept |
Returns a pointer to the underlying contiguous data array. | |
T * | data () noexcept |
Returns a pointer to the underlying contiguous data array. | |
constexpr bool | operator== (const Matrix &rhs) const noexcept |
Compares two matrices for equality. | |
constexpr bool | operator!= (const Matrix &rhs) const noexcept |
Compares two matrices for inequality. | |
constexpr Matrix & | operator+= (const Matrix &rhs) noexcept |
Adds the elements of another matrix to this matrix. | |
constexpr Matrix & | operator-= (const Matrix &rhs) noexcept |
Subtracts the elements of another matrix from this matrix. | |
constexpr Matrix & | operator*= (T scalar) noexcept |
Multiplies this matrix by a scalar. | |
constexpr Matrix< T, C, R > | transposed () const noexcept |
Computes the transpose of this matrix. | |
constexpr Matrix< T, C, R > & | transpose () noexcept |
Computes the transpose of this matrix. | |
constexpr T | determinant () const |
Computes the determinant of the matrix. | |
constexpr Matrix | inversed () const |
Computes the inverse of the matrix. | |
constexpr Matrix & | inverse () |
Computes the inverse of the matrix. | |
template<int ViewR, int ViewC> | |
constexpr Matrix::MatView< ViewR, ViewC > | view (int row_start, int col_start) |
Creates a mutable, non-owning view into a sub-region of this matrix. | |
template<int ViewR, int ViewC> | |
constexpr const Matrix::MatView< ViewR, ViewC > | view (int row_start, int col_start) const |
Creates a non-owning, read-only view into a sub-region of this const matrix. | |
constexpr auto | submatrix (int row_to_remove, int col_to_remove) const |
Creates a submatrix by removing a specified row and column. | |
constexpr Matrix | operator+ (const Matrix &rhs) const noexcept |
Matrix addition. | |
constexpr Matrix | operator- (const Matrix &rhs) const noexcept |
Matrix subtraction. | |
template<std::convertible_to< T > U> | |
constexpr Matrix | operator* (U scalar) const noexcept |
Matrix multiplication by a scalar. | |
constexpr Vector< T, R > | operator* (const Vector< T, R > &rhs) const noexcept |
Matrix-Vector multiplication. | |
template<int M> | |
constexpr Matrix< T, R, M > | operator* (const Matrix< T, C, M > &rhs) const noexcept |
Matrix-Matrix multiplication. | |
constexpr bool | is_zero () const |
Checks if the matrix is zero. | |
constexpr bool | is_identity () const |
Checks if the matrix is identity. | |
constexpr bool | has_nan () const |
Checks if the matrix has NaN values. |
Static Public Member Functions | |
static constexpr Matrix | zeros () noexcept |
Creates a matrix with all components set to zero. | |
static constexpr Matrix | identity () noexcept |
Creates an identity matrix. |
Friends | |
template<std::convertible_to< T > U> | |
constexpr Matrix | operator* (U scalar, const Matrix< T, R, C > &mat) noexcept |
Matrix multiplication by a scalar. | |
std::ostream & | operator<< (std::ostream &os, const Matrix< T, R, C > &mat) |
Matrix stream output. |
A template class for RxC dimensional mathematical matrices.
This class provides a generic, fixed-size matrix implementation using row-major memory layout. It's designed for high performance and flexibility, with extensive use of constexpr for compile-time computations.
T | The underlying floating-point type. |
R | The number of rows. |
C | The number of columns. |
using pbpt::math::Matrix< T, R, C >::MatView = MatrixView<T, R, C, ViewR, ViewC> |
Provides a view into a sub-region of the matrix.
R1 | The number of rows in the view. |
C1 | The number of columns in the view. |
r | The starting row index of the view. |
c | The starting column index of the view. |
|
inlineexplicitconstexprnoexcept |
Constructs a matrix from a list of col vectors.
The number of vectors must match the number of columns (C). Each vector's dimension must match the number of rows (R). The requires clause ensures this constructor is only enabled for Vector types.
col_vecs | A parameter pack of column vectors. |
|
inlineconstexprnoexcept |
Constructs a matrix from a list of values.
The number of values must match the number of elements (R * C).
Vals | The parameter pack of values. |
|
inlineconstexpr |
Provides const access to matrix components by row and column.
r | The zero-based row index. |
c | The zero-based column index. |
std::out_of_range | If index is out of bounds at runtime. |
|
inlinenoexcept |
Returns a pointer to the underlying contiguous data array.
Useful for interoperability with graphics APIs like OpenGL. The data is in row-major order.
|
inlinenoexcept |
Returns a pointer to the underlying contiguous data array.
Useful for interoperability with graphics APIs like OpenGL. The data is in row-major order.
|
inlineconstexpr |
Computes the determinant of the matrix.
|
inlineconstexpr |
Checks if the matrix has NaN values.
|
inlinestaticconstexprnoexcept |
Creates an identity matrix.
|
inlineconstexpr |
Computes the inverse of the matrix.
std::runtime_error | if the matrix is singular (determinant is zero). |
|
inlineconstexpr |
Computes the inverse of the matrix.
std::runtime_error | if the matrix is singular (determinant is zero). |
|
inlineconstexpr |
Checks if the matrix is identity.
|
inlineconstexpr |
Checks if the matrix is zero.
|
inlineconstexprnoexcept |
Compares two matrices for inequality.
rhs | The matrix to compare with. |
|
inlineconstexprnoexcept |
Matrix-Matrix multiplication.
The number of columns in the left matrix must equal the number of rows in the right matrix.
|
inlineconstexprnoexcept |
Matrix multiplication by a scalar.
Multiplies each element of the matrix by the scalar.
|
inlineconstexprnoexcept |
Multiplies this matrix by a scalar.
scalar | The scalar to multiply by. |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Adds the elements of another matrix to this matrix.
rhs | The matrix to add. |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Subtracts the elements of another matrix from this matrix.
rhs | The matrix to subtract. |
|
inlineconstexprnoexcept |
Compares two matrices for equality.
rhs | The matrix to compare with. |
|
inlineconstexpr |
Creates a submatrix by removing a specified row and column.
|
inlineconstexprnoexcept |
Computes the transpose of this matrix.
|
inlineconstexprnoexcept |
Computes the transpose of this matrix.
|
inlineconstexpr |
Creates a mutable, non-owning view into a sub-region of this matrix.
NewR | The number of rows in the view. |
NewC | The number of columns in the view. |
row_start | The starting row index for the view. |
col_start | The starting column index for the view. |
|
inlineconstexpr |
Creates a non-owning, read-only view into a sub-region of this const matrix.
ViewR | The number of rows in the view. |
ViewC | The number of columns in the view. |
row_start | The starting row index for the view. |
col_start | The starting column index for the view. |
|
friend |
Matrix multiplication by a scalar.
Multiplies each element of the matrix by the scalar.
|
friend |
Matrix stream output.
T | The matrix element type. |
R | The number of rows in the matrix. |
C | The number of columns in the matrix. |
os | The output stream. |
mat | The matrix to output. |