File size: 759 Bytes
712dbf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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,
    const nb::callable& orig_func,
    std::vector<PyObject*> deps);

template <typename F, typename... Deps>
nb::callable mlx_func(F func, const nb::callable& orig_func, Deps&&... deps) {
  return mlx_func(
      nb::cpp_function(std::move(func)),
      orig_func,
      std::vector<PyObject*>{deps.ptr()...});
}

template <typename... Deps>
nb::callable
mlx_func(nb::object func, const nb::callable& orig_func, Deps&&... deps) {
  return mlx_func(
      std::move(func), orig_func, std::vector<PyObject*>{deps.ptr()...});
}