cunumpy 0.1.4__tar.gz → 0.1.5__tar.gz
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.
- cunumpy-0.1.5/PKG-INFO +155 -0
- cunumpy-0.1.5/README.md +115 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/pyproject.toml +4 -3
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/__init__.py +4 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/__init__.pyi +2 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/kernel.py +4 -1
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/xp.py +28 -0
- cunumpy-0.1.5/src/cunumpy.egg-info/PKG-INFO +155 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy.egg-info/requires.txt +5 -2
- cunumpy-0.1.4/PKG-INFO +0 -93
- cunumpy-0.1.4/README.md +0 -55
- cunumpy-0.1.4/src/cunumpy.egg-info/PKG-INFO +0 -93
- {cunumpy-0.1.4 → cunumpy-0.1.5}/setup.cfg +0 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/main.py +0 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy/py.typed +0 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy.egg-info/SOURCES.txt +0 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy.egg-info/dependency_links.txt +0 -0
- {cunumpy-0.1.4 → cunumpy-0.1.5}/src/cunumpy.egg-info/top_level.txt +0 -0
cunumpy-0.1.5/PKG-INFO
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cunumpy
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
5
|
+
Author: Max
|
|
6
|
+
Project-URL: Source, https://github.com/max-models/cunumpy
|
|
7
|
+
Keywords: python
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: array-api-compat
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: black[jupyter]; extra == "dev"
|
|
22
|
+
Requires-Dist: isort; extra == "dev"
|
|
23
|
+
Requires-Dist: cunumpy[docs,test-compiled]; extra == "dev"
|
|
24
|
+
Provides-Extra: docs
|
|
25
|
+
Requires-Dist: ipykernel; extra == "docs"
|
|
26
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
27
|
+
Requires-Dist: nbconvert; extra == "docs"
|
|
28
|
+
Requires-Dist: nbsphinx; extra == "docs"
|
|
29
|
+
Requires-Dist: jupyterlab; extra == "docs"
|
|
30
|
+
Requires-Dist: pre-commit; extra == "docs"
|
|
31
|
+
Requires-Dist: pyproject-fmt; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinx-book-theme; extra == "docs"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: coverage; extra == "test"
|
|
36
|
+
Requires-Dist: pytest; extra == "test"
|
|
37
|
+
Provides-Extra: test-compiled
|
|
38
|
+
Requires-Dist: cunumpy[test]; extra == "test-compiled"
|
|
39
|
+
Requires-Dist: pyccel; extra == "test-compiled"
|
|
40
|
+
|
|
41
|
+
# CuNumpy
|
|
42
|
+
|
|
43
|
+
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
44
|
+
|
|
45
|
+
# Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install cunumpy
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Example usage:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
export ARRAY_BACKEND=cupy
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import cunumpy as xp
|
|
59
|
+
|
|
60
|
+
xp.set_backend("cupy")
|
|
61
|
+
|
|
62
|
+
arr = xp.array([1, 2])
|
|
63
|
+
|
|
64
|
+
print(f"{type(arr) = }")
|
|
65
|
+
print(f"{xp.__version__ = }")
|
|
66
|
+
|
|
67
|
+
# Convert to NumPy
|
|
68
|
+
arr_np = xp.to_numpy(arr)
|
|
69
|
+
|
|
70
|
+
# Convert to active backend
|
|
71
|
+
arr_xp = xp.to_cunumpy(arr)
|
|
72
|
+
|
|
73
|
+
# Inspect backend
|
|
74
|
+
print(f"{xp.get_backend(arr) = }")
|
|
75
|
+
print(f"{xp.is_gpu(arr) = }")
|
|
76
|
+
print(f"{xp.is_cpu(arr) = }")
|
|
77
|
+
|
|
78
|
+
# Temporarily switch backend
|
|
79
|
+
with xp.use_backend("numpy"):
|
|
80
|
+
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
81
|
+
arr_cpu = xp.zeros(100)
|
|
82
|
+
|
|
83
|
+
# Set backend globally
|
|
84
|
+
xp.set_backend("cupy")
|
|
85
|
+
|
|
86
|
+
# Synchronize GPU operations (no-op on CPU)
|
|
87
|
+
xp.synchronize()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Output:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
type(arr) = <class 'cupy.ndarray'>
|
|
94
|
+
xp.__version__ = '0.1.4'
|
|
95
|
+
xp.get_backend(arr) = 'cupy'
|
|
96
|
+
xp.is_gpu(arr) = True
|
|
97
|
+
xp.is_cpu(arr) = False
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# Pyodide
|
|
101
|
+
|
|
102
|
+
cuNumPy supports Pyodide with the NumPy backend. In an initialized Pyodide
|
|
103
|
+
JavaScript runtime, install the package and run a Python-source kernel:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
await pyodide.loadPackage("micropip");
|
|
107
|
+
await pyodide.runPythonAsync(`
|
|
108
|
+
import micropip
|
|
109
|
+
await micropip.install("cunumpy")
|
|
110
|
+
|
|
111
|
+
import cunumpy as xp
|
|
112
|
+
xp.set_backend("numpy")
|
|
113
|
+
|
|
114
|
+
def scale(values, factor):
|
|
115
|
+
values[:] *= factor
|
|
116
|
+
return values
|
|
117
|
+
|
|
118
|
+
values = xp.array([1.0, 2.0, 3.0])
|
|
119
|
+
result = xp.PyccelKernel(scale)(values, 2.0)
|
|
120
|
+
assert result is values
|
|
121
|
+
print(xp.to_numpy(result)) # [2. 4. 6.]
|
|
122
|
+
`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
NumPy is the default backend when `ARRAY_BACKEND` is unset. CuPy/CUDA and
|
|
126
|
+
native Pyccel compilation are not supported in Pyodide. Despite its name,
|
|
127
|
+
`PyccelKernel` accepts ordinary Python callables and neither imports Pyccel nor
|
|
128
|
+
compiles code. Applications must supply Python-source kernels with
|
|
129
|
+
Pyodide-compatible imports.
|
|
130
|
+
|
|
131
|
+
CI tests the built wheel in Pyodide's WebAssembly runtime under Node.js, including
|
|
132
|
+
array operations, conversions, mutation/aliasing, backend context restoration,
|
|
133
|
+
and Python kernels, while rejecting CuPy or Pyccel imports. This does not test
|
|
134
|
+
browser-specific integration such as page loading or workers. See the
|
|
135
|
+
[Pyodide guide](docs/source/pyodide.md) for details and local test commands.
|
|
136
|
+
|
|
137
|
+
# Development tests
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install -e '.[test]'
|
|
141
|
+
pytest tests/portable
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The `test` extra is compiler-free. For compiled-kernel tests, install
|
|
145
|
+
`'.[test-compiled]'` and a working native compiler, then run `pytest`.
|
|
146
|
+
The `dev` extra includes these compiled-test dependencies as before.
|
|
147
|
+
|
|
148
|
+
# Build docs
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
make html
|
|
153
|
+
cd ../
|
|
154
|
+
open docs/_build/html/index.html
|
|
155
|
+
```
|
cunumpy-0.1.5/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# CuNumpy
|
|
2
|
+
|
|
3
|
+
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
4
|
+
|
|
5
|
+
# Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install cunumpy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Example usage:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
export ARRAY_BACKEND=cupy
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import cunumpy as xp
|
|
19
|
+
|
|
20
|
+
xp.set_backend("cupy")
|
|
21
|
+
|
|
22
|
+
arr = xp.array([1, 2])
|
|
23
|
+
|
|
24
|
+
print(f"{type(arr) = }")
|
|
25
|
+
print(f"{xp.__version__ = }")
|
|
26
|
+
|
|
27
|
+
# Convert to NumPy
|
|
28
|
+
arr_np = xp.to_numpy(arr)
|
|
29
|
+
|
|
30
|
+
# Convert to active backend
|
|
31
|
+
arr_xp = xp.to_cunumpy(arr)
|
|
32
|
+
|
|
33
|
+
# Inspect backend
|
|
34
|
+
print(f"{xp.get_backend(arr) = }")
|
|
35
|
+
print(f"{xp.is_gpu(arr) = }")
|
|
36
|
+
print(f"{xp.is_cpu(arr) = }")
|
|
37
|
+
|
|
38
|
+
# Temporarily switch backend
|
|
39
|
+
with xp.use_backend("numpy"):
|
|
40
|
+
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
41
|
+
arr_cpu = xp.zeros(100)
|
|
42
|
+
|
|
43
|
+
# Set backend globally
|
|
44
|
+
xp.set_backend("cupy")
|
|
45
|
+
|
|
46
|
+
# Synchronize GPU operations (no-op on CPU)
|
|
47
|
+
xp.synchronize()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Output:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
type(arr) = <class 'cupy.ndarray'>
|
|
54
|
+
xp.__version__ = '0.1.4'
|
|
55
|
+
xp.get_backend(arr) = 'cupy'
|
|
56
|
+
xp.is_gpu(arr) = True
|
|
57
|
+
xp.is_cpu(arr) = False
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
# Pyodide
|
|
61
|
+
|
|
62
|
+
cuNumPy supports Pyodide with the NumPy backend. In an initialized Pyodide
|
|
63
|
+
JavaScript runtime, install the package and run a Python-source kernel:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
await pyodide.loadPackage("micropip");
|
|
67
|
+
await pyodide.runPythonAsync(`
|
|
68
|
+
import micropip
|
|
69
|
+
await micropip.install("cunumpy")
|
|
70
|
+
|
|
71
|
+
import cunumpy as xp
|
|
72
|
+
xp.set_backend("numpy")
|
|
73
|
+
|
|
74
|
+
def scale(values, factor):
|
|
75
|
+
values[:] *= factor
|
|
76
|
+
return values
|
|
77
|
+
|
|
78
|
+
values = xp.array([1.0, 2.0, 3.0])
|
|
79
|
+
result = xp.PyccelKernel(scale)(values, 2.0)
|
|
80
|
+
assert result is values
|
|
81
|
+
print(xp.to_numpy(result)) # [2. 4. 6.]
|
|
82
|
+
`);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
NumPy is the default backend when `ARRAY_BACKEND` is unset. CuPy/CUDA and
|
|
86
|
+
native Pyccel compilation are not supported in Pyodide. Despite its name,
|
|
87
|
+
`PyccelKernel` accepts ordinary Python callables and neither imports Pyccel nor
|
|
88
|
+
compiles code. Applications must supply Python-source kernels with
|
|
89
|
+
Pyodide-compatible imports.
|
|
90
|
+
|
|
91
|
+
CI tests the built wheel in Pyodide's WebAssembly runtime under Node.js, including
|
|
92
|
+
array operations, conversions, mutation/aliasing, backend context restoration,
|
|
93
|
+
and Python kernels, while rejecting CuPy or Pyccel imports. This does not test
|
|
94
|
+
browser-specific integration such as page loading or workers. See the
|
|
95
|
+
[Pyodide guide](docs/source/pyodide.md) for details and local test commands.
|
|
96
|
+
|
|
97
|
+
# Development tests
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install -e '.[test]'
|
|
101
|
+
pytest tests/portable
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The `test` extra is compiler-free. For compiled-kernel tests, install
|
|
105
|
+
`'.[test-compiled]'` and a working native compiler, then run `pytest`.
|
|
106
|
+
The `dev` extra includes these compiled-test dependencies as before.
|
|
107
|
+
|
|
108
|
+
# Build docs
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
make html
|
|
113
|
+
cd ../
|
|
114
|
+
open docs/_build/html/index.html
|
|
115
|
+
```
|
|
@@ -5,7 +5,7 @@ requires = [ "setuptools", "wheel" ]
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "cunumpy"
|
|
8
|
-
version = "0.1.
|
|
8
|
+
version = "0.1.5"
|
|
9
9
|
description = "Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
keywords = [ "python" ]
|
|
@@ -30,7 +30,7 @@ dependencies = [
|
|
|
30
30
|
optional-dependencies.dev = [
|
|
31
31
|
"black[jupyter]",
|
|
32
32
|
"isort",
|
|
33
|
-
"cunumpy[test,docs]",
|
|
33
|
+
"cunumpy[test-compiled,docs]",
|
|
34
34
|
]
|
|
35
35
|
# https://medium.com/@pratikdomadiya123/build-project-documentation-quickly-with-the-sphinx-python-2a9732b66594
|
|
36
36
|
optional-dependencies.docs = [
|
|
@@ -44,7 +44,8 @@ optional-dependencies.docs = [
|
|
|
44
44
|
"sphinx",
|
|
45
45
|
"sphinx-book-theme",
|
|
46
46
|
]
|
|
47
|
-
optional-dependencies.test = [ "coverage", "
|
|
47
|
+
optional-dependencies.test = [ "coverage", "pytest" ]
|
|
48
|
+
optional-dependencies.test-compiled = [ "cunumpy[test]", "pyccel" ]
|
|
48
49
|
urls."Source" = "https://github.com/max-models/cunumpy"
|
|
49
50
|
|
|
50
51
|
[tool.setuptools.packages.find]
|
|
@@ -4,10 +4,12 @@ from importlib.metadata import PackageNotFoundError, version
|
|
|
4
4
|
from . import xp
|
|
5
5
|
from .kernel import PyccelKernel
|
|
6
6
|
from .xp import (
|
|
7
|
+
assert_same_backend,
|
|
7
8
|
cupy_available,
|
|
8
9
|
get_backend,
|
|
9
10
|
is_cpu,
|
|
10
11
|
is_gpu,
|
|
12
|
+
same_backend,
|
|
11
13
|
set_backend,
|
|
12
14
|
set_device,
|
|
13
15
|
synchronize,
|
|
@@ -25,12 +27,14 @@ except PackageNotFoundError:
|
|
|
25
27
|
__all__ = [
|
|
26
28
|
"PyccelKernel",
|
|
27
29
|
"__version__",
|
|
30
|
+
"assert_same_backend",
|
|
28
31
|
"cupy_available",
|
|
29
32
|
"cupy_backend",
|
|
30
33
|
"get_backend",
|
|
31
34
|
"is_cpu",
|
|
32
35
|
"is_gpu",
|
|
33
36
|
"numpy_backend",
|
|
37
|
+
"same_backend",
|
|
34
38
|
"set_backend",
|
|
35
39
|
"set_device",
|
|
36
40
|
"synchronize",
|
|
@@ -17,6 +17,8 @@ def cupy_available() -> bool: ...
|
|
|
17
17
|
def get_backend(array: Any) -> str: ...
|
|
18
18
|
def is_gpu(array: Any) -> bool: ...
|
|
19
19
|
def is_cpu(array: Any) -> bool: ...
|
|
20
|
+
def same_backend(*arrays: Any) -> bool: ...
|
|
21
|
+
def assert_same_backend(*arrays: Any) -> None: ...
|
|
20
22
|
@contextmanager
|
|
21
23
|
def use_backend(backend: str) -> Generator[None]: ...
|
|
22
24
|
def set_backend(backend: str) -> None: ...
|
|
@@ -8,6 +8,9 @@ made by the kernel are copied back to the device afterwards, and any arrays
|
|
|
8
8
|
returned by the kernel are moved back to the device.
|
|
9
9
|
|
|
10
10
|
On the NumPy backend the wrapper is a no-op and the kernel is called directly.
|
|
11
|
+
Ordinary Python callables are supported, including in Pyodide. This module
|
|
12
|
+
neither imports Pyccel nor compiles kernels; compilation, if desired, is the
|
|
13
|
+
caller's responsibility.
|
|
11
14
|
"""
|
|
12
15
|
|
|
13
16
|
from __future__ import annotations
|
|
@@ -24,7 +27,7 @@ __all__ = ["PyccelKernel"]
|
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
class PyccelKernel:
|
|
27
|
-
"""Call a Pyccel-compiled kernel with NumPy or CuPy arrays.
|
|
30
|
+
"""Call a NumPy callable or Pyccel-compiled kernel with NumPy or CuPy arrays.
|
|
28
31
|
|
|
29
32
|
Parameters
|
|
30
33
|
----------
|
|
@@ -192,6 +192,34 @@ def is_cpu(array: Any) -> bool:
|
|
|
192
192
|
return get_backend(array) == "numpy"
|
|
193
193
|
|
|
194
194
|
|
|
195
|
+
def same_backend(*arrays: Any) -> bool:
|
|
196
|
+
"""Return True if all given arrays live on the same backend.
|
|
197
|
+
|
|
198
|
+
Trivially True for zero or one array.
|
|
199
|
+
"""
|
|
200
|
+
if len(arrays) <= 1:
|
|
201
|
+
return True
|
|
202
|
+
backends = {get_backend(array) for array in arrays}
|
|
203
|
+
return len(backends) == 1
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def assert_same_backend(*arrays: Any) -> None:
|
|
207
|
+
"""Raise TypeError if the given arrays don't all live on the same backend.
|
|
208
|
+
|
|
209
|
+
Mixing NumPy and CuPy arrays in an operation typically fails with a
|
|
210
|
+
confusing, backend-internal error (e.g. a CuPy kernel dispatch error
|
|
211
|
+
complaining about an "unsupported type"). Call this upfront to fail
|
|
212
|
+
with a clear message instead. Use `to_cunumpy()`/`to_numpy()`/`to_cupy()`
|
|
213
|
+
to align mismatched arrays onto one backend first.
|
|
214
|
+
"""
|
|
215
|
+
if not same_backend(*arrays):
|
|
216
|
+
backends = [get_backend(array) for array in arrays]
|
|
217
|
+
raise TypeError(
|
|
218
|
+
f"Arrays are on mismatched backends: {backends}. Use "
|
|
219
|
+
"xp.to_cunumpy()/xp.to_numpy()/xp.to_cupy() to align them first."
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
195
223
|
# TYPE_CHECKING is True when type checking (e.g., mypy), but False at runtime.
|
|
196
224
|
# This allows us to use autocompletion for xp (i.e., numpy/cupy) as if numpy was imported.
|
|
197
225
|
if TYPE_CHECKING:
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cunumpy
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
5
|
+
Author: Max
|
|
6
|
+
Project-URL: Source, https://github.com/max-models/cunumpy
|
|
7
|
+
Keywords: python
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: array-api-compat
|
|
19
|
+
Requires-Dist: numpy
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: black[jupyter]; extra == "dev"
|
|
22
|
+
Requires-Dist: isort; extra == "dev"
|
|
23
|
+
Requires-Dist: cunumpy[docs,test-compiled]; extra == "dev"
|
|
24
|
+
Provides-Extra: docs
|
|
25
|
+
Requires-Dist: ipykernel; extra == "docs"
|
|
26
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
27
|
+
Requires-Dist: nbconvert; extra == "docs"
|
|
28
|
+
Requires-Dist: nbsphinx; extra == "docs"
|
|
29
|
+
Requires-Dist: jupyterlab; extra == "docs"
|
|
30
|
+
Requires-Dist: pre-commit; extra == "docs"
|
|
31
|
+
Requires-Dist: pyproject-fmt; extra == "docs"
|
|
32
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
33
|
+
Requires-Dist: sphinx-book-theme; extra == "docs"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: coverage; extra == "test"
|
|
36
|
+
Requires-Dist: pytest; extra == "test"
|
|
37
|
+
Provides-Extra: test-compiled
|
|
38
|
+
Requires-Dist: cunumpy[test]; extra == "test-compiled"
|
|
39
|
+
Requires-Dist: pyccel; extra == "test-compiled"
|
|
40
|
+
|
|
41
|
+
# CuNumpy
|
|
42
|
+
|
|
43
|
+
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
44
|
+
|
|
45
|
+
# Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install cunumpy
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Example usage:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
export ARRAY_BACKEND=cupy
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import cunumpy as xp
|
|
59
|
+
|
|
60
|
+
xp.set_backend("cupy")
|
|
61
|
+
|
|
62
|
+
arr = xp.array([1, 2])
|
|
63
|
+
|
|
64
|
+
print(f"{type(arr) = }")
|
|
65
|
+
print(f"{xp.__version__ = }")
|
|
66
|
+
|
|
67
|
+
# Convert to NumPy
|
|
68
|
+
arr_np = xp.to_numpy(arr)
|
|
69
|
+
|
|
70
|
+
# Convert to active backend
|
|
71
|
+
arr_xp = xp.to_cunumpy(arr)
|
|
72
|
+
|
|
73
|
+
# Inspect backend
|
|
74
|
+
print(f"{xp.get_backend(arr) = }")
|
|
75
|
+
print(f"{xp.is_gpu(arr) = }")
|
|
76
|
+
print(f"{xp.is_cpu(arr) = }")
|
|
77
|
+
|
|
78
|
+
# Temporarily switch backend
|
|
79
|
+
with xp.use_backend("numpy"):
|
|
80
|
+
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
81
|
+
arr_cpu = xp.zeros(100)
|
|
82
|
+
|
|
83
|
+
# Set backend globally
|
|
84
|
+
xp.set_backend("cupy")
|
|
85
|
+
|
|
86
|
+
# Synchronize GPU operations (no-op on CPU)
|
|
87
|
+
xp.synchronize()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Output:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
type(arr) = <class 'cupy.ndarray'>
|
|
94
|
+
xp.__version__ = '0.1.4'
|
|
95
|
+
xp.get_backend(arr) = 'cupy'
|
|
96
|
+
xp.is_gpu(arr) = True
|
|
97
|
+
xp.is_cpu(arr) = False
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
# Pyodide
|
|
101
|
+
|
|
102
|
+
cuNumPy supports Pyodide with the NumPy backend. In an initialized Pyodide
|
|
103
|
+
JavaScript runtime, install the package and run a Python-source kernel:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
await pyodide.loadPackage("micropip");
|
|
107
|
+
await pyodide.runPythonAsync(`
|
|
108
|
+
import micropip
|
|
109
|
+
await micropip.install("cunumpy")
|
|
110
|
+
|
|
111
|
+
import cunumpy as xp
|
|
112
|
+
xp.set_backend("numpy")
|
|
113
|
+
|
|
114
|
+
def scale(values, factor):
|
|
115
|
+
values[:] *= factor
|
|
116
|
+
return values
|
|
117
|
+
|
|
118
|
+
values = xp.array([1.0, 2.0, 3.0])
|
|
119
|
+
result = xp.PyccelKernel(scale)(values, 2.0)
|
|
120
|
+
assert result is values
|
|
121
|
+
print(xp.to_numpy(result)) # [2. 4. 6.]
|
|
122
|
+
`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
NumPy is the default backend when `ARRAY_BACKEND` is unset. CuPy/CUDA and
|
|
126
|
+
native Pyccel compilation are not supported in Pyodide. Despite its name,
|
|
127
|
+
`PyccelKernel` accepts ordinary Python callables and neither imports Pyccel nor
|
|
128
|
+
compiles code. Applications must supply Python-source kernels with
|
|
129
|
+
Pyodide-compatible imports.
|
|
130
|
+
|
|
131
|
+
CI tests the built wheel in Pyodide's WebAssembly runtime under Node.js, including
|
|
132
|
+
array operations, conversions, mutation/aliasing, backend context restoration,
|
|
133
|
+
and Python kernels, while rejecting CuPy or Pyccel imports. This does not test
|
|
134
|
+
browser-specific integration such as page loading or workers. See the
|
|
135
|
+
[Pyodide guide](docs/source/pyodide.md) for details and local test commands.
|
|
136
|
+
|
|
137
|
+
# Development tests
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
pip install -e '.[test]'
|
|
141
|
+
pytest tests/portable
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The `test` extra is compiler-free. For compiled-kernel tests, install
|
|
145
|
+
`'.[test-compiled]'` and a working native compiler, then run `pytest`.
|
|
146
|
+
The `dev` extra includes these compiled-test dependencies as before.
|
|
147
|
+
|
|
148
|
+
# Build docs
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
make html
|
|
153
|
+
cd ../
|
|
154
|
+
open docs/_build/html/index.html
|
|
155
|
+
```
|
cunumpy-0.1.4/PKG-INFO
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: cunumpy
|
|
3
|
-
Version: 0.1.4
|
|
4
|
-
Summary: Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
5
|
-
Author: Max
|
|
6
|
-
Project-URL: Source, https://github.com/max-models/cunumpy
|
|
7
|
-
Keywords: python
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
-
Requires-Python: >=3.8
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
Requires-Dist: array-api-compat
|
|
19
|
-
Requires-Dist: numpy
|
|
20
|
-
Provides-Extra: dev
|
|
21
|
-
Requires-Dist: black[jupyter]; extra == "dev"
|
|
22
|
-
Requires-Dist: isort; extra == "dev"
|
|
23
|
-
Requires-Dist: cunumpy[docs,test]; extra == "dev"
|
|
24
|
-
Provides-Extra: docs
|
|
25
|
-
Requires-Dist: ipykernel; extra == "docs"
|
|
26
|
-
Requires-Dist: myst-parser; extra == "docs"
|
|
27
|
-
Requires-Dist: nbconvert; extra == "docs"
|
|
28
|
-
Requires-Dist: nbsphinx; extra == "docs"
|
|
29
|
-
Requires-Dist: jupyterlab; extra == "docs"
|
|
30
|
-
Requires-Dist: pre-commit; extra == "docs"
|
|
31
|
-
Requires-Dist: pyproject-fmt; extra == "docs"
|
|
32
|
-
Requires-Dist: sphinx; extra == "docs"
|
|
33
|
-
Requires-Dist: sphinx-book-theme; extra == "docs"
|
|
34
|
-
Provides-Extra: test
|
|
35
|
-
Requires-Dist: coverage; extra == "test"
|
|
36
|
-
Requires-Dist: pyccel; extra == "test"
|
|
37
|
-
Requires-Dist: pytest; extra == "test"
|
|
38
|
-
|
|
39
|
-
# CuNumpy
|
|
40
|
-
|
|
41
|
-
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
42
|
-
|
|
43
|
-
# Install
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install cunumpy
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Example usage:
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
export ARRAY_BACKEND=cupy
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
import cunumpy as xp
|
|
57
|
-
|
|
58
|
-
arr = xp.array([1, 2])
|
|
59
|
-
|
|
60
|
-
print(type(arr))
|
|
61
|
-
print(xp.__version__)
|
|
62
|
-
|
|
63
|
-
# Convert to NumPy
|
|
64
|
-
arr_np = xp.to_numpy(arr)
|
|
65
|
-
|
|
66
|
-
# Convert to active backend
|
|
67
|
-
arr_xp = xp.to_cunumpy(arr)
|
|
68
|
-
|
|
69
|
-
# Inspect backend
|
|
70
|
-
print(xp.get_backend(arr))
|
|
71
|
-
print(xp.is_gpu(arr))
|
|
72
|
-
print(xp.is_cpu(arr))
|
|
73
|
-
|
|
74
|
-
# Temporarily switch backend
|
|
75
|
-
with xp.use_backend("numpy"):
|
|
76
|
-
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
77
|
-
arr_cpu = xp.zeros(100)
|
|
78
|
-
|
|
79
|
-
# Set backend globally
|
|
80
|
-
xp.set_backend("cupy")
|
|
81
|
-
|
|
82
|
-
# Synchronize GPU operations (no-op on CPU)
|
|
83
|
-
xp.synchronize()
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
# Build docs
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
make html
|
|
91
|
-
cd ../
|
|
92
|
-
open docs/_build/html/index.html
|
|
93
|
-
```
|
cunumpy-0.1.4/README.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# CuNumpy
|
|
2
|
-
|
|
3
|
-
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
4
|
-
|
|
5
|
-
# Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install cunumpy
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Example usage:
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
export ARRAY_BACKEND=cupy
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
```python
|
|
18
|
-
import cunumpy as xp
|
|
19
|
-
|
|
20
|
-
arr = xp.array([1, 2])
|
|
21
|
-
|
|
22
|
-
print(type(arr))
|
|
23
|
-
print(xp.__version__)
|
|
24
|
-
|
|
25
|
-
# Convert to NumPy
|
|
26
|
-
arr_np = xp.to_numpy(arr)
|
|
27
|
-
|
|
28
|
-
# Convert to active backend
|
|
29
|
-
arr_xp = xp.to_cunumpy(arr)
|
|
30
|
-
|
|
31
|
-
# Inspect backend
|
|
32
|
-
print(xp.get_backend(arr))
|
|
33
|
-
print(xp.is_gpu(arr))
|
|
34
|
-
print(xp.is_cpu(arr))
|
|
35
|
-
|
|
36
|
-
# Temporarily switch backend
|
|
37
|
-
with xp.use_backend("numpy"):
|
|
38
|
-
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
39
|
-
arr_cpu = xp.zeros(100)
|
|
40
|
-
|
|
41
|
-
# Set backend globally
|
|
42
|
-
xp.set_backend("cupy")
|
|
43
|
-
|
|
44
|
-
# Synchronize GPU operations (no-op on CPU)
|
|
45
|
-
xp.synchronize()
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
# Build docs
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
make html
|
|
53
|
-
cd ../
|
|
54
|
-
open docs/_build/html/index.html
|
|
55
|
-
```
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: cunumpy
|
|
3
|
-
Version: 0.1.4
|
|
4
|
-
Summary: Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
5
|
-
Author: Max
|
|
6
|
-
Project-URL: Source, https://github.com/max-models/cunumpy
|
|
7
|
-
Keywords: python
|
|
8
|
-
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
-
Requires-Python: >=3.8
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
Requires-Dist: array-api-compat
|
|
19
|
-
Requires-Dist: numpy
|
|
20
|
-
Provides-Extra: dev
|
|
21
|
-
Requires-Dist: black[jupyter]; extra == "dev"
|
|
22
|
-
Requires-Dist: isort; extra == "dev"
|
|
23
|
-
Requires-Dist: cunumpy[docs,test]; extra == "dev"
|
|
24
|
-
Provides-Extra: docs
|
|
25
|
-
Requires-Dist: ipykernel; extra == "docs"
|
|
26
|
-
Requires-Dist: myst-parser; extra == "docs"
|
|
27
|
-
Requires-Dist: nbconvert; extra == "docs"
|
|
28
|
-
Requires-Dist: nbsphinx; extra == "docs"
|
|
29
|
-
Requires-Dist: jupyterlab; extra == "docs"
|
|
30
|
-
Requires-Dist: pre-commit; extra == "docs"
|
|
31
|
-
Requires-Dist: pyproject-fmt; extra == "docs"
|
|
32
|
-
Requires-Dist: sphinx; extra == "docs"
|
|
33
|
-
Requires-Dist: sphinx-book-theme; extra == "docs"
|
|
34
|
-
Provides-Extra: test
|
|
35
|
-
Requires-Dist: coverage; extra == "test"
|
|
36
|
-
Requires-Dist: pyccel; extra == "test"
|
|
37
|
-
Requires-Dist: pytest; extra == "test"
|
|
38
|
-
|
|
39
|
-
# CuNumpy
|
|
40
|
-
|
|
41
|
-
Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
|
|
42
|
-
|
|
43
|
-
# Install
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install cunumpy
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Example usage:
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
export ARRAY_BACKEND=cupy
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
```python
|
|
56
|
-
import cunumpy as xp
|
|
57
|
-
|
|
58
|
-
arr = xp.array([1, 2])
|
|
59
|
-
|
|
60
|
-
print(type(arr))
|
|
61
|
-
print(xp.__version__)
|
|
62
|
-
|
|
63
|
-
# Convert to NumPy
|
|
64
|
-
arr_np = xp.to_numpy(arr)
|
|
65
|
-
|
|
66
|
-
# Convert to active backend
|
|
67
|
-
arr_xp = xp.to_cunumpy(arr)
|
|
68
|
-
|
|
69
|
-
# Inspect backend
|
|
70
|
-
print(xp.get_backend(arr))
|
|
71
|
-
print(xp.is_gpu(arr))
|
|
72
|
-
print(xp.is_cpu(arr))
|
|
73
|
-
|
|
74
|
-
# Temporarily switch backend
|
|
75
|
-
with xp.use_backend("numpy"):
|
|
76
|
-
# This code runs on CPU even if ARRAY_BACKEND=cupy
|
|
77
|
-
arr_cpu = xp.zeros(100)
|
|
78
|
-
|
|
79
|
-
# Set backend globally
|
|
80
|
-
xp.set_backend("cupy")
|
|
81
|
-
|
|
82
|
-
# Synchronize GPU operations (no-op on CPU)
|
|
83
|
-
xp.synchronize()
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
# Build docs
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
90
|
-
make html
|
|
91
|
-
cd ../
|
|
92
|
-
open docs/_build/html/index.html
|
|
93
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|