Simple wrapper for numpy and cupy. Replace `import numpy as np` with `import cunumpy as xp`.
Project description
CuNumpy
Simple wrapper for numpy and cupy. Replace import numpy as np with import cunumpy as xp.
Install
pip install cunumpy
Example usage:
export ARRAY_BACKEND=cupy
import cunumpy as xp
arr = xp.array([1,2])
print(type(arr))
print(xp.__version__)
# Convert to NumPy
arr_np = xp.to_numpy(arr)
# Convert to active backend
arr_xp = xp.to_cunumpy(arr)
# Inspect backend
print(xp.get_backend(arr))
print(xp.is_gpu(arr))
print(xp.is_cpu(arr))
# Temporarily switch backend
with xp.use_backend("numpy"):
# This code runs on CPU even if ARRAY_BACKEND=cupy
arr_cpu = xp.zeros(100)
# Set backend globally
xp.set_backend("cupy")
# Synchronize GPU operations (no-op on CPU)
xp.synchronize()
Build docs
make html
cd ../
open docs/_build/html/index.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cunumpy-0.1.2.tar.gz
(4.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cunumpy-0.1.2.tar.gz.
File metadata
- Download URL: cunumpy-0.1.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf73b37b58186c04f9eecd62483802f5c47c9761551e728076986995fbb3a27f
|
|
| MD5 |
f4d3a65cbd2daf7d4438d5ba8b89233c
|
|
| BLAKE2b-256 |
639d87178ab9907d63385ee96a9af7af0afea334e93164929b47353093459821
|
File details
Details for the file cunumpy-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cunumpy-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f270481bcc5b02b8bf6710e59ed7f62c1a9f89791b6c45649fe036c860a30ff5
|
|
| MD5 |
12ad20de87646d3dfb084e2e199ce976
|
|
| BLAKE2b-256 |
94be0fbd0f11b38f2efae657af5b2de92488f80dfebbfbf72fc03b9a91f34808
|