|
5 | 5 | is_dask_namespace, is_jax_namespace, is_pydata_sparse_namespace,
|
6 | 6 | )
|
7 | 7 |
|
8 |
| -from array_api_compat import device, is_array_api_obj, is_writeable_array, to_device |
9 |
| - |
| 8 | +from array_api_compat import ( |
| 9 | + device, is_array_api_obj, is_writeable_array, size, to_device |
| 10 | +) |
10 | 11 | from ._helpers import import_, wrapped_libraries, all_libraries
|
11 | 12 |
|
12 | 13 | import pytest
|
@@ -92,6 +93,28 @@ def test_is_writeable_array_numpy():
|
92 | 93 | assert not is_writeable_array(x)
|
93 | 94 |
|
94 | 95 |
|
| 96 | +@pytest.mark.parametrize("library", all_libraries) |
| 97 | +def test_size(library): |
| 98 | + xp = import_(library) |
| 99 | + x = xp.asarray([1, 2, 3]) |
| 100 | + assert size(x) == 3 |
| 101 | + |
| 102 | + |
| 103 | +@pytest.mark.parametrize("library", all_libraries) |
| 104 | +def test_size_none(library): |
| 105 | + if library == "sparse": |
| 106 | + pytest.skip("No arange(); no indexing by sparse arrays") |
| 107 | + |
| 108 | + xp = import_(library) |
| 109 | + x = xp.arange(10) |
| 110 | + x = x[x < 5] |
| 111 | + |
| 112 | + # dask.array now has shape=(nan, ) and size=nan |
| 113 | + # ndonnx now has shape=(None, ) and size=None |
| 114 | + # Eager libraries have shape=(5, ) and size=5 |
| 115 | + assert size(x) in (None, 5) |
| 116 | + |
| 117 | + |
95 | 118 | @pytest.mark.parametrize("library", all_libraries)
|
96 | 119 | def test_device(library):
|
97 | 120 | xp = import_(library, wrapper=True)
|
|
0 commit comments