5#include "../Exceptions.hpp"
13namespace stratax::core {
56 : buffer_(shape.
rank())
62 buffer_[shape.rank() - 1] = 1;
64 for (std::size_t i = shape.rank() - 1; i > 0; --i) {
65 buffer_[i - 1] = validation::checked_multiply(
68 "Strides overflow for shape");
94 [[nodiscard]] std::
size_t size() const noexcept
96 return buffer_.size();
104 [[nodiscard]]
bool empty() const noexcept
106 return buffer_.empty();
114 [[nodiscard]] std::size_t
rank() const noexcept
116 return buffer_.size();
129 return buffer_[index];
141 const std::size_t&
at(std::size_t index)
const
143 validation::require_index(index,
rank(),
"Strides index out of bounds");
144 return buffer_[index];
154 return buffer_.front();
162 const std::size_t&
back()
const
164 return buffer_.back();
172 [[nodiscard]]
const std::size_t*
data() const noexcept
174 return buffer_.data();
184 return buffer_.begin();
194 return buffer_.begin();
204 return buffer_.cbegin();
214 return buffer_.end();
224 return buffer_.end();
234 return buffer_.cend();
244 return buffer_.rbegin();
254 return buffer_.rbegin();
264 return buffer_.crbegin();
274 return buffer_.rend();
284 return buffer_.rend();
294 return buffer_.crend();
304 buffer_.swap(other.buffer_);
316 if (
rank() != other.rank()) {
320 for (std::size_t i = 0; i <
rank(); ++i) {
321 if (buffer_[i] != other.buffer_[i]) {
338 return !(*
this == other);
350inline std::ostream& operator<<(std::ostream& os,
const Strides& stride)
355 for (std::size_t dim : stride)
364 if (stride.rank() == 1)
Shared runtime validation helpers.
Owns contiguous dynamically allocated storage.
const T * const_iterator
Const iterator over contiguous buffer elements.
std::reverse_iterator< const_iterator > const_reverse_iterator
Const reverse iterator over contiguous buffer elements.
Stores a list of dimension lengths for an array shape.
const_iterator begin() const noexcept
Returns a const iterator to the first stride value.
const_iterator cbegin() const noexcept
Returns a const iterator to the first stride value.
bool operator!=(const Strides &other) const noexcept
Returns whether two stride vectors differ.
bool operator==(const Strides &other) const noexcept
Compares two stride vectors for equality.
Buffer< std::size_t >::const_iterator iterator
Iterator over immutable stride values.
const std::size_t & at(std::size_t index) const
Returns a stride value with bounds checking.
Buffer< std::size_t >::const_iterator const_iterator
Const iterator over stride values.
Buffer< std::size_t >::const_reverse_iterator reverse_iterator
Reverse iterator over immutable stride values.
Strides(const Strides &)=default
Copies stride metadata.
bool empty() const noexcept
Returns whether the stride vector is empty.
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the last stride value.
const std::size_t & operator()(std::size_t index) const
Returns a stride value without bounds checking.
std::size_t rank() const noexcept
Returns the number of dimensions represented by the strides.
const_iterator end() const noexcept
Returns a const iterator one past the last stride value.
Buffer< std::size_t >::const_reverse_iterator const_reverse_iterator
Const reverse iterator over stride values.
const_iterator cend() const noexcept
Returns a const iterator one past the last stride value.
const std::size_t * data() const noexcept
Returns the raw stride data pointer.
reverse_iterator rend() noexcept
Returns a reverse iterator before the first stride value.
const std::size_t & back() const
Returns the last stride value.
iterator end() noexcept
Returns an iterator one past the last stride value.
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the last stride value.
std::size_t size() const noexcept
Returns the number of stored stride values.
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the last stride value.
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator before the first stride value.
const std::size_t & front() const
Returns the first stride value.
iterator begin() noexcept
Returns an iterator to the first stride value.
Strides(Strides &&) noexcept=default
Moves stride metadata.
void swap(Strides &other) noexcept
Swaps the stored strides with another instance.
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator before the first stride value.
Strides() noexcept=default
Creates an empty stride vector.