-
#include "tensorstore/index_interval.h" -
Result<std::pair<OptionallyImplicitIndexInterval, Index>>
tensorstore::ExtractHalfOpenStridedSlice(
OptionallyImplicitIndexInterval orig,
Index start,
Index stop,
Index stride); Extracts a strided half-open interval from a containing interval.
This function is primarily for use by
DimExpression::HalfOpenInterval.The precise definition is as follows:
Sets
adjusted_starttoorig.interval.inclusive_min()ifstride > 0, ororig.interval.inclusive_max()otherwise.Sets
implicit_lower = orig.implicit_lower().
Otherwise (if
start != kImplicit):Sets
adjusted_start = start.Sets
implicit_lower = false.
Sets
adjusted_stoptoorig.interval.inclusive_min()ifstride < 0, ororig.interval.inclusive_max()otherwise.Sets
implicit_upper = orig.implicit_upper().
Otherwise (
stop != kImplicit):Sets
adjusted_stop = stop - sign(stride).Sets
implicit_upper = false.
If
stride > 0:Sets
adjusted_intervalto[adjusted_start, adjusted_stop].
Otherwise (if
stride < 0):Sets
adjusted_intervalto[adjusted_stop, adjusted_start].Swaps
implicit_lowerandimplicit_upper.
Sets
new_inclusive_min = adjusted_start / stride(rounding towards zero).If
adjusted_stop * sign(stride) == kInfIndex:Sets
new_size = kInfIndex + 1 - new_inclusive_min.
Otherwise:
Sets
new_sizeto the maximum positive integer such thatadjusted_start + stride * (new_size - 1)is contained inadjusted_interval.
Sets
new_intervalto be the interval starting atnew_inclusive_minwith a size ofnew_size.Examples:
If
orig = [5, 10],start = 6,stop = 9, andstride = 1, returns[6, 8]withadjusted_start = 6.If
orig = [5*, 10],start = 4,stop = 9, andstride = 1, returns[4, 8]withadjusted_start = 4.If
orig = [5*, 10],start = kImplicit,stop = 9, andstride = 1, returns[5*, 8]withadjusted_start = 5.If
orig = [5, 10],start = 9,stop = 7, andstride = -2, returns[-4, -4]withadjusted_start = 9.- Parameters:¶
- OptionallyImplicitIndexInterval orig¶
The original interval from which to extract a strided slice.
- Index start¶
The index in
origcorresponding to the inclusive_min value in the result interval. If equal tokImplicit, the lower (ifstride > 0) or upper (ifstride < 0) bound oforigis used.- Index stop¶
Specifies the exclusive stop index in
orig. If equal tokImplicit, the upper (ifstride > 0) or lower (ifstride < 0) bound oforigis used.- Index stride¶
Specifies the stride value.
- Returns:¶
{{new_interval, implicit_lower, implicit_upper}, adjusted_start}.- Error absl::StatusCode::kInvalidArgument:¶
if
stride == 0orstride == std::numeric_limits<Index>::min().- Error absl::StatusCode::kInvalidArgument:¶
if
adjusted_intervalis not a valid interval.- Error absl::StatusCode::kOutOfRange:¶
if
adjusted_intervalis not contained withinorig(implicit bounds oforigdo not constrainadjusted_interval).