Performs the equivalent of a DynamicUpdateSlice in-place on this array.
| 469 | |
| 470 | // Performs the equivalent of a DynamicUpdateSlice in-place on this array. |
| 471 | void UpdateSlice(const Array<T>& from, |
| 472 | absl::Span<const int64> start_indices) { |
| 473 | CHECK_EQ(from.num_dimensions(), num_dimensions()); |
| 474 | std::vector<int64> limit_indices; |
| 475 | std::transform(start_indices.begin(), start_indices.end(), |
| 476 | from.dimensions().begin(), std::back_inserter(limit_indices), |
| 477 | std::plus<int64>{}); |
| 478 | std::vector<int64> index(sizes_.size()); |
| 479 | int64 from_i = 0; |
| 480 | for (int64 i = 0; i < num_elements(); ++i, next_index(&index)) { |
| 481 | if (array_impl::all_inside_range(index, start_indices, limit_indices)) { |
| 482 | // Even though the bounds of from are different to our bounds, we're |
| 483 | // iterating in the same order. So we can simply write successive linear |
| 484 | // indices instead of recalculating a multi-dimensional index. |
| 485 | values_[i] = from.values_[from_i++]; |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | // Performs an in-place reshape, modifying the dimensions but not the |
| 491 | // underlying data. |