Skip to content

Commit 885f35d

Browse files
committed
test eager_shape
1 parent c0d9f5d commit 885f35d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tests/test_helpers.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from array_api_extra._lib import Backend
88
from array_api_extra._lib._testing import xp_assert_equal
99
from array_api_extra._lib._utils._compat import device as get_device
10-
from array_api_extra._lib._utils._helpers import asarrays, in1d, ndindex
10+
from array_api_extra._lib._utils._helpers import asarrays, eager_shape, in1d, ndindex
1111
from array_api_extra._lib._utils._typing import Array, Device, DType
1212
from array_api_extra.testing import lazy_xp_function
1313

@@ -156,3 +156,20 @@ def test_numpy_generics(self, dtype: DType):
156156
)
157157
def test_ndindex(shape: tuple[int, ...]):
158158
assert tuple(ndindex(*shape)) == tuple(np.ndindex(*shape))
159+
160+
161+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="index by sparse array")
162+
def test_eager_shape(xp: ModuleType, library: Backend):
163+
a = xp.asarray([1, 2, 3])
164+
# Lazy arrays, like Dask, have an eager shape until you slice them with
165+
# a lazy boolean mask
166+
assert eager_shape(a) == a.shape == (3,)
167+
168+
b = a[a > 2]
169+
if library is Backend.DASK:
170+
with pytest.raises(TypeError, match="Unsupported lazy shape"):
171+
_ = eager_shape(b)
172+
# FIXME can't test use case for None in the shape until we add support for
173+
# other lazy backends
174+
else:
175+
assert eager_shape(b) == b.shape == (1,)

0 commit comments

Comments
 (0)