Skip to content

Commit 6508d71

Browse files
committed
chore: wip
1 parent 2b8facb commit 6508d71

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ lint.isort.known-first-party = [ "array_api_jit", "tests" ]
8888
addopts = """\
8989
-v
9090
-Wdefault
91-
--cov=array_api_jit
92-
--cov-report=term
93-
--cov-report=xml
9491
"""
9592
pythonpath = [ "src" ]
9693

src/array_api_jit/main.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# https://github.com/search?q=gumerov+translation+language%3APython&type=code&l=Python
2+
import importlib.util
23
from collections.abc import Mapping, Sequence
34
from functools import cache, wraps
45
from types import ModuleType
@@ -7,23 +8,36 @@
78
from array_api_compat import array_namespace
89
from frozendict import frozendict
910

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+
1023
P = ParamSpec("P")
1124
T = TypeVar("T")
1225

1326

1427
def _default_decorator(
15-
module: ModuleType, /, *args: Any, **kwargs: Any
28+
module: ModuleType,
29+
/,
1630
) -> Callable[[Callable[P, T]], Callable[P, T]]:
1731
if "numpy" in module.__name__:
1832
import numba
1933

20-
return numba.jit(*args, **kwargs)
34+
return numba.jit()
2135
elif "torch" in module.__name__:
2236
import torch
2337

2438
return torch.compile
2539
else:
26-
return getattr(module, "jit", lambda x: x)(*args, **kwargs)
40+
return getattr(module, "jit", lambda x: x)
2741

2842

2943
def jit(
@@ -65,7 +79,7 @@ def jit_cached(xp: ModuleType) -> Callable[P, T]:
6579
if name in decorator_:
6680
decorator_current = decorator_[name]
6781
else:
68-
decorator_current = _default_decorator(xp, *decorator_args_, **decorator_kwargs_)
82+
decorator_current = _default_decorator(xp)
6983

7084
return decorator_current(f, *decorator_args__, **decorator_kwargs__)
7185

tests/test_main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def test_jit(xp: Any) -> None:
10-
@jit(decorator_kwargs={"numpy": {"forceobj": True, "nopython": False}}) # type: ignore
10+
@jit() # type: ignore
1111
def spherical_coordinates(
1212
r: torch.Tensor, theta: torch.Tensor, phi: torch.Tensor
1313
) -> torch.Tensor:
@@ -22,5 +22,4 @@ def spherical_coordinates(
2222
theta = xp.linspace(0, xp.pi, 100)
2323
phi = xp.linspace(0, 2 * xp.pi, 100)
2424
x = spherical_coordinates(r, theta, phi) # type: ignore
25-
print(x.shape)
2625
assert x.shape == (100, 3)

0 commit comments

Comments
 (0)