MCPcopy Create free account
hub / github.com/ml-explore/mlx / tree_flatten

Function tree_flatten

python/src/trees.cpp:236–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236std::vector<mx::array> tree_flatten(nb::handle tree, bool strict /* = true */) {
237 std::vector<mx::array> flat_tree;
238
239 tree_visit(tree, [&](nb::handle obj) {
240 if (nb::isinstance<mx::array>(obj)) {
241 flat_tree.push_back(nb::cast<mx::array>(obj));
242 } else if (strict) {
243 throw std::invalid_argument(
244 "[tree_flatten] The argument should contain only arrays");
245 }
246 });
247
248 return flat_tree;
249}
250
251nb::object tree_unflatten(
252 nb::object tree,

Callers 7

py_value_and_gradFunction · 0.70
py_vmapFunction · 0.70
call_implMethod · 0.70
operator()Method · 0.70
operator()Method · 0.70
init_transformsFunction · 0.70
init_exportFunction · 0.70

Calls 2

tree_visitFunction · 0.85
push_backMethod · 0.80

Tested by

no test coverage detected