Skip to content

Commit 8a327a3

Browse files
committed
Test elements in test_asarray_scalars
1 parent 76e974d commit 8a327a3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

array_api_tests/test_creation_functions.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from itertools import count
33
from typing import Iterator, NamedTuple, Union
44

5-
from hypothesis import assume, given
5+
from hypothesis import assume, given, note
66
from hypothesis import strategies as st
77

88
from . import _array_module as xp
@@ -214,15 +214,16 @@ def test_asarray_scalars(shape, data):
214214
elements_strat = xps.from_dtype(_dtype)
215215
size = math.prod(shape)
216216
obj_strat = st.lists(elements_strat, min_size=size, max_size=size)
217+
scalar_type = dh.get_scalar_type(_dtype)
217218
if dtype is None:
218219
# For asarray to infer the dtype we're testing, obj requires at least
219220
# one element to be the scalar equivalent of the inferred dtype, and so
220221
# we filter out invalid examples. Note we use type() as Python booleans
221222
# instance check with ints e.g. isinstance(False, int) == True.
222-
scalar_type = dh.get_scalar_type(_dtype)
223223
obj_strat = obj_strat.filter(lambda l: any(type(e) == scalar_type for e in l))
224-
obj_strat = obj_strat.map(lambda l: sh.reshape(l, shape))
225-
obj = data.draw(obj_strat, label="obj")
224+
_obj = data.draw(obj_strat, label="_obj")
225+
obj = sh.reshape(_obj, shape)
226+
note(f"{obj=}")
226227

227228
out = xp.asarray(obj, **kw)
228229

@@ -240,6 +241,9 @@ def test_asarray_scalars(shape, data):
240241
assert kw["dtype"] == _dtype # sanity check
241242
ph.assert_kw_dtype("asarray", _dtype, out.dtype)
242243
ph.assert_shape("asarray", out.shape, shape)
244+
for idx, v_expect in zip(sh.ndindex(out.shape), _obj):
245+
v = scalar_type(out[idx])
246+
ph.assert_scalar_equals("asarray", scalar_type, idx, v, v_expect, **kw)
243247

244248

245249
# TODO: test asarray with arrays and copy (in a seperate method)

0 commit comments

Comments
 (0)