Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
Indexing.hpp File Reference
#include <cstddef>
#include <stratax/core/Exceptions.hpp>
#include <stratax/core/Strides.hpp>
#include <stratax/core/Shape.hpp>
#include <stratax/core/Validation.hpp>

Go to the source code of this file.

Functions

template<typename IndexContainer>
std::size_t offset (const stratax::core::Shape &shape, const stratax::core::Strides &strides, const IndexContainer &index)
 Computes a flat storage offset from a shape, strides, and index container.

Function Documentation

◆ offset()

template<typename IndexContainer>
std::size_t offset ( const stratax::core::Shape & shape,
const stratax::core::Strides & strides,
const IndexContainer & index )

Computes a flat storage offset from a shape, strides, and index container.

Parameters
shapeArray shape.
stridesRow-major or custom strides matching the shape.
indexIndex container with one entry per dimension.
Returns
Flat storage offset.
Exceptions
Exceptions::DimensionErrorIf the ranks do not match.
Exceptions::IndexErrorIf an index is out of bounds or the offset overflows.

Definition at line 23 of file Indexing.hpp.

References stratax::core::Shape::begin(), stratax::core::Strides::begin(), stratax::core::validation::checked_add(), stratax::core::validation::checked_multiply(), stratax::core::Shape::rank(), stratax::core::Strides::rank(), and stratax::core::validation::require_rank().

Referenced by stratax::container::Tensor< U >::at(), stratax::container::Tensor< U >::at(), stratax::container::Tensor< U >::operator()(), stratax::container::Tensor< U >::operator()(), and stratax::container::detail::print_tensor_recursive().