| 98 | size_t TensorSliceView::NumAxes() const { return range_vec_.size(); } |
| 99 | |
| 100 | NdIndex TensorSliceView::OffsetTo(const TensorSliceView& other) const { |
| 101 | CHECK_EQ(other.NumAxes(), NumAxes()); |
| 102 | DimVector indices_vec(range_vec_.size()); |
| 103 | std::transform(range_vec_.cbegin(), range_vec_.cend(), other.range_vec_.cbegin(), |
| 104 | indices_vec.begin(), |
| 105 | [](const Range& lhs, const Range& rhs) { return lhs.begin() - rhs.begin(); }); |
| 106 | return NdIndex(indices_vec); |
| 107 | } |
| 108 | |
| 109 | void TensorSliceView::ToProto(TensorSliceViewProto* proto) const { |
| 110 | for (const Range& range : range_vec_) { range.ToProto(proto->mutable_dim()->Add()); } |