aest 0.1.0
Collection of C++ utility libraries
Loading...
Searching...
No Matches
Matrix.cppm File Reference
module aest.blas

Partition aest.blas:matrix: fixed-size vectors and matrices and their compile-time operations. More...

#include <array>
#include <concepts>
#include <cstddef>

Go to the source code of this file.

Typedefs

template<typename T, std::size_t Size>
using aest::blas::Vector = std::array<T, Size>
 A column vector of fixed size.
template<typename T, std::size_t Rows, std::size_t Columns>
using aest::blas::Matrix = std::array<Vector<T, Columns>, Rows>
 A matrix of fixed size, stored as an array of rows.

Functions

template<typename T>
constexpr T aest::blas::cofactor (const std::array< std::array< T, 3 >, 3 > &matrix, const std::size_t row, const std::size_t column)
 Cofactor of one element of a 3x3 matrix, sign included.
template<typename T, std::size_t Rows, std::size_t Columns>
constexpr Vector< T, Rows > aest::blas::multiply (const Matrix< T, Rows, Columns > &matrix, const Vector< T, Columns > &vector)
 Multiplies a matrix by a column vector.
template<typename T, std::size_t Rows, std::size_t Inner, std::size_t Columns>
constexpr Matrix< T, Rows, Columns > aest::blas::multiply (const Matrix< T, Rows, Inner > &lhs, const Matrix< T, Inner, Columns > &rhs)
 Multiplies two matrices.
template<typename T, std::size_t Rows, std::size_t Columns>
constexpr Matrix< T, Columns, Rows > aest::blas::transpose (const Matrix< T, Rows, Columns > &matrix)
 Swaps the rows and columns of a matrix.
template<typename T, std::size_t Size>
constexpr Matrix< T, Size, Size > aest::blas::diagonal (const Vector< T, Size > &vector)
 Builds a square matrix with a vector on its diagonal and 0 elsewhere.
template<typename T>
constexpr T aest::blas::determinant (const Matrix< T, 3, 3 > &matrix)
 Determinant of a 3x3 matrix, by cofactor expansion along the first row.
template<std::floating_point T>
constexpr Matrix< T, 3, 3 > aest::blas::inverse (const Matrix< T, 3, 3 > &matrix)
 Inverts a 3x3 matrix through its adjugate.

Detailed Description

Partition aest.blas:matrix: fixed-size vectors and matrices and their compile-time operations.

Author
Davide Pierotti

Definition in file Matrix.cppm.

Typedef Documentation

◆ Matrix

template<typename T, std::size_t Rows, std::size_t Columns>
using aest::blas::Matrix = std::array<Vector<T, Columns>, Rows>
export

A matrix of fixed size, stored as an array of rows.

Template Parameters
TThe element type
RowsThe number of rows
ColumnsThe number of columns

Definition at line 57 of file Matrix.cppm.

◆ Vector

template<typename T, std::size_t Size>
using aest::blas::Vector = std::array<T, Size>
export

A column vector of fixed size.

Template Parameters
TThe element type
SizeThe number of elements

Definition at line 48 of file Matrix.cppm.

Function Documentation

◆ cofactor()

template<typename T>
T aest::blas::cofactor ( const std::array< std::array< T, 3 >, 3 > & matrix,
const std::size_t row,
const std::size_t column )
constexpr

Cofactor of one element of a 3x3 matrix, sign included.

Template Parameters
TThe element type
Parameters
[in]matrixThe matrix, a Matrix<T, 3, 3>
[in]rowRow of the element
[in]columnColumn of the element
Returns
The determinant of the minor without row and column, with the sign of the element's position.

Definition at line 26 of file Matrix.cppm.

◆ determinant()

template<typename T>
T aest::blas::determinant ( const Matrix< T, 3, 3 > & matrix)
constexprexport

Determinant of a 3x3 matrix, by cofactor expansion along the first row.

Template Parameters
TThe element type
Parameters
[in]matrixThe matrix
Returns
The determinant of matrix.

Definition at line 142 of file Matrix.cppm.

◆ diagonal()

template<typename T, std::size_t Size>
Matrix< T, Size, Size > aest::blas::diagonal ( const Vector< T, Size > & vector)
constexprexport

Builds a square matrix with a vector on its diagonal and 0 elsewhere.

Template Parameters
TThe element type
SizeThe number of elements of vector, and of rows and columns
Parameters
[in]vectorThe diagonal
Returns
The matrix that scales each element of a vector by the matching element of vector.

Definition at line 128 of file Matrix.cppm.

◆ inverse()

template<std::floating_point T>
Matrix< T, 3, 3 > aest::blas::inverse ( const Matrix< T, 3, 3 > & matrix)
constexprexport

Inverts a 3x3 matrix through its adjugate.

Template Parameters
TThe element type, a floating-point type
Parameters
[in]matrixThe matrix to invert
Returns
The inverse of matrix.
Precondition
matrix is invertible: its determinant is not 0.

Definition at line 158 of file Matrix.cppm.

◆ multiply() [1/2]

template<typename T, std::size_t Rows, std::size_t Columns>
Vector< T, Rows > aest::blas::multiply ( const Matrix< T, Rows, Columns > & matrix,
const Vector< T, Columns > & vector )
constexprexport

Multiplies a matrix by a column vector.

Template Parameters
TThe element type
RowsThe number of rows of matrix and elements of the result
ColumnsThe number of columns of matrix and elements of vector
Parameters
[in]matrixThe matrix
[in]vectorThe column vector
Returns
The product matrix * vector.

Definition at line 69 of file Matrix.cppm.

◆ multiply() [2/2]

template<typename T, std::size_t Rows, std::size_t Inner, std::size_t Columns>
Matrix< T, Rows, Columns > aest::blas::multiply ( const Matrix< T, Rows, Inner > & lhs,
const Matrix< T, Inner, Columns > & rhs )
constexprexport

Multiplies two matrices.

Template Parameters
TThe element type
RowsThe number of rows of lhs and of the result
InnerThe number of columns of lhs and rows of rhs
ColumnsThe number of columns of rhs and of the result
Parameters
[in]lhsThe left-hand matrix
[in]rhsThe right-hand matrix
Returns
The product lhs * rhs, which applies rhs first when used on a vector.

Definition at line 90 of file Matrix.cppm.

◆ transpose()

template<typename T, std::size_t Rows, std::size_t Columns>
Matrix< T, Columns, Rows > aest::blas::transpose ( const Matrix< T, Rows, Columns > & matrix)
constexprexport

Swaps the rows and columns of a matrix.

Template Parameters
TThe element type
RowsThe number of rows of matrix
ColumnsThe number of columns of matrix
Parameters
[in]matrixThe matrix to transpose
Returns
The matrix whose rows are the columns of matrix.

Definition at line 110 of file Matrix.cppm.