array-api-jit 0.1.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- array_api_jit/__init__.py +1 -1
- array_api_jit/_main.py +22 -20
- {array_api_jit-0.1.0.dist-info → array_api_jit-1.1.0.dist-info}/METADATA +12 -34
- array_api_jit-1.1.0.dist-info/RECORD +8 -0
- {array_api_jit-0.1.0.dist-info → array_api_jit-1.1.0.dist-info}/WHEEL +1 -1
- array_api_jit-0.1.0.dist-info/RECORD +0 -8
- {array_api_jit-0.1.0.dist-info → array_api_jit-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {array_api_jit-0.1.0.dist-info → array_api_jit-1.1.0.dist-info}/top_level.txt +0 -0
array_api_jit/__init__.py
CHANGED
array_api_jit/_main.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# https://github.com/search?q=gumerov+translation+language%3APython&type=code&l=Python
|
|
2
1
|
import importlib.util
|
|
3
2
|
import warnings
|
|
4
3
|
from collections.abc import Callable, Mapping, Sequence
|
|
@@ -14,15 +13,14 @@ from array_api_compat import (
|
|
|
14
13
|
is_numpy_namespace,
|
|
15
14
|
is_torch_namespace,
|
|
16
15
|
)
|
|
17
|
-
from frozendict import frozendict
|
|
18
16
|
|
|
19
17
|
if importlib.util.find_spec("numba"):
|
|
20
18
|
import numpy as np
|
|
21
19
|
from numba.extending import overload
|
|
22
20
|
|
|
23
21
|
@overload(array_namespace)
|
|
24
|
-
def _array_namespace_overload(*
|
|
25
|
-
def inner(*
|
|
22
|
+
def _array_namespace_overload(*_args: Any) -> Any:
|
|
23
|
+
def inner(*_args: Any) -> Any:
|
|
26
24
|
return np
|
|
27
25
|
|
|
28
26
|
return inner
|
|
@@ -43,6 +41,13 @@ STR_TO_IS_NAMESPACE = {
|
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
|
|
44
|
+
def _identity[**P, T](
|
|
45
|
+
f: Callable[P, T],
|
|
46
|
+
/,
|
|
47
|
+
) -> Callable[P, T]:
|
|
48
|
+
return f
|
|
49
|
+
|
|
50
|
+
|
|
46
51
|
def _default_decorator(
|
|
47
52
|
module: ModuleType,
|
|
48
53
|
/,
|
|
@@ -51,20 +56,19 @@ def _default_decorator(
|
|
|
51
56
|
import jax
|
|
52
57
|
|
|
53
58
|
return jax.jit
|
|
54
|
-
|
|
59
|
+
if is_numpy_namespace(module) or is_cupy_namespace(module):
|
|
55
60
|
# import numba
|
|
56
61
|
|
|
57
62
|
# return numba.jit()
|
|
58
63
|
# The success rate of numba.jit is low
|
|
59
|
-
return
|
|
60
|
-
|
|
64
|
+
return _identity
|
|
65
|
+
if is_torch_namespace(module):
|
|
61
66
|
import torch
|
|
62
67
|
|
|
63
68
|
return torch.compile
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
return getattr(module, "jit", lambda x: x)
|
|
69
|
+
if is_dask_namespace(module):
|
|
70
|
+
return _identity
|
|
71
|
+
return getattr(module, "jit", _identity)
|
|
68
72
|
|
|
69
73
|
|
|
70
74
|
Decorator = Callable[[Callable[Pin, Tin]], Callable[Pin, Tin]]
|
|
@@ -122,9 +126,11 @@ def jit(
|
|
|
122
126
|
|
|
123
127
|
"""
|
|
124
128
|
|
|
125
|
-
def new_decorator(
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
def new_decorator(
|
|
130
|
+
f: Callable[Pinner, Tinner],
|
|
131
|
+
) -> Callable[Pinner, Tinner]:
|
|
132
|
+
decorator_args_ = decorator_args or {}
|
|
133
|
+
decorator_kwargs_ = decorator_kwargs or {}
|
|
128
134
|
decorator_ = decorator or {}
|
|
129
135
|
|
|
130
136
|
@cache
|
|
@@ -132,14 +138,10 @@ def jit(
|
|
|
132
138
|
for name_, is_namespace in STR_TO_IS_NAMESPACE.items():
|
|
133
139
|
if is_namespace(xp):
|
|
134
140
|
name = name_
|
|
135
|
-
|
|
136
|
-
name = xp.__name__.split(".")[0]
|
|
141
|
+
name = xp.__name__.split(".")[0]
|
|
137
142
|
decorator_args__ = decorator_args_.get(name, ())
|
|
138
143
|
decorator_kwargs__ = decorator_kwargs_.get(name, {})
|
|
139
|
-
if name in decorator_
|
|
140
|
-
decorator_current = decorator_[name]
|
|
141
|
-
else:
|
|
142
|
-
decorator_current = _default_decorator(xp)
|
|
144
|
+
decorator_current = decorator_[name] if name in decorator_ else _default_decorator(xp)
|
|
143
145
|
try:
|
|
144
146
|
return decorator_current(f, *decorator_args__, **decorator_kwargs__)
|
|
145
147
|
except Exception as e:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: array-api-jit
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: JIT decorator supporting multiple array API compatible libraries
|
|
5
|
-
Author
|
|
6
|
-
License: MIT
|
|
5
|
+
Author: 34j
|
|
6
|
+
License-Expression: MIT
|
|
7
7
|
Project-URL: Bug Tracker, https://github.com/34j/array-api-jit/issues
|
|
8
8
|
Project-URL: Changelog, https://github.com/34j/array-api-jit/blob/main/CHANGELOG.md
|
|
9
9
|
Project-URL: documentation, https://array-api-jit.readthedocs.io
|
|
@@ -12,17 +12,15 @@ Classifier: Development Status :: 2 - Pre-Alpha
|
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
13
|
Classifier: Natural Language :: English
|
|
14
14
|
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
19
|
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
License-File: LICENSE
|
|
23
23
|
Requires-Dist: array-api-compat>=1.11.2
|
|
24
|
-
Requires-Dist: cm-time>=0.1.2
|
|
25
|
-
Requires-Dist: frozendict>=2.4.6
|
|
26
24
|
Dynamic: license-file
|
|
27
25
|
|
|
28
26
|
# array API JIT
|
|
@@ -34,19 +32,19 @@ Dynamic: license-file
|
|
|
34
32
|
<a href="https://array-api-jit.readthedocs.io">
|
|
35
33
|
<img src="https://img.shields.io/readthedocs/array-api-jit.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
|
|
36
34
|
</a>
|
|
35
|
+
</p>
|
|
36
|
+
<p align="center">
|
|
37
37
|
<a href="https://codecov.io/gh/34j/array-api-jit">
|
|
38
38
|
<img src="https://img.shields.io/codecov/c/github/34j/array-api-jit.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
|
|
39
39
|
</a>
|
|
40
|
-
</p>
|
|
41
|
-
<p align="center">
|
|
42
40
|
<a href="https://github.com/astral-sh/uv">
|
|
43
41
|
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
|
|
44
42
|
</a>
|
|
45
43
|
<a href="https://github.com/astral-sh/ruff">
|
|
46
44
|
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
|
|
47
45
|
</a>
|
|
48
|
-
<a href="https://github.com/
|
|
49
|
-
<img src="https://img.shields.io/
|
|
46
|
+
<a href="https://github.com/j178/prek">
|
|
47
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json" alt="prek">
|
|
50
48
|
</a>
|
|
51
49
|
</p>
|
|
52
50
|
<p align="center">
|
|
@@ -80,6 +78,8 @@ pip install array-api-jit
|
|
|
80
78
|
Simply decorate your function with `@jit()`:
|
|
81
79
|
|
|
82
80
|
```python
|
|
81
|
+
from typing import Any
|
|
82
|
+
|
|
83
83
|
from array_api_jit import jit
|
|
84
84
|
|
|
85
85
|
|
|
@@ -114,25 +114,3 @@ def sin_n_times(x: Any, n: int) -> Any:
|
|
|
114
114
|
x = xp.sin(x)
|
|
115
115
|
return x
|
|
116
116
|
```
|
|
117
|
-
|
|
118
|
-
## Contributors ✨
|
|
119
|
-
|
|
120
|
-
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
121
|
-
|
|
122
|
-
<!-- prettier-ignore-start -->
|
|
123
|
-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
124
|
-
<!-- markdownlint-disable -->
|
|
125
|
-
<!-- markdownlint-enable -->
|
|
126
|
-
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
127
|
-
<!-- prettier-ignore-end -->
|
|
128
|
-
|
|
129
|
-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
|
130
|
-
|
|
131
|
-
## Credits
|
|
132
|
-
|
|
133
|
-
[](https://github.com/copier-org/copier)
|
|
134
|
-
|
|
135
|
-
This package was created with
|
|
136
|
-
[Copier](https://copier.readthedocs.io/) and the
|
|
137
|
-
[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
|
|
138
|
-
project template.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
array_api_jit/__init__.py,sha256=6Cd5sMzZMC4jIJ97HL2eYIS8scDQonRkgK-uT221w_w,64
|
|
2
|
+
array_api_jit/_main.py,sha256=5cjXZOyAl_m1NAE9YNUWD-wORnozj9GUl7gpEpq_UsI,5854
|
|
3
|
+
array_api_jit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
array_api_jit-1.1.0.dist-info/licenses/LICENSE,sha256=Otwb96xcK4QBqXXVdBKpLZVnc4mJuFTa8rsMUEpphMM,1061
|
|
5
|
+
array_api_jit-1.1.0.dist-info/METADATA,sha256=Bks5iWQ_K91J7ktOSungqKarAt-VeVLHhiHwcGEKM88,4265
|
|
6
|
+
array_api_jit-1.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
array_api_jit-1.1.0.dist-info/top_level.txt,sha256=90tmkew6kqpBt5VZbfvK2cvsOfCn_oFZfDf74F-s7Hg,14
|
|
8
|
+
array_api_jit-1.1.0.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
array_api_jit/__init__.py,sha256=ex_A2mp0ZTg3y3hvbNxj9s75gW1FL1eLhbd7JPUa-ic,64
|
|
2
|
-
array_api_jit/_main.py,sha256=m_pgnGiMGtHT6eFKTTIGFV2tl7fLwWeyvEQPpIyVSeo,6007
|
|
3
|
-
array_api_jit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
array_api_jit-0.1.0.dist-info/licenses/LICENSE,sha256=Otwb96xcK4QBqXXVdBKpLZVnc4mJuFTa8rsMUEpphMM,1061
|
|
5
|
-
array_api_jit-0.1.0.dist-info/METADATA,sha256=spw7X8EcB6K6YYxTHVyNo4qLd9jd7O_icFRw91BaFrM,5237
|
|
6
|
-
array_api_jit-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
array_api_jit-0.1.0.dist-info/top_level.txt,sha256=90tmkew6kqpBt5VZbfvK2cvsOfCn_oFZfDf74F-s7Hg,14
|
|
8
|
-
array_api_jit-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|