MCPcopy Create free account
hub / github.com/activeloopai/deeplake / new_to_old_offset

Function new_to_old_offset

cpp/nd/impl/strided_array.hpp:20–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19template <typename I>
20int new_to_old_offset(int new_offset, const icm::shape& old_shape, I begin, I end)
21{
22 icm::small_vector<int> old_strides(old_shape.size(), 1);
23 icm::small_vector<int> new_strides(old_shape.size(), 1);
24 auto os = 1;
25 auto ns = 1;
26 auto distance = std::distance(begin, end);
27 for (auto i = old_shape.size() - 1; i > 0; --i) {
28 os *= old_shape[i];
29 if (i < distance) {
30 ns *= (begin + i)->size();
31 } else {
32 ns *= old_shape[i];
33 }
34 old_strides[i - 1] = os;
35 new_strides[i - 1] = ns;
36 }
37 auto old_offset = 0;
38 I it = begin;
39 for (auto i = 0; i < old_shape.size(); ++i) {
40 if (it != end) {
41 auto ci = (*it)[new_offset / new_strides[i]];
42 if (ci >= old_shape[i]) {
43 throw invalid_operation("Subscript index is out of array bounds.");
44 }
45 old_offset += old_strides[i] * ci;
46 ++it;
47 } else {
48 old_offset += old_strides[i] * (new_offset / new_strides[i]);
49 }
50 new_offset %= new_strides[i];
51 }
52 return old_offset;
53}
54
55template <typename T, typename I>
56class single_strided_array

Callers 2

valueMethod · 0.85
valueMethod · 0.85

Calls 2

invalid_operationClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected