#include "tensorstore/index_space/dimension_identifier.h"
Result<DimensionIndex>
tensorstore::NormalizeDimensionIndex(DimensionIndex index,
                                     
DimensionIndex rank);

Normalizes a dimension index in the range (-rank, rank) to the range [0, rank).

Parameters:
DimensionIndex index

The dimension index to normalize. A negative index value is equivalent to index + rank (effectively counts from the last dimension).

DimensionIndex rank

The rank of the index space.

Pre:

rank >= 0

Returns:

index >= 0 ? index : index + rank.

Error absl::StatusCode::kInvalidArgument:

if index is outside [-rank, rank).