Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
stratax::core::Strides Class Reference

Stores strides for a shape in contiguous memory. More...

#include <Strides.hpp>

Public Member Functions

 Strides () noexcept=default
 Creates an empty stride vector.
 Strides (const Shape &shape)
 Creates row-major strides for a given shape.
 Strides (const Strides &)=default
 Strides (Strides &&) noexcept=default
Stridesoperator= (const Strides &)=default
Stridesoperator= (Strides &&) noexcept=default
 ~Strides ()=default
 Destroys the stride vector.
std::size_t size () const noexcept
 Returns the number of stored stride values.
bool empty () const noexcept
 Returns whether the stride vector is empty.
std::size_t rank () const noexcept
 Returns the number of dimensions represented by the strides.
const std::size_t & operator() (std::size_t index) const
 Returns a stride value without bounds checking.
const std::size_t & at (std::size_t index) const
 Returns a stride value with bounds checking.
const std::size_t & front () const
 Returns the first stride value.
const std::size_t & back () const
 Returns the last stride value.
const std::size_t * data () const noexcept
 Returns the raw stride data pointer.
const std::size_t * begin () noexcept
 Returns an iterator to the first stride value.
const std::size_t * begin () const noexcept
 Returns a const iterator to the first stride value.
const std::size_t * cbegin () const noexcept
 Returns a const iterator to the first stride value.
const std::size_t * end () noexcept
 Returns an iterator one past the last stride value.
const std::size_t * end () const noexcept
 Returns a const iterator one past the last stride value.
const std::size_t * cend () const noexcept
 Returns a const iterator one past the last stride value.
std::reverse_iterator< const std::size_t * > rbegin () noexcept
 Returns a reverse iterator to the last stride value.
std::reverse_iterator< const std::size_t * > rbegin () const noexcept
 Returns a const reverse iterator to the last stride value.
std::reverse_iterator< const std::size_t * > crbegin () const noexcept
 Returns a const reverse iterator to the last stride value.
std::reverse_iterator< const std::size_t * > rend () noexcept
 Returns a reverse iterator before the first stride value.
std::reverse_iterator< const std::size_t * > rend () const noexcept
 Returns a const reverse iterator before the first stride value.
std::reverse_iterator< const std::size_t * > crend () const noexcept
 Returns a const reverse iterator before the first stride value.
void swap (Strides &other) noexcept
 Swaps the stored strides with another instance.
bool operator== (const Strides &other) const noexcept
 Compares two stride vectors for equality.
bool operator!= (const Strides &other) const noexcept
 Returns whether two stride vectors differ.

Detailed Description

Stores strides for a shape in contiguous memory.

Strides map logical indices to flat storage offsets, typically for row-major layout. The values are stored as metadata and do not own any array elements.

Definition at line 22 of file Strides.hpp.

Constructor & Destructor Documentation

◆ Strides() [1/4]

stratax::core::Strides::Strides ( )
defaultnoexcept

Creates an empty stride vector.

Referenced by operator!=(), operator=(), operator=(), operator==(), Strides(), Strides(), Strides(), swap(), and ~Strides().

◆ Strides() [2/4]

stratax::core::Strides::Strides ( const Shape & shape)
inlineexplicit

Creates row-major strides for a given shape.

The last dimension receives stride 1 and each preceding dimension is computed from the product of the dimensions to its right.

Parameters
shapeSource shape used to derive stride values.
Exceptions
Exceptions::DimensionErrorIf stride computation overflows.

Definition at line 43 of file Strides.hpp.

References rank(), and Strides().

◆ Strides() [3/4]

stratax::core::Strides::Strides ( const Strides & )
default

References Strides().

◆ Strides() [4/4]

stratax::core::Strides::Strides ( Strides && )
defaultnoexcept

References Strides().

◆ ~Strides()

stratax::core::Strides::~Strides ( )
default

Destroys the stride vector.

References Strides().

Member Function Documentation

◆ at()

const std::size_t & stratax::core::Strides::at ( std::size_t index) const
inline

Returns a stride value with bounds checking.

Parameters
indexStride index.
Returns
Const reference to the requested stride value.
Exceptions
Exceptions::IndexErrorIf the index is out of bounds.

Definition at line 123 of file Strides.hpp.

References rank(), and stratax::core::validation::require_index().

◆ back()

const std::size_t & stratax::core::Strides::back ( ) const
inline

Returns the last stride value.

Returns
Const reference to the last stride value.

Definition at line 144 of file Strides.hpp.

◆ begin() [1/2]

const std::size_t * stratax::core::Strides::begin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first stride value.

Returns
Const iterator to the beginning of the stride storage.

Definition at line 174 of file Strides.hpp.

◆ begin() [2/2]

const std::size_t * stratax::core::Strides::begin ( )
inlinenodiscardnoexcept

Returns an iterator to the first stride value.

Returns
Iterator to the beginning of the stride storage.

Definition at line 164 of file Strides.hpp.

Referenced by offset().

◆ cbegin()

const std::size_t * stratax::core::Strides::cbegin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first stride value.

Returns
Const iterator to the beginning of the stride storage.

Definition at line 184 of file Strides.hpp.

◆ cend()

const std::size_t * stratax::core::Strides::cend ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last stride value.

Returns
Const iterator to the end of the stride storage.

Definition at line 214 of file Strides.hpp.

◆ crbegin()

std::reverse_iterator< const std::size_t * > stratax::core::Strides::crbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last stride value.

Returns
Const reverse iterator starting at the last stride value.

Definition at line 244 of file Strides.hpp.

◆ crend()

std::reverse_iterator< const std::size_t * > stratax::core::Strides::crend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first stride value.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 274 of file Strides.hpp.

◆ data()

const std::size_t * stratax::core::Strides::data ( ) const
inlinenodiscardnoexcept

Returns the raw stride data pointer.

Returns
Pointer to the first stored stride, or nullptr when empty.

Definition at line 154 of file Strides.hpp.

◆ empty()

bool stratax::core::Strides::empty ( ) const
inlinenodiscardnoexcept

Returns whether the stride vector is empty.

Returns
true when no strides are stored.

Definition at line 86 of file Strides.hpp.

◆ end() [1/2]

const std::size_t * stratax::core::Strides::end ( ) const
inlinenodiscardnoexcept

Returns a const iterator one past the last stride value.

Returns
Const iterator to the end of the stride storage.

Definition at line 204 of file Strides.hpp.

◆ end() [2/2]

const std::size_t * stratax::core::Strides::end ( )
inlinenodiscardnoexcept

Returns an iterator one past the last stride value.

Returns
Iterator to the end of the stride storage.

Definition at line 194 of file Strides.hpp.

◆ front()

const std::size_t & stratax::core::Strides::front ( ) const
inline

Returns the first stride value.

Returns
Const reference to the first stride value.

Definition at line 134 of file Strides.hpp.

◆ operator!=()

bool stratax::core::Strides::operator!= ( const Strides & other) const
inlinenodiscardnoexcept

Returns whether two stride vectors differ.

Parameters
otherStrides object to compare against.
Returns
true when the stride vectors are not equal.

Definition at line 318 of file Strides.hpp.

References Strides().

◆ operator()()

const std::size_t & stratax::core::Strides::operator() ( std::size_t index) const
inline

Returns a stride value without bounds checking.

Parameters
indexStride index.
Returns
Const reference to the requested stride value.
Warning
The caller must ensure that the index is in range.

Definition at line 109 of file Strides.hpp.

◆ operator=() [1/2]

Strides & stratax::core::Strides::operator= ( const Strides & )
default

References Strides().

◆ operator=() [2/2]

Strides & stratax::core::Strides::operator= ( Strides && )
defaultnoexcept

References Strides().

◆ operator==()

bool stratax::core::Strides::operator== ( const Strides & other) const
inlinenodiscardnoexcept

Compares two stride vectors for equality.

Parameters
otherStrides object to compare against.
Returns
true when the stride vectors match exactly.

Definition at line 296 of file Strides.hpp.

References rank(), and Strides().

◆ rank()

std::size_t stratax::core::Strides::rank ( ) const
inlinenodiscardnoexcept

Returns the number of dimensions represented by the strides.

Returns
Rank of the stride vector.

Definition at line 96 of file Strides.hpp.

Referenced by at(), offset(), stratax::core::operator<<(), operator==(), and Strides().

◆ rbegin() [1/2]

std::reverse_iterator< const std::size_t * > stratax::core::Strides::rbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the last stride value.

Returns
Const reverse iterator starting at the last stride value.

Definition at line 234 of file Strides.hpp.

◆ rbegin() [2/2]

std::reverse_iterator< const std::size_t * > stratax::core::Strides::rbegin ( )
inlinenodiscardnoexcept

Returns a reverse iterator to the last stride value.

Returns
Reverse iterator starting at the last stride value.

Definition at line 224 of file Strides.hpp.

◆ rend() [1/2]

std::reverse_iterator< const std::size_t * > stratax::core::Strides::rend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator before the first stride value.

Returns
Const reverse iterator representing the end sentinel.

Definition at line 264 of file Strides.hpp.

◆ rend() [2/2]

std::reverse_iterator< const std::size_t * > stratax::core::Strides::rend ( )
inlinenodiscardnoexcept

Returns a reverse iterator before the first stride value.

Returns
Reverse iterator representing the end sentinel.

Definition at line 254 of file Strides.hpp.

◆ size()

std::size_t stratax::core::Strides::size ( ) const
inlinenodiscardnoexcept

Returns the number of stored stride values.

Returns
Number of stored stride values.

Definition at line 76 of file Strides.hpp.

References size().

Referenced by size().

◆ swap()

void stratax::core::Strides::swap ( Strides & other)
inlinenoexcept

Swaps the stored strides with another instance.

Parameters
otherStrides object to exchange state with.

Definition at line 284 of file Strides.hpp.

References Strides().


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