Skip to content

Commit bd9b01f

Browse files
committed
test newer dask
2 parents 035969e + f3145b0 commit bd9b01f

30 files changed

+365
-110
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Array API Tests (NumPy 1.26)
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
array-api-tests-numpy-latest:
7+
uses: ./.github/workflows/array-api-tests.yml
8+
with:
9+
package-name: numpy
10+
package-version: '== 1.26.*'
11+
xfails-file-extra: '-1-26'

.github/workflows/array-api-tests-torch.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ jobs:
1010
# Proper linalg testing will require
1111
# https://github.com/data-apis/array-api-tests/pull/101
1212
pytest-extra-args: "--disable-extension linalg"
13+
extra-env-vars: |
14+
ARRAY_API_TESTS_SKIP_DTYPES=uint16,uint32,uint64

.github/workflows/array-api-tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ on:
2727
skips-file-extra:
2828
required: false
2929
type: string
30-
30+
extra-env-vars:
31+
required: false
32+
type: string
33+
description: "Multiline string of environment variables to set for the test run."
3134

3235
env:
3336
PYTEST_ARGS: "--max-examples 200 -v -rxXfE --ci ${{ inputs.pytest-extra-args }} --hypothesis-disable-deadline"
@@ -54,6 +57,11 @@ jobs:
5457
uses: actions/setup-python@v5
5558
with:
5659
python-version: ${{ matrix.python-version }}
60+
- name: Set Extra Environment Variables
61+
# Set additional environment variables if provided
62+
if: inputs.extra-env-vars
63+
run: |
64+
echo "${{ inputs.extra-env-vars }}" >> $GITHUB_ENV
5765
- name: Install dependencies
5866
# NumPy 1.21 doesn't support Python 3.11. There doesn't seem to be a way
5967
# to put this in the numpy 1.21 config file.

.github/workflows/docs-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Download Artifact
16-
uses: dawidd6/action-download-artifact@v3
16+
uses: dawidd6/action-download-artifact@v6
1717
with:
1818
workflow: docs-build.yml
1919
name: docs-build

.github/workflows/publish-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
if: >-
9595
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags'))
9696
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
97-
uses: pypa/gh-action-pypi-publish@v1.8.14
97+
uses: pypa/gh-action-pypi-publish@v1.9.0
9898
with:
9999
repository-url: https://test.pypi.org/legacy/
100100
print-hash: true
@@ -107,6 +107,6 @@ jobs:
107107

108108
- name: Publish distribution 📦 to PyPI
109109
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
110-
uses: pypa/gh-action-pypi-publish@v1.8.14
110+
uses: pypa/gh-action-pypi-publish@v1.9.0
111111
with:
112112
print-hash: true

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
strategy:
77
matrix:
88
python-version: ['3.9', '3.10', '3.11', '3.12']
9-
numpy-version: ['1.21', '1.26', 'dev']
9+
numpy-version: ['1.21', '1.26', '2.0', 'dev']
1010
exclude:
1111
- python-version: '3.11'
1212
numpy-version: '1.21'
@@ -28,6 +28,11 @@ jobs:
2828
else
2929
PIP_EXTRA='numpy==1.26.*'
3030
fi
31+
32+
if [ "${{ matrix.python-version }}" == "3.9" ]; then
33+
sed -i '/^ndonnx/d' requirements-dev.txt
34+
fi
35+
3136
python -m pip install -r requirements-dev.txt $PIP_EXTRA
3237
3338
- name: Run Tests

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This is a small wrapper around common array libraries that is compatible with
44
the [Array API standard](https://data-apis.org/array-api/latest/). Currently,
5-
NumPy, CuPy, PyTorch, Dask, JAX and `sparse` are supported. If you want support
6-
for other array libraries, or if you encounter any issues, please [open an
7-
issue](https://github.com/data-apis/array-api-compat/issues).
5+
NumPy, CuPy, PyTorch, Dask, JAX, ndonnx and `sparse` are supported. If you want
6+
support for other array libraries, or if you encounter any issues, please [open
7+
an issue](https://github.com/data-apis/array-api-compat/issues).
88

99
See the documentation for more details https://data-apis.org/array-api-compat/

array_api_compat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
this implementation for the default when working with NumPy arrays.
1818
1919
"""
20-
__version__ = '1.6'
20+
__version__ = '1.8'
2121

2222
from .common import * # noqa: F401, F403

array_api_compat/common/_aliases.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import NamedTuple
1313
import inspect
1414

15-
from ._helpers import _check_device
15+
from ._helpers import array_namespace, _check_device
1616

1717
# These functions are modified from the NumPy versions.
1818

@@ -264,6 +264,66 @@ def var(
264264
) -> ndarray:
265265
return xp.var(x, axis=axis, ddof=correction, keepdims=keepdims, **kwargs)
266266

267+
268+
# The min and max argument names in clip are different and not optional in numpy, and type
269+
# promotion behavior is different.
270+
def clip(
271+
x: ndarray,
272+
/,
273+
min: Optional[Union[int, float, ndarray]] = None,
274+
max: Optional[Union[int, float, ndarray]] = None,
275+
*,
276+
xp,
277+
# TODO: np.clip has other ufunc kwargs
278+
out: Optional[ndarray] = None,
279+
) -> ndarray:
280+
def _isscalar(a):
281+
return isinstance(a, (int, float, type(None)))
282+
min_shape = () if _isscalar(min) else min.shape
283+
max_shape = () if _isscalar(max) else max.shape
284+
result_shape = xp.broadcast_shapes(x.shape, min_shape, max_shape)
285+
286+
wrapped_xp = array_namespace(x)
287+
288+
# np.clip does type promotion but the array API clip requires that the
289+
# output have the same dtype as x. We do this instead of just downcasting
290+
# the result of xp.clip() to handle some corner cases better (e.g.,
291+
# avoiding uint64 -> float64 promotion).
292+
293+
# Note: cases where min or max overflow (integer) or round (float) in the
294+
# wrong direction when downcasting to x.dtype are unspecified. This code
295+
# just does whatever NumPy does when it downcasts in the assignment, but
296+
# other behavior could be preferred, especially for integers. For example,
297+
# this code produces:
298+
299+
# >>> clip(asarray(0, dtype=int8), asarray(128, dtype=int16), None)
300+
# -128
301+
302+
# but an answer of 0 might be preferred. See
303+
# https://github.com/numpy/numpy/issues/24976 for more discussion on this issue.
304+
305+
306+
# At least handle the case of Python integers correctly (see
307+
# https://github.com/numpy/numpy/pull/26892).
308+
if type(min) is int and min <= xp.iinfo(x.dtype).min:
309+
min = None
310+
if type(max) is int and max >= xp.iinfo(x.dtype).max:
311+
max = None
312+
313+
if out is None:
314+
out = wrapped_xp.asarray(xp.broadcast_to(x, result_shape), copy=True)
315+
if min is not None:
316+
a = xp.broadcast_to(xp.asarray(min), result_shape)
317+
ia = (out < a) | xp.isnan(a)
318+
# torch requires an explicit cast here
319+
out[ia] = wrapped_xp.astype(a[ia], out.dtype)
320+
if max is not None:
321+
b = xp.broadcast_to(xp.asarray(max), result_shape)
322+
ib = (out > b) | xp.isnan(b)
323+
out[ib] = wrapped_xp.astype(b[ib], out.dtype)
324+
# Return a scalar for 0-D
325+
return out[()]
326+
267327
# Unlike transpose(), the axes argument to permute_dims() is required.
268328
def permute_dims(x: ndarray, /, axes: Tuple[int, ...], xp) -> ndarray:
269329
return xp.transpose(x, axes)
@@ -465,6 +525,6 @@ def isdtype(
465525
'linspace', 'ones', 'ones_like', 'zeros', 'zeros_like',
466526
'UniqueAllResult', 'UniqueCountsResult', 'UniqueInverseResult',
467527
'unique_all', 'unique_counts', 'unique_inverse', 'unique_values',
468-
'astype', 'std', 'var', 'permute_dims', 'reshape', 'argsort',
528+
'astype', 'std', 'var', 'clip', 'permute_dims', 'reshape', 'argsort',
469529
'sort', 'nonzero', 'sum', 'prod', 'ceil', 'floor', 'trunc',
470530
'matmul', 'matrix_transpose', 'tensordot', 'vecdot', 'isdtype']

0 commit comments

Comments
 (0)