This commit is contained in:
Awni Hannun 2024-01-15 11:30:24 -08:00
parent 4f50935c2c
commit 6189111494

View File

@ -477,22 +477,26 @@ auto py_compile(const py::function& fun) {
auto inputs = tree_flatten(args, true); auto inputs = tree_flatten(args, true);
// Get globally enclosed arrays so we don't compile through them // Get globally enclosed arrays so we don't compile through them
auto global_inputs = tree_flatten(py::getattr(fun, "__globals__"), false); if (py::hasattr(fun, "__globals__")) {
std::move( auto global_inputs = tree_flatten(py::getattr(fun, "__globals__"), false);
std::begin(global_inputs), std::move(
std::end(global_inputs), std::begin(global_inputs),
std::back_inserter(inputs)); std::end(global_inputs),
std::back_inserter(inputs));
}
// Get locally enclosed arrays so we don't compile through them // Get locally enclosed arrays so we don't compile through them
auto closures = py::getattr(fun, "__closure__"); if (py::hasattr(fun, "__closure__")) {
if (py::isinstance<py::tuple>(closures)) { auto closures = py::getattr(fun, "__closure__");
for (auto& closure : closures) { if (py::isinstance<py::tuple>(closures)) {
auto enclosed_inputs = for (auto& closure : closures) {
tree_flatten(py::getattr(closure, "cell_contents"), false); auto enclosed_inputs =
std::move( tree_flatten(py::getattr(closure, "cell_contents"), false);
std::begin(enclosed_inputs), std::move(
std::end(enclosed_inputs), std::begin(enclosed_inputs),
std::back_inserter(inputs)); std::end(enclosed_inputs),
std::back_inserter(inputs));
}
} }
} }