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

Function flatten

cpp/nd/impl/flat_array.hpp:10–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace nd::impl {
9
10inline nd::array flatten(nd::array a)
11{
12 if (a.dimensions() <= 1 && !a.is_dynamic()) {
13 return a;
14 }
15 return nd::switch_numeric_dtype(a.dtype(), [&a]<typename T>() {
16 icm::vector<T> v;
17 v.reserve(a.volume());
18 for (int i = 0; i < a.size(); i++) {
19 auto arr = flatten(a[i]);
20 if (!arr.has_data()) {
21 for (int j = 0; j < arr.volume(); ++j) {
22 v.emplace_back(arr.template value<T>(j));
23 }
24 } else {
25 ASSERT(arr.dtype() == a.dtype());
26 auto d = arr.template data<T>();
27 v.insert(v.end(), d.begin(), d.end());
28 }
29 }
30 return adapt(std::move(v));
31 });
32}
33
34template <typename T>
35class flattened_array

Callers 2

nd_to_pg_typedFunction · 0.85
evalMethod · 0.85

Calls 12

switch_numeric_dtypeFunction · 0.85
adaptFunction · 0.85
dimensionsMethod · 0.45
is_dynamicMethod · 0.45
dtypeMethod · 0.45
reserveMethod · 0.45
volumeMethod · 0.45
sizeMethod · 0.45
has_dataMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected