Stratax 0.3.1
Loading...
Searching...
No Matches
stratax::core::ArrayBase< T > Class Template Reference

Shared owning storage and layout base for Stratax array containers. More...

#include <ArrayBase.hpp>

Inheritance diagram for stratax::core::ArrayBase< T >:

Public Types

using value_type = typename Buffer< T >::value_type
 Stored element type.
 
using size_type = typename Buffer< value_type >::size_type
 Unsigned type used for element counts and indices.
 
using difference_type = typename Buffer< value_type >::difference_type
 Signed type used for checked indices and iterator distances.
 
using reference = typename Buffer< value_type >::reference
 Mutable element reference type.
 
using const_reference = typename Buffer< value_type >::const_reference
 Read-only element reference type.
 
using pointer = typename Buffer< value_type >::pointer
 Mutable element pointer type.
 
using const_pointer = typename Buffer< value_type >::const_pointer
 Read-only element pointer type.
 
using iterator = typename Buffer< value_type >::iterator
 Mutable contiguous random-access iterator type.
 
using const_iterator = typename Buffer< value_type >::const_iterator
 Read-only contiguous random-access iterator type.
 
using reverse_iterator = typename Buffer< value_type >::reverse_iterator
 Mutable reverse iterator type.
 
using const_reverse_iterator = typename Buffer< value_type >::const_reverse_iterator
 Read-only reverse iterator type.
 

Public Member Functions

size_type size () const noexcept
 Returns the number of stored elements.
 
bool empty () const noexcept
 Reports whether no elements are stored.
 
size_type rank () const noexcept
 Returns the number of logical dimensions.
 
const Shapeshape () const noexcept
 Returns the logical shape metadata.
 
const Shapestrides () const noexcept
 Returns the row-major stride metadata.
 
pointer data () noexcept
 Returns a pointer to contiguous mutable element storage.
 
const_pointer data () const noexcept
 Returns a pointer to contiguous read-only element storage.
 
reference front ()
 Returns the first element.
 
const_reference front () const
 Returns the first element.
 
reference back ()
 Returns the final element.
 
const_reference back () const
 Returns the final element.
 
reference operator[] (size_type index) noexcept
 Returns an element without bounds checking.
 
const_reference operator[] (size_type index) const noexcept
 Returns an element without bounds checking.
 
reference at (difference_type index)
 Returns an element using checked, Python-style flat indexing.
 
const_reference at (difference_type index) const
 Returns an element using checked, Python-style flat indexing.
 
iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
const_iterator begin () const noexcept
 Returns a const iterator to the first element.
 
const_iterator cbegin () const noexcept
 Returns a const iterator to the first element.
 
iterator end () noexcept
 Returns a mutable iterator past the final element.
 
const_iterator end () const noexcept
 Returns a const iterator past the final element.
 
const_iterator cend () const noexcept
 Returns a const iterator past the final element.
 
reverse_iterator rbegin () noexcept
 Returns a mutable reverse iterator to the final element.
 
const_reverse_iterator rbegin () const noexcept
 Returns a const reverse iterator to the final element.
 
const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the final element.
 
reverse_iterator rend () noexcept
 Returns the past-the-end mutable reverse iterator.
 
const_reverse_iterator rend () const noexcept
 Returns the past-the-end const reverse iterator.
 
const_reverse_iterator crend () const noexcept
 Returns the past-the-end const reverse iterator.
 
void fill (const_reference value)
 Assigns value to every stored element.
 
void swap (ArrayBase &other) noexcept
 Exchanges storage and layout metadata with other.
 

Static Public Member Functions

static constexpr std::string_view dtype () noexcept
 Returns the canonical name of the stored element dtype.
 

Protected Member Functions

 ArrayBase (const Shape &shape)
 Constructs value-initialized storage for shape.
 
 ArrayBase (const Shape &shape, const_reference value)
 Constructs storage filled with value for shape.
 
 ArrayBase (const Shape &shape, Buffer< value_type > &&buffer)
 Adopts an existing buffer for shape.
 
template<typename IndexContainer >
size_type normalized_flat_offset (const IndexContainer &raw_indices) const
 Converts checked signed multidimensional indices to a flat offset.
 

Detailed Description

template<DType T>
class stratax::core::ArrayBase< T >

Shared owning storage and layout base for Stratax array containers.

ArrayBase keeps an element Buffer synchronized with Shape metadata and its derived row-major stride Shape. It supplies the common one-dimensional container interface used by Vector, Matrix, and Tensor; derived classes provide rank constraints and multidimensional indexing APIs.

The class is not directly constructible by users because its constructors are protected.

Template Parameters
TType of each stored array element.
Invariants
See also
Buffer
Shape

Definition at line 37 of file ArrayBase.hpp.

Member Typedef Documentation

◆ const_iterator

template<DType T>
using stratax::core::ArrayBase< T >::const_iterator = typename Buffer<value_type>::const_iterator

Read-only contiguous random-access iterator type.

Definition at line 57 of file ArrayBase.hpp.

◆ const_pointer

template<DType T>
using stratax::core::ArrayBase< T >::const_pointer = typename Buffer<value_type>::const_pointer

Read-only element pointer type.

Definition at line 53 of file ArrayBase.hpp.

◆ const_reference

template<DType T>
using stratax::core::ArrayBase< T >::const_reference = typename Buffer<value_type>::const_reference

Read-only element reference type.

Definition at line 49 of file ArrayBase.hpp.

◆ const_reverse_iterator

template<DType T>
using stratax::core::ArrayBase< T >::const_reverse_iterator = typename Buffer<value_type>::const_reverse_iterator

Read-only reverse iterator type.

Definition at line 61 of file ArrayBase.hpp.

◆ difference_type

template<DType T>
using stratax::core::ArrayBase< T >::difference_type = typename Buffer<value_type>::difference_type

Signed type used for checked indices and iterator distances.

Definition at line 45 of file ArrayBase.hpp.

◆ iterator

template<DType T>
using stratax::core::ArrayBase< T >::iterator = typename Buffer<value_type>::iterator

Mutable contiguous random-access iterator type.

Definition at line 55 of file ArrayBase.hpp.

◆ pointer

template<DType T>
using stratax::core::ArrayBase< T >::pointer = typename Buffer<value_type>::pointer

Mutable element pointer type.

Definition at line 51 of file ArrayBase.hpp.

◆ reference

template<DType T>
using stratax::core::ArrayBase< T >::reference = typename Buffer<value_type>::reference

Mutable element reference type.

Definition at line 47 of file ArrayBase.hpp.

◆ reverse_iterator

template<DType T>
using stratax::core::ArrayBase< T >::reverse_iterator = typename Buffer<value_type>::reverse_iterator

Mutable reverse iterator type.

Definition at line 59 of file ArrayBase.hpp.

◆ size_type

template<DType T>
using stratax::core::ArrayBase< T >::size_type = typename Buffer<value_type>::size_type

Unsigned type used for element counts and indices.

Definition at line 43 of file ArrayBase.hpp.

◆ value_type

template<DType T>
using stratax::core::ArrayBase< T >::value_type = typename Buffer<T>::value_type

Stored element type.

Definition at line 41 of file ArrayBase.hpp.

Constructor & Destructor Documentation

◆ ArrayBase() [1/3]

template<DType T>
stratax::core::ArrayBase< T >::ArrayBase ( const Shape shape)
inlineexplicitprotected

Constructs value-initialized storage for shape.

Parameters
shapeLogical shape of the resulting array.
Exceptions
Exceptions::DimensionErrorIf the element count or a stride cannot be represented by size_type.
std::bad_allocIf element or metadata allocation fails.
Anyexception thrown while constructing a value_type element.
Complexity
O(shape.elements() + shape.rank()).

Definition at line 218 of file ArrayBase.hpp.

◆ ArrayBase() [2/3]

template<DType T>
stratax::core::ArrayBase< T >::ArrayBase ( const Shape shape,
const_reference  value 
)
inlineprotected

Constructs storage filled with value for shape.

Parameters
shapeLogical shape of the resulting array.
valueValue copied into every element.
Exceptions
Exceptions::DimensionErrorIf the element count or a stride cannot be represented by size_type.
std::bad_allocIf element or metadata allocation fails.
Anyexception thrown by value_type's copy constructor.
Complexity
O(shape.elements() + shape.rank()).

Definition at line 234 of file ArrayBase.hpp.

◆ ArrayBase() [3/3]

template<DType T>
stratax::core::ArrayBase< T >::ArrayBase ( const Shape shape,
Buffer< value_type > &&  buffer 
)
inlineprotected

Adopts an existing buffer for shape.

Ownership of buffer is transferred before its element count is validated. If validation fails, the adopted storage is released while unwinding construction.

Parameters
shapeLogical shape associated with the storage.
bufferElement storage to adopt.
Exceptions
Exceptions::ShapeErrorIf buffer.size() != shape.elements().
Exceptions::DimensionErrorIf the element count or a stride cannot be represented by size_type.
std::bad_allocIf metadata allocation fails.
Complexity
O(shape.rank()) plus O(1) buffer ownership transfer.

Definition at line 255 of file ArrayBase.hpp.

Member Function Documentation

◆ at() [1/2]

template<DType T>
reference stratax::core::ArrayBase< T >::at ( difference_type  index)
inline

Returns an element using checked, Python-style flat indexing.

Parameters
indexIndex in the range [-size(), size()).
Exceptions
Exceptions::IndexErrorIf index is outside the valid range.
Complexity
O(1).

Definition at line 150 of file ArrayBase.hpp.

◆ at() [2/2]

template<DType T>
const_reference stratax::core::ArrayBase< T >::at ( difference_type  index) const
inline

Returns an element using checked, Python-style flat indexing.

Parameters
indexIndex in the range [-size(), size()).
Exceptions
Exceptions::IndexErrorIf index is outside the valid range.
Complexity
O(1).

Definition at line 157 of file ArrayBase.hpp.

◆ back() [1/2]

template<DType T>
reference stratax::core::ArrayBase< T >::back ( )
inline

Returns the final element.

Exceptions
Exceptions::IndexErrorIf empty.
Complexity
O(1).

Definition at line 119 of file ArrayBase.hpp.

◆ back() [2/2]

template<DType T>
const_reference stratax::core::ArrayBase< T >::back ( ) const
inline

Returns the final element.

Exceptions
Exceptions::IndexErrorIf empty.
Complexity
O(1).

Definition at line 129 of file ArrayBase.hpp.

◆ begin() [1/2]

template<DType T>
const_iterator stratax::core::ArrayBase< T >::begin ( ) const
inlinenoexcept

Returns a const iterator to the first element.

Complexity
O(1).

Definition at line 162 of file ArrayBase.hpp.

◆ begin() [2/2]

template<DType T>
iterator stratax::core::ArrayBase< T >::begin ( )
inlinenoexcept

Returns a mutable iterator to the first element.

Complexity
O(1).

Definition at line 160 of file ArrayBase.hpp.

◆ cbegin()

template<DType T>
const_iterator stratax::core::ArrayBase< T >::cbegin ( ) const
inlinenoexcept

Returns a const iterator to the first element.

Complexity
O(1).

Definition at line 164 of file ArrayBase.hpp.

◆ cend()

template<DType T>
const_iterator stratax::core::ArrayBase< T >::cend ( ) const
inlinenoexcept

Returns a const iterator past the final element.

Complexity
O(1).

Definition at line 170 of file ArrayBase.hpp.

◆ crbegin()

template<DType T>
const_reverse_iterator stratax::core::ArrayBase< T >::crbegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the final element.

Complexity
O(1).

Definition at line 176 of file ArrayBase.hpp.

◆ crend()

template<DType T>
const_reverse_iterator stratax::core::ArrayBase< T >::crend ( ) const
inlinenoexcept

Returns the past-the-end const reverse iterator.

Complexity
O(1).

Definition at line 182 of file ArrayBase.hpp.

◆ data() [1/2]

template<DType T>
const_pointer stratax::core::ArrayBase< T >::data ( ) const
inlinenoexcept

Returns a pointer to contiguous read-only element storage.

Returns
First element address, or nullptr when empty.
Complexity
O(1).

Definition at line 95 of file ArrayBase.hpp.

◆ data() [2/2]

template<DType T>
pointer stratax::core::ArrayBase< T >::data ( )
inlinenoexcept

Returns a pointer to contiguous mutable element storage.

Returns
First element address, or nullptr when empty.
Complexity
O(1).

Definition at line 89 of file ArrayBase.hpp.

◆ dtype()

template<DType T>
static constexpr std::string_view stratax::core::ArrayBase< T >::dtype ( )
inlinestaticconstexprnoexcept

Returns the canonical name of the stored element dtype.

Complexity
O(1).

Definition at line 64 of file ArrayBase.hpp.

◆ empty()

template<DType T>
bool stratax::core::ArrayBase< T >::empty ( ) const
inlinenoexcept

Reports whether no elements are stored.

Complexity
O(1).

Definition at line 73 of file ArrayBase.hpp.

◆ end() [1/2]

template<DType T>
const_iterator stratax::core::ArrayBase< T >::end ( ) const
inlinenoexcept

Returns a const iterator past the final element.

Complexity
O(1).

Definition at line 168 of file ArrayBase.hpp.

◆ end() [2/2]

template<DType T>
iterator stratax::core::ArrayBase< T >::end ( )
inlinenoexcept

Returns a mutable iterator past the final element.

Complexity
O(1).

Definition at line 166 of file ArrayBase.hpp.

◆ fill()

template<DType T>
void stratax::core::ArrayBase< T >::fill ( const_reference  value)
inline

Assigns value to every stored element.

Parameters
valueValue copied into each element.
Exceptions
Anyexception thrown by value_type's copy-assignment operator.
Complexity
O(size()).

Definition at line 190 of file ArrayBase.hpp.

◆ front() [1/2]

template<DType T>
reference stratax::core::ArrayBase< T >::front ( )
inline

Returns the first element.

Exceptions
Exceptions::IndexErrorIf empty.
Complexity
O(1).

Definition at line 98 of file ArrayBase.hpp.

◆ front() [2/2]

template<DType T>
const_reference stratax::core::ArrayBase< T >::front ( ) const
inline

Returns the first element.

Exceptions
Exceptions::IndexErrorIf empty.
Complexity
O(1).

Definition at line 108 of file ArrayBase.hpp.

◆ normalized_flat_offset()

template<DType T>
template<typename IndexContainer >
size_type stratax::core::ArrayBase< T >::normalized_flat_offset ( const IndexContainer &  raw_indices) const
inlineprotected

Converts checked signed multidimensional indices to a flat offset.

Each component is normalized independently against its corresponding dimension. Negative components count backward from the end. The selected exception context controls standardized rank and component diagnostics.

Template Parameters
IndexContainerSized, indexable container of signed indices.
Parameters
raw_indicesOne index per logical dimension.
contextArray category used to select standardized diagnostics.
Returns
Row-major flat element offset.
Exceptions
Exceptions::RankErrorIf the number of indices differs from the rank.
Exceptions::IndexErrorIf an index component is out of bounds.
Complexity
O(rank()).

Definition at line 283 of file ArrayBase.hpp.

◆ operator[]() [1/2]

template<DType T>
const_reference stratax::core::ArrayBase< T >::operator[] ( size_type  index) const
inlinenoexcept

Returns an element without bounds checking.

Precondition
index < size().
Complexity
O(1).

Definition at line 142 of file ArrayBase.hpp.

◆ operator[]() [2/2]

template<DType T>
reference stratax::core::ArrayBase< T >::operator[] ( size_type  index)
inlinenoexcept

Returns an element without bounds checking.

Precondition
index < size().
Complexity
O(1).

Definition at line 140 of file ArrayBase.hpp.

◆ rank()

template<DType T>
size_type stratax::core::ArrayBase< T >::rank ( ) const
inlinenoexcept

Returns the number of logical dimensions.

Complexity
O(1).

Definition at line 76 of file ArrayBase.hpp.

◆ rbegin() [1/2]

template<DType T>
const_reverse_iterator stratax::core::ArrayBase< T >::rbegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the final element.

Complexity
O(1).

Definition at line 174 of file ArrayBase.hpp.

◆ rbegin() [2/2]

template<DType T>
reverse_iterator stratax::core::ArrayBase< T >::rbegin ( )
inlinenoexcept

Returns a mutable reverse iterator to the final element.

Complexity
O(1).

Definition at line 172 of file ArrayBase.hpp.

◆ rend() [1/2]

template<DType T>
const_reverse_iterator stratax::core::ArrayBase< T >::rend ( ) const
inlinenoexcept

Returns the past-the-end const reverse iterator.

Complexity
O(1).

Definition at line 180 of file ArrayBase.hpp.

◆ rend() [2/2]

template<DType T>
reverse_iterator stratax::core::ArrayBase< T >::rend ( )
inlinenoexcept

Returns the past-the-end mutable reverse iterator.

Complexity
O(1).

Definition at line 178 of file ArrayBase.hpp.

◆ shape()

template<DType T>
const Shape & stratax::core::ArrayBase< T >::shape ( ) const
inlinenoexcept

Returns the logical shape metadata.

Complexity
O(1).

Definition at line 79 of file ArrayBase.hpp.

◆ size()

template<DType T>
size_type stratax::core::ArrayBase< T >::size ( ) const
inlinenoexcept

Returns the number of stored elements.

Complexity
O(1).

Definition at line 70 of file ArrayBase.hpp.

◆ strides()

template<DType T>
const Shape & stratax::core::ArrayBase< T >::strides ( ) const
inlinenoexcept

Returns the row-major stride metadata.

Complexity
O(1).

Definition at line 82 of file ArrayBase.hpp.

◆ swap()

template<DType T>
void stratax::core::ArrayBase< T >::swap ( ArrayBase< T > &  other)
inlinenoexcept

Exchanges storage and layout metadata with other.

Pointers, references, and iterators remain valid but refer to elements now owned by the other object.

Parameters
otherArrayBase whose state is exchanged with this object.
Complexity
O(1).

Definition at line 201 of file ArrayBase.hpp.


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