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

Array API extra #3065

Merged
merged 28 commits into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bcf53a8
Array API extra
honno Aug 23, 2021
d83d89f
Remove PrettyArrayModule wrapper
honno Sep 7, 2021
516fddd
Comment that notes the xp function signature assertion
honno Sep 7, 2021
c84839f
Actually smoke indexer in valid indexers test
honno Sep 7, 2021
667c4bc
Skip tests using optional Array API methods using markers
honno Sep 7, 2021
0f4a48d
Drop newaxis support in indices()
honno Sep 7, 2021
ef55531
Rudimentary valid indexers (slow generation)
honno Sep 7, 2021
f584cae
Appropiate min/max dims behaviour for indices(), expose xps.slices()
honno Sep 8, 2021
c229f31
Made indices tests ported from tests/numpy work with array_api
honno Sep 8, 2021
6fca573
xarray -> Xarray in docs
honno Sep 8, 2021
9993004
Compact indices effeciency test
honno Sep 8, 2021
c72374f
Label valid indexer draws
honno Sep 8, 2021
06202ad
Clearer error in indices() for shapes with non-negative integers
honno Sep 8, 2021
19f71b2
Fix lint issue
honno Sep 8, 2021
52ae7bc
Revert indices() injecting custom slices method
honno Sep 9, 2021
1d49cc7
Used check_argument for basic_indices() shapes check, improved msg
honno Sep 9, 2021
b81dad0
Use appropiate Sphinx func links
honno Sep 9, 2021
cbcf09d
Internal testing/coverage for dtype methods
honno Sep 9, 2021
389cde2
Use assigntment expressions in error messages
honno Sep 9, 2021
d8ea29b
Remove redundant skip in large uint arrays test
honno Sep 9, 2021
b6c2e42
Clarified comment in ellipsis indices test (NumPy and Array API)
honno Sep 9, 2021
fba0fb2
Improved clarity in ellipsis indices test (NumPy and Array API)
honno Sep 10, 2021
72dd427
Change max_dims defaulting in indices() to len(shape)
honno Sep 10, 2021
520d018
Dtype name lists are now tuples
honno Sep 10, 2021
e90e34d
Refactor test code
Zac-HD Sep 11, 2021
47ba696
Link to xp.unique() issue
Zac-HD Sep 11, 2021
bd9797b
Avoid type: ignore
Zac-HD Sep 11, 2021
500fd15
Set, not defaultdict
Zac-HD Sep 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ their individual contributions.

.. NOTE - this list is in alphabetical order by first name (or handle).

* `Aaron Meurer <https://github.com/asmeurer>`_
* `Adam Johnson <https://github.com/adamchainz>`_
* `Adam Sven Johnson <https://www.github.com/pkqk>`_
* `Afrida Tabassum <https://github.com/oxfordhalfblood>`_ ([email protected])
Expand Down Expand Up @@ -93,6 +94,7 @@ their individual contributions.
* `Markus Unterwaditzer <https://github.com/untitaker>`_ ([email protected])
* `Mathieu Paturel <https://github.com/math2001>`_ ([email protected])
* `Matt Bachmann <https://www.github.com/bachmann1234>`_ ([email protected])
* `Matthew Barber <https://www.github.com/honno>`_ ([email protected])
* `Max Nordlund <https://www.github.com/maxnordlund>`_ ([email protected])
* `Maxim Kulkin <https://www.github.com/maximkulkin>`_ ([email protected])
* `Michel Alexandre Salim <https://github.com/michel-slm>`_ ([email protected])
Expand Down
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RELEASE_TYPE: minor

This release introduces strategies for array/tensor libraries adopting the
`Array API standard <https://data-apis.org/>`__ (:issue:`3037`).
They are available in :ref:`the hypothesis.extra.array_api extra <array-api>`,
and work much like the existing :doc:`strategies for NumPy <numpy>`.
10 changes: 10 additions & 0 deletions hypothesis-python/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import datetime
import os
import sys
import types

import sphinx_rtd_theme

Expand Down Expand Up @@ -59,6 +60,14 @@ def setup(app):
if os.path.isfile(os.path.join(os.path.dirname(__file__), "..", "RELEASE.rst")):
app.tags.add("has_release_file")

# patch in mock array_api namespace so we can autodoc it
from hypothesis.extra.array_api import make_strategies_namespace, mock_xp

mod = types.ModuleType("xps")
mod.__dict__.update(make_strategies_namespace(mock_xp).__dict__)
assert "xps" not in sys.modules
sys.modules["xps"] = mod


language = None

Expand Down Expand Up @@ -98,6 +107,7 @@ def setup(app):
"pypi": ("https://pypi.org/project/%s/", ""),
"bpo": ("https://bugs.python.org/issue%s", "bpo-"),
"np-ref": ("https://numpy.org/doc/stable/reference/%s", ""),
"xp-ref": ("https://data-apis.org/array-api/latest/API_specification/%s", ""),
"wikipedia": ("https://en.wikipedia.org/wiki/%s", ""),
}

Expand Down
38 changes: 38 additions & 0 deletions hypothesis-python/docs/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,41 @@ and confirmed working with every Pandas minor version from 0.25 through to 1.1.
Releases that are not the latest patch release of their minor version are not
tested or officially supported, but will probably also work unless you hit a
pandas bug.

.. _array-api:

---------
Array API
---------

.. tip::
The Array API standard is not yet finalised, so this module will make breaking
changes if necessary to support newer versions of the standard.

Hypothesis offers strategies for `Array API <https://data-apis.org/>`_ adopting
libraries in the ``hypothesis.extra.array_api`` package. See :issue:`3037` for
more details. If you want to test with :pypi:`CuPy`, :pypi:`Dask`, :pypi:`JAX`,
:pypi:`MXNet`, :pypi:`PyTorch <torch>`, :pypi:`TensorFlow`, or :pypi:`Xarray` -
or just ``numpy.array_api`` - this is the extension for you!

.. autofunction:: hypothesis.extra.array_api.make_strategies_namespace

The resulting namespace contains all our familiar strategies like
:func:`~xps.arrays` and :func:`~xps.from_dtype`, but based on the array-API
standard semantics and returning objects from the ``xp`` module:

.. automodule:: xps
:members:
from_dtype,
arrays,
array_shapes,
scalar_dtypes,
boolean_dtypes,
numeric_dtypes,
integer_dtypes,
unsigned_integer_dtypes,
floating_dtypes,
valid_tuple_axes,
broadcastable_shapes,
mutually_broadcastable_shapes,
indices,
Loading