Tannic
A C++ Tensor Library
|
Classes | |
struct | Range |
Represents a half-open interval [start, stop) for slicing. More... | |
Functions | |
template<Integral Index, Integral Size> | |
constexpr Index | normalize (Index index, Size bound) |
Normalize a possibly-negative index into the valid range [0, bound) . | |
template<Integral Size> | |
constexpr Range | normalize (Range range, Size size) |
Normalize a slicing range into valid [start, stop) indices. | |
|
inlineconstexpr |
Normalize a possibly-negative index into the valid range [0, bound)
.
Index | Integral type of the index |
Size | Integral type of the bound |
index | Index to normalize (may be negative, counting from the end) |
bound | Upper bound (dimension size) |
Assertion | failure if the normalized index is out of bounds |
This function is used internally by the tensor library when processing indexing operations. It allows Python-like negative indices, where -1
refers to the last element of a dimension, -2
the second-to-last, etc.
tensor[i]
) and slicing operations.
|
inlineconstexpr |
Normalize a slicing range into valid [start, stop)
indices.
Size | Integral type of the dimension size |
range | A possibly-negative Range |
size | Size of the dimension being indexed |
Range
with non-negative, normalized indicesThis function is used internally by the tensor library when converting user-provided slicing ranges into valid [start, stop)
intervals. Negative start
and stop
values are supported and are interpreted relative to the end of the dimension:
start = -1
→ last elementstop = -1
→ one-past-the-endtannic::range{}
or slicing syntax; this function ensures those inputs are mapped into safe, non-negative indices before evaluation.