cortexlib
v0.2.0
|
matrix - Two Dimensional Array More...
#include <matrix.hxx>
Public Types | |
using | value_type = T |
using | size_type = std::size_t |
using | difference_type = std::ptrdiff_t |
using | allocator_type = Alloc |
using | alloc_traits = typename std::allocator_traits< Alloc > |
using | reference = T & |
using | const_reference = const T & |
using | pointer = typename alloc_traits::pointer |
using | const_pointer = typename alloc_traits::const_pointer |
using | iterator = cxl::normal_iterator< pointer, matrix > |
using | const_iterator = cxl::normal_iterator< const_pointer, matrix > |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Public Member Functions | |
constexpr | matrix () noexcept |
Default Constructor. More... | |
constexpr | matrix (const allocator_type &alloc) noexcept |
Allocator Constructor. More... | |
constexpr | matrix (size_type num_rows, size_type num_columns, const allocator_type &alloc=allocator_type{}) |
Default Size Constructor. More... | |
constexpr | matrix (size_type num_rows, size_type num_columns, const_reference fill_value, const allocator_type &alloc=allocator_type()) |
Explicit Value and Size Constructor. More... | |
constexpr | matrix (const matrix &other) |
Copy Constructor. More... | |
constexpr | matrix (const matrix &other, const allocator_type &alloc) |
Copy Constructor with Alternative Allocator. More... | |
constexpr | matrix (matrix &&other) noexcept |
Move Constructor. More... | |
constexpr | matrix (matrix &&other, const allocator_type &alloc) noexcept |
Move Constructor with Alternative Allocator. More... | |
constexpr | matrix (std::initializer_list< std::initializer_list< value_type >> list, [[maybe_unused]] const allocator_type &alloc=allocator_type{}) |
Initialiser List Constructor. More... | |
constexpr | matrix (const std::tuple< size_type, size_type > &dimensions, [[maybe_unused]] const allocator_type &alloc=allocator_type{}) |
Dimension Constructor. More... | |
constexpr auto | operator= (const matrix &other) -> matrix & |
Copy Assignment. More... | |
constexpr auto | operator= (matrix &&other) noexcept -> matrix & |
Move Assignment. More... | |
constexpr auto | operator= (std::initializer_list< std::initializer_list< value_type >> list) -> matrix & |
Initialiser List Assignment. More... | |
~matrix () | |
Destructor. More... | |
constexpr auto | assign (std::initializer_list< std::initializer_list< value_type >> list) -> void |
Initialiser List Assign. More... | |
constexpr auto | resize (size_type new_rows, size_type new_columns) -> void |
Resizes the matrix memory. More... | |
constexpr auto | resize (size_type new_rows, size_type new_columns, const_reference fill_value) -> void |
Resizes Matrices memory. More... | |
constexpr auto | erase (const_iterator position) -> iterator |
Erases element indicated by position. More... | |
constexpr auto | erase (const_iterator first, const_iterator last) -> iterator |
Erases elements between first and last. More... | |
constexpr auto | clear () -> void |
Clears the matrix elements. More... | |
constexpr auto | reshape (size_type new_rows, size_type new_columns) -> void |
Reshape current matrix elements to new dimensions. More... | |
void | swap (matrix &other) noexcept |
Swaps two Matrices of the same type. More... | |
constexpr auto | get_allocator () const noexcept -> allocator_type |
Get Allocator. More... | |
constexpr auto | size () const noexcept -> size_type |
matrix Size More... | |
constexpr auto | num_rows () const noexcept -> size_type |
Number of rows. More... | |
constexpr auto | num_columns () const noexcept -> size_type |
Number of Columns. More... | |
constexpr auto | max_size () const noexcept -> size_type |
Max matrix Size. More... | |
constexpr auto | shape () const noexcept -> std::tuple< size_type, size_type > |
Dimensions. More... | |
constexpr auto | is_square () const noexcept -> bool |
Is Square Predicate. More... | |
constexpr auto | empty () const noexcept -> bool |
Empty. More... | |
constexpr auto | data () noexcept -> pointer |
Data. More... | |
constexpr auto | data () const noexcept -> const_pointer |
Data. More... | |
constexpr auto | at (size_type row, size_type column) -> reference |
Point based element access. More... | |
constexpr auto | at (size_type row, size_type column) const -> const_reference |
Point based element access. More... | |
constexpr auto | operator() (size_type row, size_type column) -> reference |
Point based element access operator. More... | |
constexpr auto | operator() (size_type row, size_type column) const -> const_reference |
Point based element access operator. More... | |
constexpr auto | front () noexcept -> reference |
Front. More... | |
constexpr auto | front () const noexcept -> const_reference |
Front. More... | |
constexpr auto | back () noexcept -> reference |
Back. More... | |
constexpr auto | back () const noexcept -> const_reference |
Back. More... | |
constexpr auto | begin () noexcept -> iterator |
Begin Iterator. More... | |
constexpr auto | begin () const noexcept -> const_iterator |
Begin Iterator (const) More... | |
constexpr auto | cbegin () const noexcept -> const_iterator |
Constant Begin Iterator. More... | |
constexpr auto | rbegin () noexcept -> reverse_iterator |
Reverse Begin Iterator. More... | |
constexpr auto | rbegin () const noexcept -> const_reverse_iterator |
Reverse Begin Iterator (const) More... | |
constexpr auto | crbegin () const noexcept -> const_reverse_iterator |
Constant Reverse Begin Iterator. More... | |
constexpr auto | end () noexcept -> iterator |
End Iterator. More... | |
constexpr auto | end () const noexcept -> const_iterator |
End Iterator (const) More... | |
constexpr auto | cend () const noexcept -> const_iterator |
Constant End Iterator. More... | |
constexpr auto | rend () noexcept -> reverse_iterator |
Reverse End Iterator. More... | |
constexpr auto | rend () const noexcept -> const_reverse_iterator |
Reverse End Iterator (const) More... | |
constexpr auto | crend () const noexcept -> const_reverse_iterator |
Constant Reverse End Iterator. More... | |
template<std::copy_constructible F> | |
constexpr auto | map (F func) const -> matrix< std::invoke_result_t< F, value_type >> |
matrix Transpose More... | |
template<std::ranges::input_range Rng, std::copy_constructible F> | |
constexpr auto | map (Rng &&rng, F func) const -> matrix< std::invoke_result_t< F, value_type, typename std::remove_cvref_t< decltype(*std::ranges::begin(rng))>>> |
matrix map with range More... | |
template<std::input_iterator It, std::sentinel_for< It > Sn, std::copy_constructible Fn> | |
constexpr auto | map (It first, Sn last, Fn func) const -> matrix< std::invoke_result_t< Fn, value_type, typename std::remove_cvref_t< typename std::iterator_traits< It >::value_type >>> |
Map - Iterator Pair. More... | |
matrix - Two Dimensional Array
A two dimensional, owning generic array. Support slicing, array based operations and multidimensional iteration and point based index.
Elements are stored continuously in memory and are layed out in a row-wise fashion.
T | |
Alloc | default: std::allocator<T> |
using cxl::matrix< T, Alloc >::alloc_traits = typename std::allocator_traits<Alloc> |
using cxl::matrix< T, Alloc >::allocator_type = Alloc |
using cxl::matrix< T, Alloc >::const_iterator = cxl::normal_iterator<const_pointer, matrix> |
using cxl::matrix< T, Alloc >::const_pointer = typename alloc_traits::const_pointer |
using cxl::matrix< T, Alloc >::const_reference = const T& |
using cxl::matrix< T, Alloc >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
using cxl::matrix< T, Alloc >::difference_type = std::ptrdiff_t |
using cxl::matrix< T, Alloc >::iterator = cxl::normal_iterator<pointer, matrix> |
using cxl::matrix< T, Alloc >::pointer = typename alloc_traits::pointer |
using cxl::matrix< T, Alloc >::reference = T& |
using cxl::matrix< T, Alloc >::reverse_iterator = std::reverse_iterator<iterator> |
using cxl::matrix< T, Alloc >::size_type = std::size_t |
using cxl::matrix< T, Alloc >::value_type = T |
|
inlineconstexprnoexcept |
Default Constructor.
Default constructor for matrix.
|
inlineexplicitconstexprnoexcept |
Allocator Constructor.
Default Constructs a matrix with a given allocator.
alloc | type: const allocator_type& |
|
inlineexplicitconstexpr |
Default Size Constructor.
Constructs a matrix with dimensions of num_rows x num_columns. Values are default constructed or fill constructed depending on the default contractibility qualification.
num_columns | type: size_type |
num_rows | type: size_type |
alloc | type: const allocator_type& |
|
inlineexplicitconstexpr |
Explicit Value and Size Constructor.
Constructs a matrix with dimensions of num_rows x num_columns. Values are constructed from the a constant reference to a provided fill_value.
num_columns | type: size_type |
num_rows | type: size_type |
fill_value | type: value_type |
alloc | type: const allocator_type& |
|
inlineconstexpr |
Copy Constructor.
Constructs a matrix that is a copy of another matrix of the same underlying type.
other | type: const matrix& |
|
inlineexplicitconstexpr |
Copy Constructor with Alternative Allocator.
Constructs a matrix that is a copy of another matrix of the same underlying type.
other | type: const matrix& |
alloc | type: const allocator_type& |
|
inlineconstexprnoexcept |
Move Constructor.
Moves ownership of an existing Matrix's resources to this matrix and leaves the other matrix in a default constructed state.
other | type: matrix&& |
|
inlineexplicitconstexprnoexcept |
Move Constructor with Alternative Allocator.
Moves ownership of an existing Matrices resources to this matrix and leaves the other matrix in a default constructed state. Uses an alternative allocator for construction of this
matrix.
other | type: matrix&& |
alloc | type: const allocator_type& |
|
inlineconstexpr |
Initialiser List Constructor.
Uses std::initializer_list to create a matrix from an initializer list of initializer lists. Elements ownership is moved to the Matrices memory.
std::invalid_argument |
list | type: std::initializer_list<std::initializer_list<value_type>> |
alloc | type: [[maybe_unused]] const allocator_type& |
|
inlineexplicitconstexpr |
Dimension Constructor.
Constructs a matrix from the dimensions of another. The matrix is default constructed. Takes the result of a call to matrix::dimension()
.
dimensions | type: const std::tuple<size_type, size_type>& |
alloc | type: [[maybe_unused]] const allocator_type& |
|
inline |
Destructor.
Releases the resources of this matrix and leaves the matrix in an uninitialized state.
|
inlineconstexpr |
Initialiser List Assign.
Uses std::initializer_list to reassign values to a matrix. If the lists dimensions are not the same as the Matrices dimensions, then the matrix is resized to match the dimensions of the list.
std::invalid_argument |
list | type: std::initializer_list<std::initializer_list<value_type>> |
|
inlineconstexpr |
Point based element access.
Returns a reference to the element that is at the point position (column, row) of the matrix.
column | type: size_type |
row | type: size_type |
|
inlineconstexpr |
Point based element access.
Returns a reference to the element that is at the point position (column, row) of the matrix.
column | type: size_type |
row | type: size_type |
|
inlineconstexprnoexcept |
Back.
Returns a reference to the back element of the matrix.
|
inlineconstexprnoexcept |
Back.
Returns a reference to the back element of the matrix.
|
inlineconstexprnoexcept |
Begin Iterator (const)
Constant iterator to the beginning of the Matrices data.
|
inlineconstexprnoexcept |
Begin Iterator.
Iterator to the beginning of the Matrices data.
|
inlineconstexprnoexcept |
Constant Begin Iterator.
Constant iterator to the beginning of the matrix.
|
inlineconstexprnoexcept |
Constant End Iterator.
Constant iterator to the end of the Matrices data.
|
inlineconstexpr |
Clears the matrix elements.
The elements of the matrix are destroyed and the memory is deallocated entirely. The matrix is however, left in a state where it could be re-initialised through matrix::resize or reassignment.
|
inlineconstexprnoexcept |
Constant Reverse Begin Iterator.
Constant iterator to the reversed beginning of the Matrices data.
|
inlineconstexprnoexcept |
Constant Reverse End Iterator.
Constant iterator to the reversed end of the Matrices data.
|
inlineconstexprnoexcept |
Data.
Returns the underlying data pointer.
|
inlineconstexprnoexcept |
Data.
Returns the underlying data pointer.
|
inlineconstexprnoexcept |
Empty.
Checks whether the matrix is empty.
|
inlineconstexprnoexcept |
End Iterator (const)
Constant iterator to the end of the Matrices data.
|
inlineconstexprnoexcept |
End Iterator.
Iterator to the end of the Matrices data.
|
inlineconstexpr |
Erases elements between first and last.
Erases elements between first and last and then resets memory to value_type.
first | type: const_iterator |
last | type: const_iterator |
|
inlineconstexpr |
Erases element indicated by position.
Erases the value of the matrix at position and resets it to value_type.
position | type: const_iterator |
|
inlineconstexprnoexcept |
Front.
Returns a reference to the front element of the matrix.
|
inlineconstexprnoexcept |
Front.
Returns a reference to the front element of the matrix.
|
inlineconstexprnoexcept |
Get Allocator.
Returns the allocator used by the matrix.
|
inlineconstexprnoexcept |
Is Square Predicate.
If the number of rows and columns are equal, the matrix is square.
|
inlineconstexpr |
matrix Transpose
Performs a matrix transpose. Uses std::copy over std::ranges::copy as the output iterator is required to be std::constructible_v which column_iterator doesn't satisfy yet.
matrix map
Maps a function over the matrix, returning the mapped matrix.
F | concept: std::copy_constructible |
func | type: F |
|
inlineconstexpr |
Map - Iterator Pair.
Maps a function over the matrix and a range denoted by an iterator pair, returning the mapped matrix. Returns an empty matrix if this
is empty.
It | concept: std::input_iterator |
Sn | concept: std::sentinel_for<It> |
F | concept: std::copy_constructible |
first | type: It |
last | type Sn |
func | type: Fn |
|
inlineconstexpr |
matrix map with range
Maps a function over the matrix and another range object, returning the mapped matrix. Returns an empty matrix if this
is empty.
Rng | concept: std::ranges::input_range |
F | concept: std::copy_constructible |
rng | type Rng&& |
func | type F |
|
inlineconstexprnoexcept |
Max matrix Size.
Returns the maximum number of elements that can be stored in the matrix per the allocator.
|
inlineconstexprnoexcept |
Number of Columns.
Returns the number of columns of the matrix.
|
inlineconstexprnoexcept |
Number of rows.
Returns the number of rows of the matrix.
|
inlineconstexpr |
Point based element access operator.
Provides point access to Matrices elements. Overloads the invocation operator. Utilises the at() method.
column | type: size_type |
row | type: size_type |
|
inlineconstexpr |
Point based element access operator.
Provides point access to Matrices elements. Overloads the invocation operator. Utilises the at() method.
column | type: size_type |
row | type: size_type |
|
inlineconstexpr |
Copy Assignment.
Copies the contents of another matrix into this matrix and returns///this. If self assignment occurs then///this is returned immediately.
other | type: const matrix& |
|
inlineconstexprnoexcept |
Move Assignment.
Moves the ownership of other's resources to this matrix and leaves the other matrix in a default constructed state. Returns///this. If self assignment occurs then///this is returned immediately.
other | type: matrix&& |
|
inlineconstexpr |
Initialiser List Assignment.
Uses std::initializer_list to create a matrix from an initializer list of initializer lists. Elements ownership is moved to the Matrices memory.
std::invalid_argument |
list | type: [std::initializer_list<std::initializer_list<value_type>>] |
|
inlineconstexprnoexcept |
Reverse Begin Iterator (const)
Constant iterator to the reversed beginning of the Matrices data.
|
inlineconstexprnoexcept |
Reverse Begin Iterator.
Iterator to the reversed beginning of the Matrices data.
|
inlineconstexprnoexcept |
Reverse End Iterator (const)
Constant iterator to the reversed end of the Matrices data.
|
inlineconstexprnoexcept |
Reverse End Iterator.
Iterator to the reversed end of the Matrices data.
|
inlineconstexpr |
Reshape current matrix elements to new dimensions.
Reshapes the current Matrices dimensions while guaranteeing that no reallocation occurs. Elements are preserved but reordered.
std::length_error |
new_rows | type: size_type |
new_columns | type: size_type |
|
inlineconstexpr |
Resizes the matrix memory.
new_rows | type: size_type |
new_columns | type: size_type |
|
inlineconstexpr |
Resizes Matrices memory.
Resizes the matrix to a new shape of new_rows x new_columns. Resizing will cause reallocation to a new memory block if the new shape is larger or smaller than the current shape. For larger shape, previous values are copied to the new sequential memory location which will reshuffle the data's layout. New memory is given the value of fill_value. A smaller resize shape will result in elements past the new shape's sequential extent to be destroyed and deallocated. If the overall memory size remains the same, the data is only reshaped.
std::length_error |
new_rows | type: size_type |
new_columns | type: size_type |
fill_value | type: const_reference |
|
inlineconstexprnoexcept |
Dimensions.
Returns a tuple of the Matrices shape.
|
inlineconstexprnoexcept |
matrix Size
Returns the overall size of the matrix.
|
inlinenoexcept |
Swaps two Matrices of the same type.
Swaps the contents of two Matrices with the same underlying value and allocator types. The swap is performed by moving ownership of the matrices resources.
other | type: matrix& |