mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-16 01:49:05 +08:00
Cycle leak break (#1856)
* detect and break leaks in custom function * detect and break leaks in custom function
This commit is contained in:
24
python/src/mlx_func.h
Normal file
24
python/src/mlx_func.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright © 2025 Apple Inc.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <nanobind/nanobind.h>
|
||||
#include <nanobind/stl/function.h>
|
||||
|
||||
namespace nb = nanobind;
|
||||
using namespace nb::literals;
|
||||
|
||||
nb::callable mlx_func(nb::object func, std::vector<PyObject*> deps);
|
||||
|
||||
template <typename F, typename... Deps>
|
||||
nb::callable mlx_func(F func, Deps&&... deps) {
|
||||
return mlx_func(
|
||||
nb::cpp_function(std::move(func)), std::vector<PyObject*>{deps.ptr()...});
|
||||
}
|
||||
|
||||
template <typename... Deps>
|
||||
nb::callable mlx_func(nb::object func, Deps&&... deps) {
|
||||
return mlx_func(std::move(func), std::vector<PyObject*>{deps.ptr()...});
|
||||
}
|
||||
Reference in New Issue
Block a user