#include "tensorstore/index_space/dimension_identifier.h"
struct tensorstore::DimRangeSpec;

Represents a range of dimension indices.

Equal to *inclusive_start + i * step for i = 0, 1, ..., where *inclusive_start + i * step < *exclusive_stop if step > 0 and *inclusive_start + i * step > *exclusive_stop if step < 0.

A DimRangeSpec can be used to specify both existing dimensions as well as dimensions to be added. However, when specifying dimensions to be added and the final rank is to be inferred from the dimension selection itself, certain forms of DimRangeSpec are disallowed because they do not permit the final rank to be inferred. For example:

  • DimRangeSpec{-3, std::nullopt, 1} unambiguously specifies the last 3 dimensions, and can be used to add 3 new trailing dimensions.

  • DimRangeSpec{std::nullopt, 4, 1} unambiguously specifies the first 3 dimensions, and can be used to add 3 new leading dimensions.

  • DimRangeSpec{1, -2, 1} specifies dimensions 1 up to but not including the second from the last. It cannot be used to infer the final rank when adding new dimensions.

Data members

std::optional<DimensionIndex> inclusive_start;

Inclusive start index.

std::optional<DimensionIndex> exclusive_stop;

Exclusive stop index.

DimensionIndex step = 1;

Step size, must not equal 0.

Friend functions

friend std::ostream&
operator<<(std::ostreamosconst DimRangeSpecspec);

Returns a Python-style inclusive_start:inclusive_stop or inclusive_start:exclusive_stop:step slice expression, where inclusive_start and exclusive_stop are omitted if equal to std::nullopt and step is omitted if equal to 1.

friend bool operator==(const DimRangeSpecaconst DimRangeSpecb);
friend bool operator!=(const DimRangeSpecaconst DimRangeSpecb);

Compares two DimRangeSpec objects for equality.

absl::Status
tensorstore::NormalizeDimRangeSpec(const DimRangeSpecspec,
                                   
DimensionIndex rank,
                                   
DimensionIndexBufferresult);

Appends to *result the dimensions corresponding to spec.