Skip to content

Commit 0252928

Browse files
committed
Merge branch 'main' into test_all
2 parents 7b9da30 + ecadf5b commit 0252928

File tree

8 files changed

+116
-61
lines changed

8 files changed

+116
-61
lines changed

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.12.dev0'
20+
__version__ = '1.13.0.dev0'
2121

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

array_api_compat/dask/array/_aliases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def asarray(
170170
return obj.copy() if copy else obj # pyright: ignore[reportAttributeAccessIssue]
171171

172172
if copy is False:
173-
raise NotImplementedError(
173+
raise ValueError(
174174
"Unable to avoid copy when converting a non-dask object to dask"
175175
)
176176

array_api_compat/numpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
__import__(__package__ + ".fft")
2626

27-
from .linalg import matrix_transpose, vecdot # noqa: F401
27+
from .linalg import matrix_transpose, vecdot # type: ignore[no-redef] # noqa: F401
2828

2929
__array_api_version__: Final = "2024.12"
3030

cupy-xfails.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_sc
3939
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[logaddexp]
4040
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[nextafter]
4141
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[hypot]
42+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[atan2]
43+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[divide]
44+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[copysign]
45+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[divide]
46+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[maximum]
4247

4348
# cupy (arg)min/max wrong with infinities
4449
# https://github.com/cupy/cupy/issues/7424

docs/changelog.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
# Changelog
22

3+
## 1.12.0 (2025-05-13)
4+
5+
6+
### Major changes
7+
8+
- The build system has been updated to use `pyproject.toml` instead of `setup.py`
9+
- Support for Python 3.9 has been dropped. The minimum supported Python version is now
10+
3.10; the minimum supported NumPy version is 1.22.
11+
- The `linalg` extension works correctly with `pytorch>=2.7`.
12+
- Multiple improvements to handling of devices in CuPy and PyTorch backends.
13+
Support for multiple devices in CuPy is still immature and you should use
14+
context managers rather than relying on input-output device propagation or
15+
on the `device` parameter. Please report any issues you encounter.
16+
17+
### Minor changes
18+
19+
- `finfo` and `iinfo` functions now accept array arguments, in accordance with the
20+
Array API spec;
21+
- `torch.asarray` function propagates the device of the input array. This works around
22+
the [pytorch issue #150199](https://github.com/pytorch/pytorch/issues/150199);
23+
- `torch.repeat` function is now available;
24+
- `torch.count_nonzero` function now correctly handles the case of a tuple `axis`
25+
arguments and `keepdims=True`;
26+
- `torch.meshgrid` wrapper defaults to `indexing="xy"`, in accordance with the
27+
array API specification;
28+
- `cupy.asarray` function now implements the `copy=False` argument, albeit
29+
at the cost of risking to make a temporary copy.
30+
- In `numpy.take_along_axis` and `cupy.take_along_axis` the `axis` parameter now
31+
defaults to -1, in accordance to the Array API spec.
32+
33+
34+
The following users contributed to this release:
35+
36+
Evgeni Burovski,
37+
Lucas Colley,
38+
Neil Girdhar,
39+
Joren Hammudoglu,
40+
Guido Imperiale
41+
42+
343
## 1.11.2 (2025-03-20)
444

545
This is a bugfix release with no new features compared to version 1.11.

numpy-1-22-xfails.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_sc
131131
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[nextafter]
132132
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[multiply]
133133
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[maximum]
134+
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[minimum]
134135
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[copysign]
135136
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[pow]
136137
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[pow]

tests/test_common.py

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ def test_asarray_cross_library(source_library, target_library, request):
268268
assert b.dtype == tgt_lib.int32
269269

270270

271-
272271
@pytest.mark.parametrize("library", wrapped_libraries)
273272
def test_asarray_copy(library):
274273
# Note, we have this test here because the test suite currently doesn't
@@ -278,100 +277,87 @@ def test_asarray_copy(library):
278277
xp = import_(library, wrapper=True)
279278
asarray = xp.asarray
280279
is_lib_func = globals()[is_array_functions[library]]
281-
all = xp.all if library != 'dask.array' else lambda x: xp.all(x).compute()
282-
283-
if library == 'cupy':
284-
supports_copy_false_other_ns = False
285-
supports_copy_false_same_ns = False
286-
elif library == 'dask.array':
287-
supports_copy_false_other_ns = False
288-
supports_copy_false_same_ns = True
289-
else:
290-
supports_copy_false_other_ns = True
291-
supports_copy_false_same_ns = True
292280

293281
a = asarray([1])
294282
b = asarray(a, copy=True)
295283
assert is_lib_func(b)
296284
a[0] = 0
297-
assert all(b[0] == 1)
298-
assert all(a[0] == 0)
285+
assert b[0] == 1
286+
assert a[0] == 0
299287

300288
a = asarray([1])
301-
if supports_copy_false_same_ns:
302-
b = asarray(a, copy=False)
303-
assert is_lib_func(b)
304-
a[0] = 0
305-
assert all(b[0] == 0)
306-
else:
307-
pytest.raises(NotImplementedError, lambda: asarray(a, copy=False))
308289

309-
a = asarray([1])
310-
if supports_copy_false_same_ns:
311-
pytest.raises(ValueError, lambda: asarray(a, copy=False,
312-
dtype=xp.float64))
313-
else:
314-
pytest.raises(NotImplementedError, lambda: asarray(a, copy=False, dtype=xp.float64))
290+
# Test copy=False within the same namespace
291+
b = asarray(a, copy=False)
292+
assert is_lib_func(b)
293+
a[0] = 0
294+
assert b[0] == 0
295+
with pytest.raises(ValueError):
296+
asarray(a, copy=False, dtype=xp.float64)
315297

298+
# copy=None defaults to False when possible
316299
a = asarray([1])
317300
b = asarray(a, copy=None)
318301
assert is_lib_func(b)
319302
a[0] = 0
320-
assert all(b[0] == 0)
303+
assert b[0] == 0
321304

305+
# copy=None defaults to True when impossible
322306
a = asarray([1.0], dtype=xp.float32)
323307
assert a.dtype == xp.float32
324308
b = asarray(a, dtype=xp.float64, copy=None)
325309
assert is_lib_func(b)
326310
assert b.dtype == xp.float64
327311
a[0] = 0.0
328-
assert all(b[0] == 1.0)
312+
assert b[0] == 1.0
329313

314+
# copy=None defaults to False when possible
330315
a = asarray([1.0], dtype=xp.float64)
331316
assert a.dtype == xp.float64
332317
b = asarray(a, dtype=xp.float64, copy=None)
333318
assert is_lib_func(b)
334319
assert b.dtype == xp.float64
335320
a[0] = 0.0
336-
assert all(b[0] == 0.0)
321+
assert b[0] == 0.0
337322

338323
# Python built-in types
339324
for obj in [True, 0, 0.0, 0j, [0], [[0]]]:
340-
asarray(obj, copy=True) # No error
341-
asarray(obj, copy=None) # No error
342-
if supports_copy_false_other_ns:
343-
pytest.raises(ValueError, lambda: asarray(obj, copy=False))
344-
else:
345-
pytest.raises(NotImplementedError, lambda: asarray(obj, copy=False))
325+
asarray(obj, copy=True) # No error
326+
asarray(obj, copy=None) # No error
327+
328+
with pytest.raises(ValueError):
329+
asarray(obj, copy=False)
346330

347331
# Use the standard library array to test the buffer protocol
348-
a = array.array('f', [1.0])
332+
a = array.array("f", [1.0])
349333
b = asarray(a, copy=True)
350334
assert is_lib_func(b)
351335
a[0] = 0.0
352-
assert all(b[0] == 1.0)
336+
assert b[0] == 1.0
353337

354-
a = array.array('f', [1.0])
355-
if supports_copy_false_other_ns:
338+
a = array.array("f", [1.0])
339+
if library in ("cupy", "dask.array"):
340+
with pytest.raises(ValueError):
341+
asarray(a, copy=False)
342+
else:
356343
b = asarray(a, copy=False)
357344
assert is_lib_func(b)
358345
a[0] = 0.0
359-
assert all(b[0] == 0.0)
360-
else:
361-
pytest.raises(NotImplementedError, lambda: asarray(a, copy=False))
346+
assert b[0] == 0.0
362347

363-
a = array.array('f', [1.0])
348+
a = array.array("f", [1.0])
364349
b = asarray(a, copy=None)
365350
assert is_lib_func(b)
366351
a[0] = 0.0
367-
if library in ('cupy', 'dask.array'):
352+
if library in ("cupy", "dask.array"):
368353
# A copy is required for libraries where the default device is not CPU
369354
# dask changed behaviour of copy=None in 2024.12 to copy;
370355
# this wrapper ensures the same behaviour in older versions too.
371356
# https://github.com/dask/dask/pull/11524/
372-
assert all(b[0] == 1.0)
357+
assert b[0] == 1.0
373358
else:
374-
assert all(b[0] == 0.0)
359+
# copy=None defaults to False when possible
360+
assert b[0] == 0.0
375361

376362

377363
@pytest.mark.parametrize("library", ["numpy", "cupy", "torch"])

tests/test_cupy.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,41 @@
55
from cupy.cuda import Stream
66

77

8-
def test_to_device_with_stream():
8+
@pytest.mark.parametrize(
9+
"make_stream",
10+
[
11+
lambda: Stream(),
12+
lambda: Stream(non_blocking=True),
13+
lambda: Stream(null=True),
14+
lambda: Stream(ptds=True),
15+
],
16+
)
17+
def test_to_device_with_stream(make_stream):
918
devices = xp.__array_namespace_info__().devices()
10-
streams = [
11-
Stream(),
12-
Stream(non_blocking=True),
13-
Stream(null=True),
14-
Stream(ptds=True),
15-
123, # dlpack stream
16-
]
1719

1820
a = xp.asarray([1, 2, 3])
1921
for dev in devices:
20-
for stream in streams:
21-
b = to_device(a, dev, stream=stream)
22-
assert device(b) == dev
22+
# Streams are device-specific and must be created within
23+
# the context of the device...
24+
with dev:
25+
stream = make_stream()
26+
# ... however, to_device() does not need to be inside the
27+
# device context.
28+
b = to_device(a, dev, stream=stream)
29+
assert device(b) == dev
30+
31+
32+
def test_to_device_with_dlpack_stream():
33+
devices = xp.__array_namespace_info__().devices()
34+
35+
a = xp.asarray([1, 2, 3])
36+
for dev in devices:
37+
# Streams are device-specific and must be created within
38+
# the context of the device...
39+
with dev:
40+
s1 = Stream()
41+
42+
# ... however, to_device() does not need to be inside the
43+
# device context.
44+
b = to_device(a, dev, stream=s1.ptr)
45+
assert device(b) == dev

0 commit comments

Comments
 (0)