Skip to content

Commit abc795e

Browse files
committed
remove redundant tests for comparison functions
1 parent 68f2874 commit abc795e

File tree

6 files changed

+6
-791
lines changed

6 files changed

+6
-791
lines changed

dpctl/tests/elementwise/test_equal.py

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import ctypes
18-
1917
import numpy as np
2018
import pytest
2119

22-
import dpctl
2320
import dpctl.tensor as dpt
2421
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
2522

26-
from .utils import _all_dtypes, _compare_dtypes, _usm_types
23+
from .utils import _all_dtypes, _compare_dtypes
2724

2825

2926
@pytest.mark.parametrize("op1_dtype", _all_dtypes)
@@ -60,131 +57,10 @@ def test_equal_dtype_matrix(op1_dtype, op2_dtype):
6057
assert (dpt.asnumpy(r) == np.full(r.shape, True, dtype=r.dtype)).all()
6158

6259

63-
@pytest.mark.parametrize("op1_usm_type", _usm_types)
64-
@pytest.mark.parametrize("op2_usm_type", _usm_types)
65-
def test_equal_usm_type_matrix(op1_usm_type, op2_usm_type):
66-
get_queue_or_skip()
67-
68-
sz = 128
69-
ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type)
70-
ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type)
71-
72-
r = dpt.equal(ar1, ar2)
73-
assert isinstance(r, dpt.usm_ndarray)
74-
expected_usm_type = dpctl.utils.get_coerced_usm_type(
75-
(op1_usm_type, op2_usm_type)
76-
)
77-
assert r.usm_type == expected_usm_type
78-
79-
80-
def test_equal_order():
81-
get_queue_or_skip()
82-
83-
ar1 = dpt.ones((20, 20), dtype="i4", order="C")
84-
ar2 = dpt.ones((20, 20), dtype="i4", order="C")
85-
r1 = dpt.equal(ar1, ar2, order="C")
86-
assert r1.flags.c_contiguous
87-
r2 = dpt.equal(ar1, ar2, order="F")
88-
assert r2.flags.f_contiguous
89-
r3 = dpt.equal(ar1, ar2, order="A")
90-
assert r3.flags.c_contiguous
91-
r4 = dpt.equal(ar1, ar2, order="K")
92-
assert r4.flags.c_contiguous
93-
94-
ar1 = dpt.ones((20, 20), dtype="i4", order="F")
95-
ar2 = dpt.ones((20, 20), dtype="i4", order="F")
96-
r1 = dpt.equal(ar1, ar2, order="C")
97-
assert r1.flags.c_contiguous
98-
r2 = dpt.equal(ar1, ar2, order="F")
99-
assert r2.flags.f_contiguous
100-
r3 = dpt.equal(ar1, ar2, order="A")
101-
assert r3.flags.f_contiguous
102-
r4 = dpt.equal(ar1, ar2, order="K")
103-
assert r4.flags.f_contiguous
104-
105-
ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2]
106-
ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2]
107-
r4 = dpt.equal(ar1, ar2, order="K")
108-
assert r4.strides == (20, -1)
109-
110-
ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT
111-
ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT
112-
r4 = dpt.equal(ar1, ar2, order="K")
113-
assert r4.strides == (-1, 20)
114-
115-
116-
def test_equal_broadcasting():
117-
get_queue_or_skip()
118-
119-
m = dpt.ones((100, 5), dtype="i4")
120-
v = dpt.arange(5, dtype="i4")
121-
122-
r = dpt.equal(m, v)
123-
expected = np.full((100, 5), [False, True, False, False, False], dtype="?")
124-
125-
assert (dpt.asnumpy(r) == expected).all()
126-
127-
r2 = dpt.equal(v, m)
128-
assert (dpt.asnumpy(r2) == expected).all()
129-
130-
r3 = dpt.empty_like(m, dtype="?")
131-
dpt.equal(m, v, out=r3)
132-
assert (dpt.asnumpy(r3) == expected).all()
133-
134-
135-
@pytest.mark.parametrize("arr_dt", _all_dtypes)
136-
def test_equal_python_scalar(arr_dt):
137-
q = get_queue_or_skip()
138-
skip_if_dtype_not_supported(arr_dt, q)
139-
140-
X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q)
141-
py_zeros = (
142-
bool(0),
143-
int(0),
144-
float(0),
145-
complex(0),
146-
np.float32(0),
147-
ctypes.c_int(0),
148-
)
149-
for sc in py_zeros:
150-
R = dpt.equal(X, sc)
151-
assert isinstance(R, dpt.usm_ndarray)
152-
assert dpt.all(R)
153-
R = dpt.equal(sc, X)
154-
assert isinstance(R, dpt.usm_ndarray)
155-
assert dpt.all(R)
156-
157-
15860
class MockArray:
15961
def __init__(self, arr):
16062
self.data_ = arr
16163

16264
@property
16365
def __sycl_usm_array_interface__(self):
16466
return self.data_.__sycl_usm_array_interface__
165-
166-
167-
def test_equal_mock_array():
168-
get_queue_or_skip()
169-
a = dpt.arange(10)
170-
b = dpt.ones(10)
171-
c = MockArray(b)
172-
r = dpt.equal(a, c)
173-
assert isinstance(r, dpt.usm_ndarray)
174-
175-
176-
def test_equal_canary_mock_array():
177-
get_queue_or_skip()
178-
a = dpt.arange(10)
179-
180-
class Canary:
181-
def __init__(self):
182-
pass
183-
184-
@property
185-
def __sycl_usm_array_interface__(self):
186-
return None
187-
188-
c = Canary()
189-
with pytest.raises(ValueError):
190-
dpt.equal(a, c)

dpctl/tests/elementwise/test_greater.py

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import ctypes
18-
1917
import numpy as np
2018
import pytest
2119

22-
import dpctl
2320
import dpctl.tensor as dpt
2421
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
2522

26-
from .utils import _all_dtypes, _compare_dtypes, _usm_types
23+
from .utils import _all_dtypes, _compare_dtypes
2724

2825

2926
@pytest.mark.parametrize("op1_dtype", _all_dtypes)
@@ -136,135 +133,6 @@ def test_greater_complex_float():
136133
assert (dpt.asnumpy(r3) == expected3).all()
137134

138135

139-
@pytest.mark.parametrize("op1_usm_type", _usm_types)
140-
@pytest.mark.parametrize("op2_usm_type", _usm_types)
141-
def test_greater_usm_type_matrix(op1_usm_type, op2_usm_type):
142-
get_queue_or_skip()
143-
144-
sz = 128
145-
ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type)
146-
ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type)
147-
148-
r = dpt.greater(ar1, ar2)
149-
assert isinstance(r, dpt.usm_ndarray)
150-
expected_usm_type = dpctl.utils.get_coerced_usm_type(
151-
(op1_usm_type, op2_usm_type)
152-
)
153-
assert r.usm_type == expected_usm_type
154-
155-
156-
def test_greater_order():
157-
get_queue_or_skip()
158-
159-
ar1 = dpt.ones((20, 20), dtype="i4", order="C")
160-
ar2 = dpt.ones((20, 20), dtype="i4", order="C")
161-
r1 = dpt.greater(ar1, ar2, order="C")
162-
assert r1.flags.c_contiguous
163-
r2 = dpt.greater(ar1, ar2, order="F")
164-
assert r2.flags.f_contiguous
165-
r3 = dpt.greater(ar1, ar2, order="A")
166-
assert r3.flags.c_contiguous
167-
r4 = dpt.greater(ar1, ar2, order="K")
168-
assert r4.flags.c_contiguous
169-
170-
ar1 = dpt.ones((20, 20), dtype="i4", order="F")
171-
ar2 = dpt.ones((20, 20), dtype="i4", order="F")
172-
r1 = dpt.greater(ar1, ar2, order="C")
173-
assert r1.flags.c_contiguous
174-
r2 = dpt.greater(ar1, ar2, order="F")
175-
assert r2.flags.f_contiguous
176-
r3 = dpt.greater(ar1, ar2, order="A")
177-
assert r3.flags.f_contiguous
178-
r4 = dpt.greater(ar1, ar2, order="K")
179-
assert r4.flags.f_contiguous
180-
181-
ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2]
182-
ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2]
183-
r4 = dpt.greater(ar1, ar2, order="K")
184-
assert r4.strides == (20, -1)
185-
186-
ar1 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT
187-
ar2 = dpt.ones((40, 40), dtype="i4", order="C")[:20, ::-2].mT
188-
r4 = dpt.greater(ar1, ar2, order="K")
189-
assert r4.strides == (-1, 20)
190-
191-
192-
def test_greater_broadcasting():
193-
get_queue_or_skip()
194-
195-
m = dpt.ones((100, 5), dtype="i4")
196-
v = dpt.arange(1, 6, dtype="i4")
197-
198-
r = dpt.greater(m, v)
199-
200-
expected = np.greater(
201-
np.ones((100, 5), dtype="i4"), np.arange(1, 6, dtype="i4")
202-
)
203-
assert (dpt.asnumpy(r) == expected.astype(r.dtype)).all()
204-
205-
r2 = dpt.greater(v, m)
206-
expected2 = np.greater(
207-
np.arange(1, 6, dtype="i4"), np.ones((100, 5), dtype="i4")
208-
)
209-
assert (dpt.asnumpy(r2) == expected2.astype(r2.dtype)).all()
210-
211-
212-
@pytest.mark.parametrize("arr_dt", _all_dtypes)
213-
def test_greater_python_scalar(arr_dt):
214-
q = get_queue_or_skip()
215-
skip_if_dtype_not_supported(arr_dt, q)
216-
217-
X = dpt.ones((10, 10), dtype=arr_dt, sycl_queue=q)
218-
py_ones = (
219-
bool(1),
220-
int(1),
221-
float(1),
222-
complex(1),
223-
np.float32(1),
224-
ctypes.c_int(1),
225-
)
226-
for sc in py_ones:
227-
R = dpt.greater(X, sc)
228-
assert isinstance(R, dpt.usm_ndarray)
229-
R = dpt.greater(sc, X)
230-
assert isinstance(R, dpt.usm_ndarray)
231-
232-
233-
class MockArray:
234-
def __init__(self, arr):
235-
self.data_ = arr
236-
237-
@property
238-
def __sycl_usm_array_interface__(self):
239-
return self.data_.__sycl_usm_array_interface__
240-
241-
242-
def test_greater_mock_array():
243-
get_queue_or_skip()
244-
a = dpt.arange(10)
245-
b = dpt.ones(10)
246-
c = MockArray(b)
247-
r = dpt.greater(a, c)
248-
assert isinstance(r, dpt.usm_ndarray)
249-
250-
251-
def test_greater_canary_mock_array():
252-
get_queue_or_skip()
253-
a = dpt.arange(10)
254-
255-
class Canary:
256-
def __init__(self):
257-
pass
258-
259-
@property
260-
def __sycl_usm_array_interface__(self):
261-
return None
262-
263-
c = Canary()
264-
with pytest.raises(ValueError):
265-
dpt.greater(a, c)
266-
267-
268136
def test_greater_mixed_integer_kinds():
269137
get_queue_or_skip()
270138

0 commit comments

Comments
 (0)