#include "tensorstore/index_interval.h"
Result<std::pair<OptionallyImplicitIndexInterval, Index>>
tensorstore::ExtractSizedStridedSlice(
    
OptionallyImplicitIndexInterval orig,
    
Index start,
    
Index size,
    
Index stride);

Extracts a strided interval of the specified size from a containing interval.

This function is primarily for use by DimExpression::SizedInterval.

The precise definition is as follows:

If start == kImplicit:

  • Sets adjusted_start to orig.interval.inclusive_min() if stride > 0, or orig.interval.inclusive_max() otherwise.

  • Sets implicit_lower = orig.implicit_lower().

Otherwise (if start != kImplicit):

Sets adjusted_start = start. Sets implicit_lower = false.

Sets new_inclusive_min = adjusted_start / stride (rounding towards zero).

If size != kImplicit:

  • Sets new_size = size.

Otherwise (if size == kImplicit):

  • Sets new_size to the maximum positive integer such that Contains(orig.interval, adjusted_start + stride * (new_size - 1)), or 0 if there is no such integer (can only occur if orig.size() == 0).

If stride < 0, swaps implicit_lower and implicit_upper.

Sets new_interval to be the interval starting at new_inclusive_min with a size of new_size.

Examples

If orig = [5, 10], start = 9, stop_or_size = 3, and stride = -2, returns [-4, -2] with adjusted_start = 9.

Parameters:
OptionallyImplicitIndexInterval orig

The original interval from which to extract a strided slice.

Index start

The index within orig corresponding to the inclusive_min value in the result interval. If equal to kImplicit, the lower (if stride > 0) or upper (if stride < 0) bound of orig is used.

Index size

Specifies the size of the result interval.

Index stride

Specifies the stride value.

Returns:

{{new_interval, implicit_lower, implicit_upper}, adjusted_start}.

Error absl::StatusCode::kInvalidArgument:

if stride == 0 or stride == std::numeric_limits<Index>::min().

Error absl::StatusCode::kInvalidArgument:

if size < 0.

Error absl::StatusCode::kOutOfRange:

if new_size > 0 and orig does not contain adjusted_start + stride * (new_size - 1) (implicit bounds of orig are not constraints).