- Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_array_helpers.py
35 lines (25 loc) · 1.38 KB
/
test_array_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fromhypothesisimportgiven
fromhypothesisimportstrategiesasst
fromarray_api_testsimport_array_moduleasxp
fromarray_api_tests.hypothesis_helpersimport (int_dtypes, arrays,
two_mutually_broadcastable_shapes)
fromarray_api_tests.shape_helpersimportiter_indices, broadcast_shapes
fromarray_api_tests .array_helpersimportexactly_equal, notequal, less
# TODO: These meta-tests currently only work with NumPy
deftest_exactly_equal():
a=xp.asarray([0, 0., -0., -0., xp.nan, xp.nan, 1, 1])
b=xp.asarray([0, -1, -0., 0., xp.nan, 1, 1, 2])
res=xp.asarray([True, False, True, False, True, False, True, False])
assertxp.all(xp.equal(exactly_equal(a, b), res))
deftest_notequal():
a=xp.asarray([0, 0., -0., -0., xp.nan, xp.nan, 1, 1])
b=xp.asarray([0, -1, -0., 0., xp.nan, 1, 1, 2])
res=xp.asarray([False, True, False, False, False, True, False, True])
assertxp.all(xp.equal(notequal(a, b), res))
@given(two_mutually_broadcastable_shapes, int_dtypes, int_dtypes, st.data())
deftest_less(shapes, dtype1, dtype2, data):
x=data.draw(arrays(shape=shapes[0], dtype=dtype1))
y=data.draw(arrays(shape=shapes[1], dtype=dtype2))
res=less(x, y)
fori, j, kiniter_indices(x.shape, y.shape, broadcast_shapes(x.shape, y.shape)):
assertres[k] == (int(x[i]) <int(y[j]))