89 static constexpr uint8_t
limit = 8;
115 : sizes_{
static_cast<size_type>(sizes)...}
116 , rank_(
sizeof...(sizes)) {
118 throw Exception(
"Strides rank limit exceeded");
137 template<Iterator Iterator>
140 for (
auto iterator =
begin; iterator !=
end; ++iterator) {
141 assert(dimension <
limit &&
"Strides rank limit exceeded");
142 sizes_[dimension++] =
static_cast<size_type>(*iterator);
146 throw Exception(
"Strides rank limit exceeded");
162 rank_ = shape.
rank();
163 if (rank_ == 0)
return;
165 sizes_[rank_ - 1] = 1;
166 for (
int size = rank_ - 2; size >= 0; --size) {
167 sizes_[size] = sizes_[size + 1] * shape[size + 1];
170 throw Exception(
"Strides rank limit exceeded");
179 return sizes_.data();
187 return sizes_.data();
194 constexpr auto rank() const noexcept {
201 return sizes_.begin();
205 return sizes_.begin() + rank_;
209 return sizes_.begin();
212 constexpr auto end()
const {
213 return sizes_.begin() + rank_;
217 return sizes_.cbegin();
221 return sizes_.cbegin() + rank_;
230 return sizes_.front();
238 return sizes_[rank_];
247 template<Integral Index>
258 template<Integral Index>
268 if (rank_ + 1 >
limit)
269 throw Exception(
"Strides rank limit exceeded");
270 sizes_[rank_] = size;
276 std::array<size_type, limit> sizes_{};
284 if (first.
rank() != second.
rank())
return false;
286 if (first[dimension] != second[dimension])
return false;
294 os << static_cast<unsigned int>(strides[dimension]);
295 if (dimension + 1 < strides.
rank()) {
A simple generic exception type for the Tannic Tensor Library.
Definition: exceptions.hpp:44
Represents the shape (dimensions) of an tensor-like expression.
Definition: shape.hpp:79
constexpr rank_type rank() const noexcept
Returns the number of dimensions (rank).
Definition: shape.hpp:207
Represents the memory strides associated with a tensor shape.
Definition: strides.hpp:87
static constexpr uint8_t limit
Definition: strides.hpp:89
constexpr auto cend() const
Definition: strides.hpp:220
constexpr auto const & operator[](Index index) const
Accesses a stride value by index (const).
Definition: strides.hpp:248
constexpr auto begin()
Definition: strides.hpp:200
constexpr auto end() const
Definition: strides.hpp:212
constexpr size_type * address() noexcept
Returns a pointer to the underlying data (non-const).
Definition: strides.hpp:178
constexpr auto rank() const noexcept
Returns the number of dimensions (rank).
Definition: strides.hpp:194
constexpr auto cbegin() const
Definition: strides.hpp:216
constexpr size_type const * address() const noexcept
Returns a pointer to the underlying data (const).
Definition: strides.hpp:186
uint8_t rank_type
Type used for rank (number of dimensions).
Definition: strides.hpp:92
constexpr Strides(const Shape &shape)
Constructs strides from a shape assuming row-major layout.
Definition: strides.hpp:161
constexpr auto front() const
Returns the first stride value.
Definition: strides.hpp:229
constexpr auto & operator[](Index index)
Accesses a stride value by index (non-const).
Definition: strides.hpp:259
constexpr Strides(Iterator begin, Iterator end)
Constructs strides from a pair of iterators.
Definition: strides.hpp:138
constexpr void expand(size_type size)
Expands the strides's last dimension with a given size.
Definition: strides.hpp:267
constexpr auto begin() const
Definition: strides.hpp:208
constexpr auto back() const
Returns the last stride value.
Definition: strides.hpp:237
int64_t size_type
Type used for size and shape dimensions.
Definition: strides.hpp:93
constexpr auto end()
Definition: strides.hpp:204
constexpr Strides() noexcept=default
Default constructor (rank 0).
Requires a type to be an integral type (e.g., int, std::size_t).
Definition: concepts.hpp:147
Requires a type to satisfy the C++20 std::input_iterator concept.
Definition: concepts.hpp:140
constexpr Index normalize(Index index, Size bound)
Normalize a possibly-negative index into the valid range [0, bound).
Definition: indexing.hpp:87
Definition: buffer.hpp:41
std::ostream & operator<<(std::ostream &os, Shape const &shape)
Definition: shape.hpp:313