44 : buffer_(shape.
rank())
50 buffer_[shape.rank() - 1] = 1;
52 for (std::size_t i = shape.rank() - 1; i > 0; --i) {
53 buffer_[i - 1] = validation::checked_multiply(
56 "Strides overflow for shape");
76 [[nodiscard]] std::
size_t size() const noexcept
78 return buffer_.size();
86 [[nodiscard]]
bool empty() const noexcept
88 return buffer_.empty();
96 [[nodiscard]] std::size_t
rank() const noexcept
98 return buffer_.size();
111 return buffer_[index];
123 const std::size_t&
at(std::size_t index)
const
126 return buffer_[index];
136 return buffer_.front();
144 const std::size_t&
back()
const
146 return buffer_.back();
154 [[nodiscard]]
const std::size_t*
data() const noexcept
156 return buffer_.data();
164 [[nodiscard]]
const std::size_t*
begin() noexcept
166 return buffer_.begin();
174 [[nodiscard]]
const std::size_t*
begin() const noexcept
176 return buffer_.begin();
184 [[nodiscard]]
const std::size_t*
cbegin() const noexcept
186 return buffer_.cbegin();
194 [[nodiscard]]
const std::size_t*
end() noexcept
196 return buffer_.end();
204 [[nodiscard]]
const std::size_t*
end() const noexcept
206 return buffer_.end();
214 [[nodiscard]]
const std::size_t*
cend() const noexcept
216 return buffer_.cend();
224 [[nodiscard]] std::reverse_iterator<const std::size_t*>
rbegin() noexcept
226 return buffer_.rbegin();
234 [[nodiscard]] std::reverse_iterator<const std::size_t*>
rbegin() const noexcept
236 return buffer_.rbegin();
244 [[nodiscard]] std::reverse_iterator<const std::size_t*>
crbegin() const noexcept
246 return buffer_.crbegin();
254 [[nodiscard]] std::reverse_iterator<const std::size_t*>
rend() noexcept
256 return buffer_.rend();
264 [[nodiscard]] std::reverse_iterator<const std::size_t*>
rend() const noexcept
266 return buffer_.rend();
274 [[nodiscard]] std::reverse_iterator<const std::size_t*>
crend() const noexcept
276 return buffer_.crend();
286 buffer_.swap(other.buffer_);
298 if (
rank() != other.rank()) {
302 for (std::size_t i = 0; i <
rank(); ++i) {
303 if (buffer_[i] != other.buffer_[i]) {
320 return !(*
this == other);
337 for (std::size_t dim : stride)
346 if (stride.
rank() == 1)
Shared runtime validation helpers.
Owns contiguous dynamically allocated storage.
Stores a list of dimension lengths for an array shape.
Stores strides for a shape in contiguous memory.
bool operator!=(const Strides &other) const noexcept
Returns whether two stride vectors differ.
std::reverse_iterator< const std::size_t * > rbegin() const noexcept
Returns a const reverse iterator to the last stride value.
bool operator==(const Strides &other) const noexcept
Compares two stride vectors for equality.
const std::size_t & at(std::size_t index) const
Returns a stride value with bounds checking.
Strides(const Strides &)=default
bool empty() const noexcept
Returns whether the stride vector is empty.
std::reverse_iterator< const std::size_t * > rend() const noexcept
Returns a const reverse iterator before the first 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.
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 * > crend() const noexcept
Returns a const reverse iterator before the first stride value.
const std::size_t * data() const noexcept
Returns the raw stride data pointer.
std::reverse_iterator< const std::size_t * > rbegin() noexcept
Returns a reverse iterator to the last stride value.
const std::size_t & back() const
Returns the last stride value.
const std::size_t * end() noexcept
Returns an iterator one past the last stride value.
const std::size_t * cend() const noexcept
Returns a const 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 * cbegin() const noexcept
Returns a const iterator to the first stride value.
const std::size_t * begin() noexcept
Returns an iterator to the first stride value.
std::reverse_iterator< const std::size_t * > crbegin() const noexcept
Returns a const reverse iterator to the last stride value.
std::size_t size() const noexcept
Returns the number of stored stride values.
const std::size_t & front() const
Returns the first stride value.
Strides(Strides &&) noexcept=default
void swap(Strides &other) noexcept
Swaps the stored strides with another instance.
Strides() noexcept=default
Creates an empty stride vector.
const std::size_t * begin() const noexcept
Returns a const iterator to the first stride value.
void require_index(std::size_t index, std::size_t size, const char *message)
Requires an index to be less than a size.
std::ostream & operator<<(std::ostream &os, const Shape &shape)
Writes a shape to a stream in tuple-like form.