7#include "nforge/core/tensor_shape.h"
17 std::array<size_t, MAX_DIMS>
shape;
47 TensorLayout(std::array<size_t, MAX_DIMS> _shape, std::array<size_t, MAX_DIMS> _strides,
48 size_t _offset,
size_t _rank);
58static inline size_t physicalOffset(
size_t linear,
const TensorLayout& L) {
60 for (
int d = L.
rank - 1; d >= 0; d--) {
61 std::lldiv_t results = std::lldiv((
long long)linear, (
long long)L.
shape[d]);
63 linear = results.quot;
64 off += results.rem * L.
strides[d];
Definition tensor_shape.h:15
Definition tensor_layout.h:15
size_t rank
Number of active dimensions.
Definition tensor_layout.h:26
bool operator==(const TensorLayout &rhs) const
True if layouts have equal rank, offset, and active shape/stride entries.
Definition tensor_layout.cpp:42
bool operator!=(const TensorLayout &rhs) const
Negation of operator==.
Definition tensor_layout.cpp:58
std::array< size_t, MAX_DIMS > shape
Shape extent per dimension. Only first rank entries active.
Definition tensor_layout.h:17
size_t offset
Storage offset before indexing begins.
Definition tensor_layout.h:23
TensorLayout()
Default constructor. Rank and offset are zero.
Definition tensor_layout.h:29
std::array< size_t, MAX_DIMS > strides
Stride (element count) per dimension. Only first rank entries active.
Definition tensor_layout.h:20