-
Notifications
You must be signed in to change notification settings - Fork 35
CuPy support #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CuPy support #6
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9f2afe8
Add a get_xp decorator to support multiple array namespaces
asmeurer e9c52c4
Add get_xp decorator to genericize the namespace for the aliases
asmeurer 1751356
Require the namespace argument to asarray() when it's ambiguous
asmeurer b3a12d9
Move all the NumPy functionality into a numpy submodule
asmeurer cf4083a
Move the wrapper code into common/, and make linalg use @get_xp
asmeurer 7333696
Move _typing.py from numpy/ to common/
asmeurer 076848e
Add a cupy submodule
asmeurer ed5705f
Rename numpy_array_api_compat/ to array_api_compat/
asmeurer 420c0da
Add __array_api_version__
asmeurer 005852f
Remove library-specific stuff from common/_typing.py
asmeurer 2912c9e
Refactor how get_xp works
asmeurer 5775b11
Rename common.linalg to common._linalg
asmeurer 936a8ad
Fix arange()
asmeurer d88f709
Fix cupy asarray to create cupy arrays instead of numpy arrays
asmeurer 360ea18
Re-enable the signature fix in get_xp
asmeurer fece5e0
Fix some issues with the linalg wrapping
asmeurer c91360b
Export helpers to the top-level namespace
asmeurer d19c1a2
Fix full_like and linspace
asmeurer 6c54b6b
Fix permute_dims
asmeurer e996d22
Add more information to the README
asmeurer 82365eb
Add a test that vendoring works
asmeurer a83b15c
Fixes to the README
asmeurer 8d2d37a
Fix missing sentence in the README
asmeurer 732b493
Move vendor_test to the top-level
asmeurer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
NumPy Array API compatibility library | ||
|
||
This is a small wrapper around NumPy and CuPy that is compatible with the | ||
Array API standard https://data-apis.org/array-api/latest/. See also NEP 47 | ||
https://numpy.org/neps/nep-0047-array-api-standard.html. | ||
|
||
Unlike numpy.array_api, this is not a strict minimal implementation of the | ||
Array API, but rather just an extension of the main NumPy namespace with | ||
changes needed to be compliant with the Array API. See | ||
https://numpy.org/doc/stable/reference/array_api.html for a full list of | ||
changes. In particular, unlike numpy.array_api, this package does not use a | ||
separate Array object, but rather just uses numpy.ndarray directly. | ||
|
||
Library authors using the Array API may wish to test against numpy.array_api | ||
to ensure they are not using functionality outside of the standard, but prefer | ||
this implementation for the default when working with NumPy arrays. | ||
|
||
""" | ||
from .common import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Internal helpers | ||
""" | ||
|
||
from functools import wraps | ||
from inspect import signature | ||
|
||
def get_xp(xp): | ||
""" | ||
Decorator to automatically replace xp with the corresponding array module. | ||
|
||
Use like | ||
|
||
import numpy as np | ||
|
||
@get_xp(np) | ||
def func(x, /, xp, kwarg=None): | ||
return xp.func(x, kwarg=kwarg) | ||
|
||
Note that xp must be a keyword argument and come after all non-keyword | ||
arguments. | ||
|
||
""" | ||
def inner(f): | ||
@wraps(f) | ||
def wrapped_f(*args, **kwargs): | ||
return f(*args, xp=xp, **kwargs) | ||
|
||
sig = signature(f) | ||
new_sig = sig.replace(parameters=[sig.parameters[i] for i in sig.parameters if i != 'xp']) | ||
|
||
if wrapped_f.__doc__ is None: | ||
wrapped_f.__doc__ = f"""\ | ||
Array API compatibility wrapper for {f.__name__}. | ||
|
||
See the corresponding documentation in NumPy/CuPy and/or the array API | ||
specification for more details. | ||
|
||
""" | ||
wrapped_f.__signature__ = new_sig | ||
return wrapped_f | ||
|
||
return inner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._helpers import * |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
incomplete sentence here - and it seems to start saying something that's fairly important.