MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Slice

Method Slice

tensorflow/compiler/xla/array.h:446–468  ·  view source on GitHub ↗

Performs the equivalent of a slice operation on this array.

Source from the content-addressed store, hash-verified

444
445 // Performs the equivalent of a slice operation on this array.
446 Array<T> Slice(absl::Span<const int64> starts,
447 absl::Span<const int64> limits) const {
448 CHECK_EQ(starts.size(), num_dimensions());
449 CHECK_EQ(limits.size(), num_dimensions());
450
451 std::vector<int64> sizes;
452 std::transform(starts.begin(), starts.end(), limits.begin(),
453 std::back_inserter(sizes),
454 [](int64 start, int64 limit) { return limit - start; });
455 Array<T> result(sizes);
456
457 std::vector<int64> index(sizes_.size());
458 int64 slice_i = 0;
459 for (int64 i = 0; i < num_elements(); ++i, next_index(&index)) {
460 if (array_impl::all_inside_range(index, starts, limits)) {
461 // Even though the bounds of result are different to our bounds, we're
462 // iterating in the same order. So we can simply write successive linear
463 // indices instead of recalculating a multi-dimensional index.
464 result.values_[slice_i++] = values_[i];
465 }
466 }
467 return result;
468 }
469
470 // Performs the equivalent of a DynamicUpdateSlice in-place on this array.
471 void UpdateSlice(const Array<T>& from,

Callers

nothing calls this directly

Calls 5

all_inside_rangeFunction · 0.85
transformFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected