akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
linalg::Matrix< T, Rows, Cols > Struct Template Reference

Owning, fixed-size, row-major matrix container over a scalar field. More...

#include <matrix.hpp>

Public Member Functions

constexpr Matrix ()=default
 Construct a value-initialized matrix.
 
template<typename... RowVectors>
requires (sizeof...(RowVectors) == Rows && Rows > 0 && (std::same_as<remove_cvref_t<RowVectors>, Vector<T, Cols>> && ...))
constexpr Matrix (RowVectors &&... rows)
 Construct by copying one fixed-size vector per matrix row.
 
constexpr const T & operator() (std::size_t row, std::size_t col) const
 Read an element at a zero-based row and column.
 
constexpr T & operator() (std::size_t row, std::size_t col)
 Read or modify an element at a zero-based row and column.
 
constexpr auto row (std::size_t index) const
 Copy one matrix row into a fixed-size vector.
 
constexpr auto begin ()
 Iterator to the first element in flattened row-major order.
 
constexpr auto begin () const
 Const iterator to the first element in row-major order.
 
constexpr auto end ()
 Iterator one past the final flattened element.
 
constexpr auto end () const
 Const iterator one past the final flattened element.
 
constexpr auto view ()
 Mutable, fixed-extent view of contiguous row-major storage.
 
constexpr auto view () const
 Const, fixed-extent view of contiguous row-major storage.
 
constexpr auto size () const
 Number of stored scalar elements (Rows * Cols).
 
constexpr bool operator== (const Matrix &) const =default
 Compare shape-compatible matrices element by element.
 

Detailed Description

template<Field T, std::size_t Rows, std::size_t Cols>
struct linalg::Matrix< T, Rows, Cols >

Owning, fixed-size, row-major matrix container over a scalar field.

Matrix stores exactly Rows * Cols elements inline. Its dimensions are part of the type, so construction, indexing, iteration, and conversion can all be used during constant evaluation. Default construction value-initializes the backing storage; arithmetic field elements therefore begin at zero.

This type supplies storage and shape, not a coordinate-space policy or a specialized matrix category. Algebraic operations are defined separately, while types such as symmetric matrices and their coordinate maps layer additional meaning over a matrix representation.

Elements use two-dimensional indexing: matrix(row, col). Both indices are zero-based and checked with AK_ASSERT. Iteration and view() expose the flattened row-major order [A(0,0), ..., A(0,Cols-1), A(1,0), ...].

Template Parameters
TReal or complex field element type.
RowsCompile-time row count.
ColsCompile-time column count.

Definition at line 44 of file matrix.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr linalg::Matrix< T, Rows, Cols >::Matrix ( )
constexprdefault

Construct a value-initialized matrix.

◆ Matrix() [2/2]

template<Field T, std::size_t Rows, std::size_t Cols>
template<typename... RowVectors>
requires (sizeof...(RowVectors) == Rows && Rows > 0 && (std::same_as<remove_cvref_t<RowVectors>, Vector<T, Cols>> && ...))
constexpr linalg::Matrix< T, Rows, Cols >::Matrix ( RowVectors &&...  rows)
inlineexplicitconstexpr

Construct by copying one fixed-size vector per matrix row.

The number of arguments must equal Rows, and every argument must be a Vector<T, Cols> after cv/ref normalization. This constructor also supports class template argument deduction through the guide below.

Parameters
rowsRow vectors in increasing row-index order.

Definition at line 60 of file matrix.hpp.

References linalg::mat_rows_v, and linalg::Matrix< T, Rows, Cols >::row().

Member Function Documentation

◆ begin() [1/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::begin ( )
inlineconstexpr

Iterator to the first element in flattened row-major order.

Definition at line 105 of file matrix.hpp.

◆ begin() [2/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::begin ( ) const
inlineconstexpr

Const iterator to the first element in row-major order.

Definition at line 107 of file matrix.hpp.

◆ end() [1/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::end ( )
inlineconstexpr

Iterator one past the final flattened element.

Definition at line 109 of file matrix.hpp.

◆ end() [2/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::end ( ) const
inlineconstexpr

Const iterator one past the final flattened element.

Definition at line 111 of file matrix.hpp.

◆ operator()() [1/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr T & linalg::Matrix< T, Rows, Cols >::operator() ( std::size_t  row,
std::size_t  col 
)
inlineconstexpr

Read or modify an element at a zero-based row and column.

Returns
Mutable reference to the stored element.

Definition at line 84 of file matrix.hpp.

References AK_ASSERT, linalg::mat_rows_v, and linalg::Matrix< T, Rows, Cols >::row().

◆ operator()() [2/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr const T & linalg::Matrix< T, Rows, Cols >::operator() ( std::size_t  row,
std::size_t  col 
) const
inlineconstexpr

Read an element at a zero-based row and column.

Returns
Const reference to the stored element.

Definition at line 74 of file matrix.hpp.

References AK_ASSERT, linalg::mat_rows_v, and linalg::Matrix< T, Rows, Cols >::row().

◆ operator==()

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr bool linalg::Matrix< T, Rows, Cols >::operator== ( const Matrix< T, Rows, Cols > &  ) const
constexprdefault

Compare shape-compatible matrices element by element.

◆ row()

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::row ( std::size_t  index) const
inlineconstexpr

Copy one matrix row into a fixed-size vector.

Returning a value deliberately keeps Matrix storage encapsulated. Use view() when direct access to the contiguous flattened storage is needed.

Definition at line 96 of file matrix.hpp.

References AK_ASSERT, and linalg::mat_rows_v.

Referenced by linalg::Matrix< T, Rows, Cols >::Matrix(), linalg::Matrix< T, Rows, Cols >::operator()(), and linalg::Matrix< T, Rows, Cols >::operator()().

◆ size()

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::size ( ) const
inlineconstexpr

Number of stored scalar elements (Rows * Cols).

Definition at line 119 of file matrix.hpp.

◆ view() [1/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::view ( )
inlineconstexpr

Mutable, fixed-extent view of contiguous row-major storage.

Definition at line 113 of file matrix.hpp.

◆ view() [2/2]

template<Field T, std::size_t Rows, std::size_t Cols>
constexpr auto linalg::Matrix< T, Rows, Cols >::view ( ) const
inlineconstexpr

Const, fixed-extent view of contiguous row-major storage.

Definition at line 115 of file matrix.hpp.


The documentation for this struct was generated from the following file: