Skip to content
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

ENH: Implementation of the NEP 47 (adopting the array API standard) #18585

Merged
merged 152 commits into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
012343d
Add initial array_api sub-namespace
asmeurer Jan 11, 2021
9934cf3
Add dtypes to the _array_api namespace
asmeurer Jan 11, 2021
e00760c
Fix array API functions that are named differently or not in the defa…
asmeurer Jan 11, 2021
fcff4e1
Fix the bool name in the array API namespace
asmeurer Jan 12, 2021
f36b648
Fix different names for some bitwise functions in the array apis
asmeurer Jan 12, 2021
c8efdbb
Fix different behavior of norm() with axis=None in the array API name…
asmeurer Jan 12, 2021
10427b0
Correct some differing keyword arguments in the array API namespace
asmeurer Jan 12, 2021
d965102
Add the device keyword to the array creation functions
asmeurer Jan 12, 2021
9578636
Make the array_api submodules private, and remove __all__ from indivi…
asmeurer Jan 12, 2021
e521b16
Add missing returns to the array API sorting functions
asmeurer Jan 12, 2021
ba4e21c
Fix the array_api submodule __init__.py imports
asmeurer Jan 12, 2021
4bd5d15
Use "import numpy as np" in the array_api submodule
asmeurer Jan 12, 2021
a78d20a
Fix array API functions that need to use np.linalg
asmeurer Jan 12, 2021
00dda8d
Add basic docstrings to the array API wrapper functions
asmeurer Jan 12, 2021
df698f8
Add an explanatory docstring to _array_api/__init__.py
asmeurer Jan 13, 2021
be1b193
Add type annotations to the array api submodule function definitions
asmeurer Jan 20, 2021
5df8ec9
Fix some incorrect type annotations in the array API submodule
asmeurer Jan 21, 2021
ad19f7f
Use np.asarray in the array API submodule for any function that can r…
asmeurer Jan 21, 2021
1efd55e
Use _implementation on all functions that have it in the array API su…
asmeurer Jan 21, 2021
affc5f0
Add some more notes to the array API module docstring
asmeurer Jan 21, 2021
f2ac67e
Update array_api namespace with latest changes from the spec
asmeurer Feb 23, 2021
d9438ad
Start implementing wrapper object for the array API
asmeurer Feb 24, 2021
e233a0a
Add some missing names in the array_api namespace __all__
asmeurer Feb 24, 2021
c791956
Fix the copy keyword argument in the array_api namespace asarray()
asmeurer Feb 24, 2021
853a18d
Implement a simple passthrough __str__ and __repr__ on the array_api …
asmeurer Feb 24, 2021
a42f71a
Only allow supported dtypes in the array_api namespace asarray()
asmeurer Feb 24, 2021
cd70920
Support array_api.ndarray in array_api.asarray()
asmeurer Feb 24, 2021
3b9c910
Return ndarray in the array_api namespace elementwise functions
asmeurer Feb 27, 2021
6e36bfc
Use a different repr form for array_api.ndarray than array
asmeurer Feb 27, 2021
061fecb
Fix the dunder methods on array_api.ndarray
asmeurer Feb 27, 2021
587613f
Use ndarray in the array API creation functions
asmeurer Feb 27, 2021
892b536
Only allow the spec guaranteed dtypes in the array API elementwise fu…
asmeurer Feb 27, 2021
b7856e3
Make an error message easier to read
asmeurer Feb 27, 2021
2ff635c
Don't check if a dtype is in all_dtypes
asmeurer Feb 27, 2021
b933ebb
Allow dimension 0 arrays in the array API namespace full() and full_l…
asmeurer Feb 27, 2021
73d2c1e
Make the array API constants into dimension 0 arrays
asmeurer Feb 27, 2021
16030e4
Clean up some imports
asmeurer Feb 27, 2021
d40985c
Fix some dunder methods on that should not be converting things to ar…
asmeurer Mar 2, 2021
f1f9dca
Make the array API manipulation functions use the array API ndarray o…
asmeurer Mar 2, 2021
63be085
Only allow __bool__, __int__, and __float__ on arrays with shape ()
asmeurer Mar 2, 2021
7132764
Remove _implementation from the array API functions
asmeurer Mar 2, 2021
58c2a99
Make sure the array API ndarray object cannot wrap an array scalar
asmeurer Mar 2, 2021
cdd6bbc
Support the ndarray object in the remaining array API functions
asmeurer Mar 5, 2021
1ccbe68
Only allow indices that are required by the spec in the array API nam…
asmeurer Mar 9, 2021
be45fa1
Update the state of the array API in the __init__.py docstring
asmeurer Mar 9, 2021
0ac7de9
Implement __array_namespace__ on the array API ndarray object
asmeurer Mar 10, 2021
9e50716
Use 'self' and 'other' for the array API ndarray method parameter names
asmeurer Mar 10, 2021
6c17d4b
Update the array API namespace __init__.py docstring with todos
asmeurer Mar 10, 2021
48a2d8c
Add a small docstring to the array API ndarray object
asmeurer Mar 10, 2021
8671a36
Use the array API types for the array API type annotations
asmeurer Mar 10, 2021
da5dc95
Only return the same array in asarray if the dtype is the same
asmeurer Mar 11, 2021
e42ae01
Use more robust code for converting an array scalar to a shape () array
asmeurer Mar 11, 2021
ed05662
Fix circular imports from types
asmeurer Mar 18, 2021
8968bc3
bitwise_left_shift and bitwise_right_shift should return the dtype of…
asmeurer Mar 18, 2021
479c8a2
bitwise_left_shift and bitwise_right_shift are only defined for x2 >= 0
asmeurer Mar 18, 2021
7ce435c
Update some annotations updated from the spec
asmeurer Mar 30, 2021
9fe4fc7
Make the array API follow the spec Python scalar promotion rules
asmeurer Mar 31, 2021
fb5c697
Give a better error message in the array API asarray for out of bound…
asmeurer Mar 31, 2021
b75a135
Fix int bounds checking in asarray() to only happen when dtype=None
asmeurer Apr 13, 2021
d40d2bc
Fix ceil() and floor() in the array API to always return the same dtype
asmeurer Apr 14, 2021
844fcd3
Move function name change notes to before the def line
asmeurer Apr 14, 2021
9af1cc6
Use dtype objects instead of classes in the array API
asmeurer Apr 15, 2021
6c196f5
Fix type promotion consistency for the array API elementwise function…
asmeurer Apr 15, 2021
b0b2539
Add meshgrid(), broadcast_arrays(), broadcast_to(), and can_cast() to…
asmeurer Apr 26, 2021
6115cce
Update signatures in the array API namespace from the latest version …
asmeurer Apr 28, 2021
edf68c5
Fix some error messages
asmeurer Apr 30, 2021
2199687
Fix the array API norm() function
asmeurer May 10, 2021
533d046
Fix array API squeeze() and stack()
asmeurer May 10, 2021
4817784
Make the array API constants Python floats
asmeurer May 10, 2021
96f40fe
Ignore warnings in array API functions that can raise them
asmeurer May 17, 2021
be1ee6c
Update signatures from the latest version of the array API spec
asmeurer May 20, 2021
f6015d2
Update a function signature from the array API spec
asmeurer Jun 14, 2021
cad21e9
Update the linear algebra functions in the array API namespace
asmeurer Jul 1, 2021
0178080
Fix in-place operators to not recreate the wrapper class
asmeurer Jul 8, 2021
1379623
Fix the __imatmul__ method in the array API namespace
asmeurer Jul 8, 2021
fc1ff6f
Capitalize the names of the type hint types in the array API
asmeurer Jul 8, 2021
aee3a56
Rename the array class in the array API namespace from ndarray to Array
asmeurer Jul 8, 2021
4240314
Update the docstring of numpy/_array_api/__init__.py
asmeurer Jul 8, 2021
5780a9b
Remove typing exports from numpy/_array_api/_types.py
asmeurer Jul 9, 2021
29b7a69
Use better type definitions for the array API custom types
asmeurer Jul 9, 2021
74478e2
Use better type signatures in the array API module
asmeurer Jul 9, 2021
60add4a
Small code cleanup
asmeurer Jul 9, 2021
6379138
Rename numpy/_array_api/_types.py to numpy/_array_api/_typing.py
asmeurer Jul 9, 2021
5febef5
Only allow floating-point dtypes in the array API __pow__ and __trued…
asmeurer Jul 9, 2021
c5999e2
Update the type hints for the array API __pow__ and __truediv__
asmeurer Jul 9, 2021
29974fb
Use tuples for internal type lists in the array API
asmeurer Jul 9, 2021
8ca96b2
Fix some typing imports
asmeurer Jul 9, 2021
639aa7c
Fix the type hints for argmin/argmax in the array API
asmeurer Jul 9, 2021
6765494
Fix typo
asmeurer Jul 9, 2021
5217236
Make the array API left and right shift do type promotion
asmeurer Jul 10, 2021
2bdc5c3
Make the _array_api submodule install correctly
asmeurer Jul 15, 2021
49bd660
Use ndim == 0 instead of shape == () in the array API code
asmeurer Jul 15, 2021
b58fbd2
Correct disallow things like a[(0, 1), (0, 1)] in the array API names…
asmeurer Jul 15, 2021
c558013
Add a comment about the _normalize_two_args trick
asmeurer Jul 15, 2021
6855a8a
Move _validate_index above the methods that are actually part of the …
asmeurer Jul 15, 2021
6f98f9e
Remove error ignoring in the array API namespace
asmeurer Jul 16, 2021
48df7af
Fix some spelling errors
asmeurer Jul 16, 2021
3cab20e
Make numpy._array_api.Array.device return "cpu"
asmeurer Jul 16, 2021
185d06d
Guard against non-array API inputs in the array API result_type()
asmeurer Jul 16, 2021
d9b9582
Move the dtype check to the array API Array._new constructor
asmeurer Jul 16, 2021
56345ff
Use asarray to convert a scalar into an array in the array API Array …
asmeurer Jul 16, 2021
7c5380d
Remove an unnecessary indexing
asmeurer Jul 16, 2021
687e2a3
Add type hints to the array API __setitem__
asmeurer Jul 16, 2021
a566cd1
Change the type hint for stream __dlpack__ to just None
asmeurer Jul 16, 2021
f20be6a
Start adding tests for the array API submodule
asmeurer Jul 19, 2021
e34c097
Always include the dtype in the array API Array repr
asmeurer Jul 21, 2021
f74b359
Add bool and int explicitly to the array API asarray() input type hints
asmeurer Jul 21, 2021
4fd028d
Implement the array API result_type() manually
asmeurer Jul 21, 2021
9d5d0ec
Fix a typo in an error message
asmeurer Jul 21, 2021
63a9a87
Restrict the array API namespace array operator type promotions
asmeurer Jul 21, 2021
a16d763
Use ValueError instead of TypeError for array API @=
asmeurer Jul 22, 2021
776b117
Add some more comments about array API type promotion stuff
asmeurer Jul 22, 2021
6265676
Prevent unwanted type promotions everywhere in the array API namespace
asmeurer Jul 22, 2021
1e835f9
Remove some dead code
asmeurer Jul 22, 2021
64bb971
Add tests for Python scalar constructors on array API arrays
asmeurer Jul 22, 2021
deaf0bf
Fix the array API __abs__() to restrict to numeric dtypes
asmeurer Jul 23, 2021
e7f6dfe
Fix the array API trunc() to return the same dtype as the input
asmeurer Jul 23, 2021
e4b7205
Fix the array API Array.__setitem__
asmeurer Jul 23, 2021
65ed981
Add tests for error cases for the array API elementwise functions
asmeurer Jul 23, 2021
5882962
Assume the current array API version is 2021.<something>
asmeurer Jul 23, 2021
8680a12
Only allow dtypes to be spelled with their names in the array API
asmeurer Jul 23, 2021
1823e7e
Allow setting device='cpu' in the array API creation functions
asmeurer Jul 24, 2021
d93aad2
Enable asarray(copy=True) in the array API namespace
asmeurer Jul 24, 2021
09a4f8c
Add a TODO comment
asmeurer Jul 24, 2021
3b91f47
Add tests for the array API creation functions
asmeurer Jul 24, 2021
1596415
Merge branch 'main' into array-api
asmeurer Aug 4, 2021
6e57d82
Rename numpy._array_api to numpy.array_api
asmeurer Aug 4, 2021
ee852b4
Print a warning when importing the numpy.array_api submodule
asmeurer Aug 4, 2021
7e6a026
Remove no longer comment about the keepdims argument to argmin
asmeurer Aug 5, 2021
c23abdc
Remove asarray() calls from the array API statistical functions
asmeurer Aug 5, 2021
5605d68
Remove unused import
asmeurer Aug 5, 2021
bc20d33
Move the array API dtype categories into the top level
asmeurer Aug 5, 2021
6789a74
Move some imports out of functions to the top of the file
asmeurer Aug 5, 2021
310929d
Fix casting for the array API concat() and stack()
asmeurer Aug 5, 2021
3730fc0
Give a better error when numpy.array_api is imported in Python 3.7
asmeurer Aug 5, 2021
d74a7d0
Add a setup.py to the array_api submodule
asmeurer Aug 6, 2021
fcdadee
Fix some dictionary key mismatches in the array API tests
asmeurer Aug 6, 2021
b6f71c8
Make the array API submodule not break the test suite
asmeurer Aug 6, 2021
5c7074f
Fix the tests for Python 3.7
asmeurer Aug 6, 2021
2fe8643
Fix the array API __len__ method
asmeurer Aug 6, 2021
4063752
Fix the array API unique() function
asmeurer Aug 6, 2021
1ae8084
Make the axis argument to squeeze() in the array_api module positiona…
asmeurer Aug 6, 2021
f13f08f
Fix the array API nonzero() function
asmeurer Aug 6, 2021
21923a5
Update the docstring of numpy.array_api
asmeurer Aug 7, 2021
8f7d00e
Run (selective) black on the array_api submodule
asmeurer Aug 7, 2021
d5956c1
Fix the return annotation for numpy.array_api.Array.__setitem__
asmeurer Aug 12, 2021
90537b5
Add smallest_normal to the array API finfo
asmeurer Aug 12, 2021
22cb4f3
Make sure array_api is included in the public API tests
asmeurer Aug 12, 2021
9978cc5
Remove Python 3.7 checks from the array API code
asmeurer Aug 23, 2021
f12fa6f
Add a release note entry for #18585
asmeurer Aug 23, 2021
06ec0ec
Remove an unused import
asmeurer Aug 23, 2021
7091e4c
Use catch_warnings(record=True) instead of simplefilter('ignore')
asmeurer Aug 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions doc/release/upcoming_changes/18585.new_feature.rst
@@ -0,0 +1,15 @@
Implementation of the NEP 47 (adopting the array API standard)
--------------------------------------------------------------

An initial implementation of `NEP 47`_ (adoption the array API standard) has
been added as ``numpy.array_api``. The implementation is experimental and will
issue a UserWarning on import, as the `array API standard
<https://data-apis.org/array-api/latest/index.html>`_ is still in draft state.
``numpy.array_api`` is a conforming implementation of the array API standard,
which is also minimal, meaning that only those functions and behaviors that
are required by the standard are implemented (see the NEP for more info).
Libraries wishing to make use of the array API standard are encouraged to use
``numpy.array_api`` to check that they are only using functionality that is
guaranteed to be present in standard conforming implementations.

.. _`NEP 47`: https://numpy.org/neps/nep-0047-array-api-standard.html
13 changes: 10 additions & 3 deletions numpy/_pytesttester.py
Expand Up @@ -137,13 +137,20 @@ def __call__(self, label='fast', verbose=1, extra_argv=None,
# offset verbosity. The "-q" cancels a "-v".
pytest_args += ["-q"]

# Filter out distutils cpu warnings (could be localized to
# distutils tests). ASV has problems with top level import,
# so fetch module for suppression here.
with warnings.catch_warnings():
warnings.simplefilter("always")
# Filter out distutils cpu warnings (could be localized to
# distutils tests). ASV has problems with top level import,
# so fetch module for suppression here.
from numpy.distutils import cpuinfo

with warnings.catch_warnings(record=True):
# Ignore the warning from importing the array_api submodule. This
# warning is done on import, so it would break pytest collection,
# but importing it early here prevents the warning from being
# issued when it imported again.
import numpy.array_api

# Filter out annoying import messages. Want these in both develop and
# release mode.
pytest_args += [
Expand Down