|
1 | 1 | # https://github.com/search?q=gumerov+translation+language%3APython&type=code&l=Python |
| 2 | +import importlib.util |
2 | 3 | from collections.abc import Mapping, Sequence |
3 | 4 | from functools import cache, wraps |
4 | 5 | from types import ModuleType |
|
7 | 8 | from array_api_compat import array_namespace |
8 | 9 | from frozendict import frozendict |
9 | 10 |
|
| 11 | +if importlib.util.find_spec("numba"): |
| 12 | + import numpy as np |
| 13 | + from numba.extending import overload |
| 14 | + |
| 15 | + @overload(array_namespace) |
| 16 | + def _array_namespace_overload(*args: Any) -> Any: |
| 17 | + def inner(*args: Any) -> Any: |
| 18 | + return np |
| 19 | + |
| 20 | + return inner |
| 21 | + |
| 22 | + |
10 | 23 | P = ParamSpec("P") |
11 | 24 | T = TypeVar("T") |
12 | 25 |
|
13 | 26 |
|
14 | 27 | def _default_decorator( |
15 | | - module: ModuleType, /, *args: Any, **kwargs: Any |
| 28 | + module: ModuleType, |
| 29 | + /, |
16 | 30 | ) -> Callable[[Callable[P, T]], Callable[P, T]]: |
17 | 31 | if "numpy" in module.__name__: |
18 | 32 | import numba |
19 | 33 |
|
20 | | - return numba.jit(*args, **kwargs) |
| 34 | + return numba.jit() |
21 | 35 | elif "torch" in module.__name__: |
22 | 36 | import torch |
23 | 37 |
|
24 | 38 | return torch.compile |
25 | 39 | else: |
26 | | - return getattr(module, "jit", lambda x: x)(*args, **kwargs) |
| 40 | + return getattr(module, "jit", lambda x: x) |
27 | 41 |
|
28 | 42 |
|
29 | 43 | def jit( |
@@ -65,7 +79,7 @@ def jit_cached(xp: ModuleType) -> Callable[P, T]: |
65 | 79 | if name in decorator_: |
66 | 80 | decorator_current = decorator_[name] |
67 | 81 | else: |
68 | | - decorator_current = _default_decorator(xp, *decorator_args_, **decorator_kwargs_) |
| 82 | + decorator_current = _default_decorator(xp) |
69 | 83 |
|
70 | 84 | return decorator_current(f, *decorator_args__, **decorator_kwargs__) |
71 | 85 |
|
|
0 commit comments