6#include <stratax/core/Buffer.hpp>
7#include <stratax/core/Shape.hpp>
8#include <stratax/exceptions/Exceptions.hpp>
9#include <stratax/indexing/Normalize.hpp>
10#include <stratax/core/dtypes/DTypeTraits.hpp>
11#include <stratax/core/dtypes/Concepts.hpp>
13namespace stratax::core {
64 [[nodiscard]]
static constexpr std::string_view
dtype() noexcept
73 [[nodiscard]]
bool empty() const noexcept {
return buffer_.
empty();}
79 [[nodiscard]]
const Shape&
shape() const noexcept {
return shape_;}
82 [[nodiscard]]
const Shape&
strides() const noexcept {
return strides_;}
105 return buffer_.
front();
115 return buffer_.
front();
126 return buffer_.
back();
136 return buffer_.
back();
203 buffer_.
swap(other.buffer_);
204 shape_.
swap(other.shape_);
205 strides_.
swap(other.strides_);
219 : buffer_(
shape.elements()),
235 : buffer_(
shape.elements(), value),
256 : buffer_(std::move(buffer)),
263 "Buffer size does not match the shape's element count.");
282 template<
typename IndexContainer>
285 if (raw_indices.size() !=
rank())
288 "The number of indices must match the array rank.");
295 const size_type index = indexing::normalize_index(
296 raw_indices[i], shape_[i]);
297 offset += index * strides_[i];
Shared owning storage and layout base for Stratax array containers.
reference back()
Returns the final element.
ArrayBase(const Shape &shape, const_reference value)
Constructs storage filled with value for shape.
reverse_iterator rend() noexcept
Returns the past-the-end mutable reverse iterator.
typename Buffer< T >::value_type value_type
Stored element type.
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the final element.
const_iterator end() const noexcept
Returns a const iterator past the final element.
const_iterator begin() const noexcept
Returns a const iterator to the first element.
typename Buffer< value_type >::pointer pointer
Mutable element pointer type.
ArrayBase(const Shape &shape, Buffer< value_type > &&buffer)
Adopts an existing buffer for shape.
typename Buffer< value_type >::const_reference const_reference
Read-only element reference type.
ArrayBase(const Shape &shape)
Constructs value-initialized storage for shape.
reference operator[](size_type index) noexcept
Returns an element without bounds checking.
const Shape & shape() const noexcept
Returns the logical shape metadata.
size_type size() const noexcept
Returns the number of stored elements.
typename Buffer< value_type >::reverse_iterator reverse_iterator
Mutable reverse iterator type.
bool empty() const noexcept
Reports whether no elements are stored.
const_iterator cbegin() const noexcept
Returns a const iterator to the first element.
void fill(const_reference value)
Assigns value to every stored element.
typename Buffer< value_type >::const_reverse_iterator const_reverse_iterator
Read-only reverse iterator type.
const_pointer data() const noexcept
Returns a pointer to contiguous read-only element storage.
const_iterator cend() const noexcept
Returns a const iterator past the final element.
pointer data() noexcept
Returns a pointer to contiguous mutable element storage.
typename Buffer< value_type >::const_pointer const_pointer
Read-only element pointer type.
size_type rank() const noexcept
Returns the number of logical dimensions.
const_reference operator[](size_type index) const noexcept
Returns an element without bounds checking.
iterator begin() noexcept
Returns a mutable iterator to the first element.
size_type normalized_flat_offset(const IndexContainer &raw_indices) const
Converts checked signed multidimensional indices to a flat offset.
typename Buffer< value_type >::difference_type difference_type
Signed type used for checked indices and iterator distances.
typename Buffer< value_type >::iterator iterator
Mutable contiguous random-access iterator type.
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the final element.
static constexpr std::string_view dtype() noexcept
Returns the canonical name of the stored element dtype.
reference front()
Returns the first element.
reference at(difference_type index)
Returns an element using checked, Python-style flat indexing.
typename Buffer< value_type >::const_iterator const_iterator
Read-only contiguous random-access iterator type.
typename Buffer< value_type >::reference reference
Mutable element reference type.
const_reverse_iterator crend() const noexcept
Returns the past-the-end const reverse iterator.
const_reference front() const
Returns the first element.
iterator end() noexcept
Returns a mutable iterator past the final element.
reverse_iterator rbegin() noexcept
Returns a mutable reverse iterator to the final element.
const_reference back() const
Returns the final element.
const_reverse_iterator rend() const noexcept
Returns the past-the-end const reverse iterator.
const_reference at(difference_type index) const
Returns an element using checked, Python-style flat indexing.
const Shape & strides() const noexcept
Returns the row-major stride metadata.
void swap(ArrayBase &other) noexcept
Exchanges storage and layout metadata with other.
typename Buffer< value_type >::size_type size_type
Unsigned type used for element counts and indices.
Fixed-size owner of aligned, contiguous element storage.
const_pointer const_iterator
Read-only contiguous random-access iterator type.
std::reverse_iterator< iterator > reverse_iterator
Mutable iterator that traverses elements in reverse order.
reverse_iterator rend() noexcept
Returns the past-the-end iterator for mutable reverse traversal.
void swap(Buffer &other) noexcept
Swaps storage and size with another buffer.
T & reference
Mutable element reference type.
size_type size() const noexcept
Returns the number of stored elements.
T * pointer
Mutable pointer to an element.
const_reverse_iterator crend() const noexcept
Returns the past-the-end iterator for const reverse traversal.
std::ptrdiff_t difference_type
Signed type used for distances between iterators.
reference front()
Returns a reference to the first element.
const_iterator cend() const noexcept
Returns a const iterator one past the final element.
pointer iterator
Mutable contiguous random-access iterator type.
bool empty() const noexcept
Returns whether the buffer has no elements.
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the final element.
std::size_t size_type
Unsigned type used for element counts and indices.
reverse_iterator rbegin() noexcept
Returns a mutable reverse iterator to the final element.
void fill(const_reference value)
Assigns a value to every element in the buffer.
pointer data() noexcept
Returns a pointer to the underlying contiguous storage.
iterator begin() noexcept
Returns a mutable iterator to the first element.
const_iterator cbegin() const noexcept
Returns a const iterator to the first element.
const T * const_pointer
Read-only pointer to an element.
reference back()
Returns a reference to the last element.
std::reverse_iterator< const_iterator > const_reverse_iterator
Read-only iterator that traverses elements in reverse order.
const T & const_reference
Read-only element reference type.
iterator end() noexcept
Returns a mutable iterator one past the final element.
T value_type
Type of each stored element.
Stores the dimensions of a multidimensional array.
size_type elements() const
Computes the total number of elements described by the shape.
size_type rank() const noexcept
Returns the number of dimensions.
void swap(Shape &other) noexcept
Exchanges dimension storage with another shape.
Provides compile-time metadata for a supported Stratax dtype.