Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Indexing.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <cstddef>
7
9
10namespace stratax::indexing {
11
27template<typename IndexContainer>
28std::size_t offset(
29 const core::Shape& strides,
30 const IndexContainer& indices)
31{
32 std::size_t result = 0;
33
34 auto stride_it = strides.begin();
35
36 for (const auto index : indices)
37 {
38 result += index * *stride_it;
39 ++stride_it;
40 }
41
42 return result;
43}
44
45} // namespace stratax::indexing
std::size_t offset(const core::Shape &strides, const IndexContainer &indices)
Computes an unchecked flat offset from strides and normalized indices.
Definition Indexing.hpp:28
Immutable dimension metadata and checked row-major strides.
Stores the dimensions of a multidimensional array.
Definition Shape.hpp:36
const_iterator begin() const noexcept
Returns a const iterator to the first dimension.
Definition Shape.hpp:227