Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Indexing.hpp File Reference

Unchecked offsets from element strides. More...

#include <cstddef>
#include <stratax/core/Shape.hpp>
Include dependency graph for Indexing.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename IndexContainer >
std::size_t stratax::indexing::offset (const core::Shape &strides, const IndexContainer &indices)
 Computes an unchecked flat offset from strides and normalized indices.
 

Detailed Description

Unchecked offsets from element strides.

Definition in file Indexing.hpp.

Function Documentation

◆ offset()

template<typename IndexContainer >
std::size_t stratax::indexing::offset ( const core::Shape &  strides,
const IndexContainer &  indices 
)

Computes an unchecked flat offset from strides and normalized indices.

Each index is multiplied by the stride for the corresponding dimension, and the products are summed to produce an element offset from the data pointer.

Template Parameters
IndexContainerIterable container of non-negative indices.
Parameters
stridesElement strides, either canonical or a view's custom strides.
indicesOne normalized index for every stride.
Returns
Flat element offset represented by indices.
Precondition
The number of indices equals strides.rank().
Every index is valid for the shape associated with strides.
The products and their sum are representable by std::size_t.
Complexity
O(strides.rank()).

Definition at line 28 of file Indexing.hpp.