Stratax 0.4.0rc1
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 Shape & shape () const noexcept
 Returns the logical shape metadata.
 
const Shape & strides () 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 ArrayBase &)=default
 Copies storage and layout into independent buffers.
 
 ArrayBase (ArrayBase &&) noexcept=default
 Transfers storage and layout, leaving the source empty with rank zero.
 
ArrayBase & operator= (ArrayBase &&) noexcept=default
 Replaces storage and layout by moving; a distinct source becomes empty with rank zero.
 
ArrayBase & operator= (const ArrayBase &other)
 Copies storage and layout as one transaction.
 
 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 40 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 60 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 56 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 52 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 64 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 48 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 58 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 54 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 50 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 62 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 46 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 44 of file ArrayBase.hpp.

Constructor & Destructor Documentation

◆ ArrayBase() [1/5]

template<DType T>
stratax::core::ArrayBase< T >::ArrayBase ( const ArrayBase< T > &  )
protecteddefault

Copies storage and layout into independent buffers.

Complexity
O(n + r), for n source elements and rank r.

◆ ArrayBase() [2/5]

template<DType T>
stratax::core::ArrayBase< T >::ArrayBase ( ArrayBase< T > &&  )
protecteddefaultnoexcept

Transfers storage and layout, leaving the source empty with rank zero.

Complexity
O(1).

◆ ArrayBase() [3/5]

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 247 of file ArrayBase.hpp.

◆ ArrayBase() [4/5]

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 263 of file ArrayBase.hpp.

◆ ArrayBase() [5/5]

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 284 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 153 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 160 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 122 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 132 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 165 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 163 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 167 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 173 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 179 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 185 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 98 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 92 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 67 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 76 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 171 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 169 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 193 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 101 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 111 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.

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

Definition at line 310 of file ArrayBase.hpp.

◆ operator=() [1/2]

template<DType T>
ArrayBase & stratax::core::ArrayBase< T >::operator= ( ArrayBase< T > &&  )
protecteddefaultnoexcept

Replaces storage and layout by moving; a distinct source becomes empty with rank zero.

Complexity
O(size() + rank()).

◆ operator=() [2/2]

template<DType T>
ArrayBase & stratax::core::ArrayBase< T >::operator= ( const ArrayBase< T > &  other)
inlineprotected

Copies storage and layout as one transaction.

Parameters
otherSource array base.
Returns
Reference to this base.
Exceptions
std::bad_allocIf storage or metadata allocation fails; this object is unchanged.
Complexity
O(size() + other.size() + rank() + other.rank()).

Definition at line 228 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 145 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 143 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 79 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 177 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 175 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 183 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 181 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 82 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 73 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 85 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.
Precondition
Both layouts satisfy any fixed-rank invariants of the receiving derived containers (for example, do not swap a Vector base with a Matrix base).
Complexity
O(1).

Definition at line 206 of file ArrayBase.hpp.


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