NumericAL
A header-only C++20 lexer built on REAL
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
numerical::matrix< T > Class Template Reference

A dense, row-major matrix of T with value semantics. More...

#include <matrix.hpp>

Public Member Functions

 matrix ()=default
 An empty matrix (0×0).
 
 matrix (std::initializer_list< std::initializer_list< T > > rows)
 From a braced list of rows; every row must have the same length.
 
 matrix (std::size_t rows, std::size_t cols, buffer< T > elements)
 From dimensions and a flat row-major buffer.
 
 matrix (std::size_t rows, std::size_t cols, const std::vector< T > &elements)
 From dimensions and a flat row-major std::vector, copied into the storage (a buffer moves in instead).
 
 matrix (std::size_t rows, std::size_t cols, std::initializer_list< T > elements)
 From dimensions and a braced list of the elements, row-major.
 
std::size_t rows () const noexcept
 The number of rows.
 
std::size_t cols () const noexcept
 The number of columns.
 
const T & operator() (std::size_t row, std::size_t col) const
 The element at (row, col).
 
bool operator== (const matrix &other) const
 Exact equality (same shape and equal elements).
 
buffer< T >::const_iterator begin () const noexcept
 Const iterator to the first element (row-major).
 
buffer< T >::const_iterator end () const noexcept
 Const iterator past the last element.
 
buffer< T > elements () &&
 The elements, row-major, handed over by a matrix about to expire, which is left 0 × 0: a large result moves on without a copy (each copy of a fresh buffer faults its pages in one by one).
 

Private Attributes

std::size_t rows_ {0}
 The number of rows.
 
std::size_t cols_ {0}
 The number of columns.
 
buffer< T > data_
 The elements, row-major.
 

Detailed Description

template<typename T>
class numerical::matrix< T >

A dense, row-major matrix of T with value semantics.

Template Parameters
TThe scalar element type.

Definition at line 34 of file matrix.hpp.

Constructor & Destructor Documentation

◆ matrix() [1/5]

template<typename T >
numerical::matrix< T >::matrix ( )
default

An empty matrix (0×0).

◆ matrix() [2/5]

template<typename T >
numerical::matrix< T >::matrix ( std::initializer_list< std::initializer_list< T > >  rows)
inline

From a braced list of rows; every row must have the same length.

Parameters
[in]rowsThe rows, each a braced list of elements.
Exceptions
dimension_errorIf the rows have unequal lengths.

Definition at line 46 of file matrix.hpp.

◆ matrix() [3/5]

template<typename T >
numerical::matrix< T >::matrix ( std::size_t  rows,
std::size_t  cols,
buffer< T >  elements 
)
inlineexplicit

From dimensions and a flat row-major buffer.

Parameters
[in]rows,colsThe dimensions.
[in]elementsThe rows*cols elements, row-major (moved in).
Exceptions
dimension_errorIf elements.size() is not rows*cols.

Definition at line 68 of file matrix.hpp.

◆ matrix() [4/5]

template<typename T >
numerical::matrix< T >::matrix ( std::size_t  rows,
std::size_t  cols,
const std::vector< T > &  elements 
)
inlineexplicit

From dimensions and a flat row-major std::vector, copied into the storage (a buffer moves in instead).

Parameters
[in]rows,colsThe dimensions.
[in]elementsThe rows*cols elements, row-major.
Exceptions
dimension_errorIf elements.size() is not rows*cols.

Definition at line 84 of file matrix.hpp.

◆ matrix() [5/5]

template<typename T >
numerical::matrix< T >::matrix ( std::size_t  rows,
std::size_t  cols,
std::initializer_list< T >  elements 
)
inlineexplicit

From dimensions and a braced list of the elements, row-major.

Parameters
[in]rows,colsThe dimensions.
[in]elementsThe rows*cols elements, row-major.
Exceptions
dimension_errorIf the list's length is not rows*cols.

Definition at line 98 of file matrix.hpp.

Member Function Documentation

◆ begin()

template<typename T >
buffer< T >::const_iterator numerical::matrix< T >::begin ( ) const
inlinenoexcept

Const iterator to the first element (row-major).

Definition at line 132 of file matrix.hpp.

◆ cols()

template<typename T >
std::size_t numerical::matrix< T >::cols ( ) const
inlinenoexcept

The number of columns.

Definition at line 113 of file matrix.hpp.

◆ elements()

template<typename T >
buffer< T > numerical::matrix< T >::elements ( ) &&
inline

The elements, row-major, handed over by a matrix about to expire, which is left 0 × 0: a large result moves on without a copy (each copy of a fresh buffer faults its pages in one by one).

Definition at line 145 of file matrix.hpp.

◆ end()

template<typename T >
buffer< T >::const_iterator numerical::matrix< T >::end ( ) const
inlinenoexcept

Const iterator past the last element.

Definition at line 138 of file matrix.hpp.

◆ operator()()

template<typename T >
const T & numerical::matrix< T >::operator() ( std::size_t  row,
std::size_t  col 
) const
inline

The element at (row, col).

Precondition
In bounds.

Definition at line 119 of file matrix.hpp.

◆ operator==()

template<typename T >
bool numerical::matrix< T >::operator== ( const matrix< T > &  other) const
inline

Exact equality (same shape and equal elements).

Definition at line 126 of file matrix.hpp.

◆ rows()

template<typename T >
std::size_t numerical::matrix< T >::rows ( ) const
inlinenoexcept

The number of rows.

Definition at line 107 of file matrix.hpp.

Member Data Documentation

◆ cols_

template<typename T >
std::size_t numerical::matrix< T >::cols_ {0}
private

The number of columns.

Definition at line 155 of file matrix.hpp.

◆ data_

template<typename T >
buffer<T> numerical::matrix< T >::data_
private

The elements, row-major.

Definition at line 156 of file matrix.hpp.

◆ rows_

template<typename T >
std::size_t numerical::matrix< T >::rows_ {0}
private

The number of rows.

Definition at line 154 of file matrix.hpp.


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