-
#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:
Sets
adjusted_starttoorig.interval.inclusive_min()ifstride > 0, ororig.interval.inclusive_max()otherwise.Sets
implicit_lower = orig.implicit_lower().
Sets
new_inclusive_min = adjusted_start / stride(rounding towards zero).Sets
new_size = size.
Otherwise (if
size == kImplicit):Sets
new_sizeto the maximum positive integer such thatContains(orig.interval, adjusted_start + stride * (new_size - 1)), or0if there is no such integer (can only occur iforig.size() == 0).
If
stride < 0, swapsimplicit_lowerandimplicit_upper.Sets
new_intervalto be the interval starting atnew_inclusive_minwith a size ofnew_size.Examples
If
orig = [5, 10],start = 9,stop_or_size = 3, andstride = -2, returns[-4, -2]withadjusted_start = 9.- Parameters:¶
- OptionallyImplicitIndexInterval orig¶
The original interval from which to extract a strided slice.
- Index start¶
The index within
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 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 == 0orstride == std::numeric_limits<Index>::min().- Error absl::StatusCode::kInvalidArgument:¶
if
size < 0.- Error absl::StatusCode::kOutOfRange:¶
if
new_size > 0andorigdoes not containadjusted_start + stride * (new_size - 1)(implicit bounds oforigare not constraints).