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

Function StridesToLayout

tensorflow/compiler/xla/python/dlpack.cc:165–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165StatusOr<std::vector<int64>> StridesToLayout(absl::Span<int64 const> dims,
166 absl::Span<int64 const> strides) {
167 CHECK_EQ(dims.size(), strides.size());
168 std::vector<int64> minor_to_major(dims.size());
169 std::iota(minor_to_major.begin(), minor_to_major.end(), 0);
170 absl::c_sort(minor_to_major, [&](int a, int b) {
171 if (strides[a] < strides[b]) {
172 return true;
173 }
174 if (strides[a] > strides[b]) {
175 return false;
176 }
177 return dims[a] == 1 && dims[b] != 1;
178 });
179 int64 stride = 1;
180 for (int64 d : minor_to_major) {
181 if (strides[d] != stride) {
182 return Unimplemented(
183 "Only DLPack tensors with trivial (compact) striding are supported; "
184 "i.e., tensors whose striding represents a transposition of the "
185 "underlying buffer but not broadcasting. Dimensions were: [%s], "
186 "strides were [%s].",
187 absl::StrJoin(dims, ","), absl::StrJoin(strides, ","));
188 }
189 stride *= dims[d];
190 }
191 return minor_to_major;
192}
193
194StatusOr<DLDeviceType> DLDeviceTypeForDevice(const Device& device) {
195 const se::Platform* platform =

Callers 1

Calls 4

UnimplementedFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected