Skip to content

Commit 66eaf79

Browse files
committed
Removed redundant overlap tests
Also rewrote overlap test for abs to only use a single dtype
1 parent 1277ba6 commit 66eaf79

File tree

8 files changed

+10
-199
lines changed

8 files changed

+10
-199
lines changed

dpctl/tests/elementwise/test_abs.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@
2323
import dpctl.tensor as dpt
2424
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
2525

26-
from .utils import (
27-
_all_dtypes,
28-
_complex_fp_dtypes,
29-
_no_complex_dtypes,
30-
_real_fp_dtypes,
31-
_usm_types,
32-
)
26+
from .utils import _all_dtypes, _complex_fp_dtypes, _real_fp_dtypes, _usm_types
3327

3428

3529
@pytest.mark.parametrize("dtype", _all_dtypes)
@@ -131,26 +125,21 @@ def test_abs_complex(dtype):
131125
)
132126

133127

134-
@pytest.mark.parametrize("dtype", _no_complex_dtypes)
135-
def test_abs_out_overlap(dtype):
136-
q = get_queue_or_skip()
137-
skip_if_dtype_not_supported(dtype, q)
138-
139-
X = dpt.linspace(0, 35, 60, dtype=dtype, sycl_queue=q)
140-
X = dpt.reshape(X, (3, 5, 4))
141-
142-
Xnp = dpt.asnumpy(X)
143-
Ynp = np.abs(Xnp, out=Xnp)
128+
def test_abs_out_overlap():
129+
get_queue_or_skip()
144130

131+
X = dpt.arange(-3, 3, 1, dtype="i4")
132+
expected = dpt.asarray([3, 2, 1, 0, 1, 2], dtype="i4")
145133
Y = dpt.abs(X, out=X)
134+
146135
assert Y is X
147-
assert np.allclose(dpt.asnumpy(X), Xnp)
136+
assert dpt.all(expected == X)
148137

149-
Ynp = np.abs(Xnp, out=Xnp[::-1])
138+
X = dpt.arange(-3, 3, 1, dtype="i4")
139+
expected = expected[::-1]
150140
Y = dpt.abs(X, out=X[::-1])
151141
assert Y is not X
152-
assert np.allclose(dpt.asnumpy(X), Xnp)
153-
assert np.allclose(dpt.asnumpy(Y), Ynp)
142+
assert dpt.all(expected == X)
154143

155144

156145
@pytest.mark.parametrize("dtype", _real_fp_dtypes)

dpctl/tests/elementwise/test_exp.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,3 @@ def test_exp_complex_special_cases(dtype):
216216
tol = 8 * dpt.finfo(dtype).resolution
217217
assert_allclose(dpt.asnumpy(dpt.real(Y)), np.real(Ynp), atol=tol, rtol=tol)
218218
assert_allclose(dpt.asnumpy(dpt.imag(Y)), np.imag(Ynp), atol=tol, rtol=tol)
219-
220-
221-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
222-
def test_exp_out_overlap(dtype):
223-
q = get_queue_or_skip()
224-
skip_if_dtype_not_supported(dtype, q)
225-
226-
X = dpt.linspace(0, 1, 15, dtype=dtype, sycl_queue=q)
227-
X = dpt.reshape(X, (3, 5))
228-
229-
Xnp = dpt.asnumpy(X)
230-
Ynp = np.exp(Xnp, out=Xnp)
231-
232-
Y = dpt.exp(X, out=X)
233-
tol = 8 * dpt.finfo(Y.dtype).resolution
234-
assert Y is X
235-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
236-
237-
Ynp = np.exp(Xnp, out=Xnp[::-1])
238-
Y = dpt.exp(X, out=X[::-1])
239-
assert Y is not X
240-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
241-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)

dpctl/tests/elementwise/test_hyperbolic.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -292,29 +292,3 @@ def test_hyper_complex_special_cases(np_call, dpt_call, dtype):
292292
assert_allclose(
293293
dpt.asnumpy(dpt.imag(dpt_call(Xc))), np.imag(Ynp), atol=tol, rtol=tol
294294
)
295-
296-
297-
@pytest.mark.parametrize("np_call, dpt_call", _all_funcs)
298-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
299-
def test_hyper_out_overlap(np_call, dpt_call, dtype):
300-
q = get_queue_or_skip()
301-
skip_if_dtype_not_supported(dtype, q)
302-
303-
X = dpt.linspace(-np.pi / 2, np.pi / 2, 60, dtype=dtype, sycl_queue=q)
304-
X = dpt.reshape(X, (3, 5, 4))
305-
306-
tol = 8 * dpt.finfo(dtype).resolution
307-
Xnp = dpt.asnumpy(X)
308-
with np.errstate(all="ignore"):
309-
Ynp = np_call(Xnp, out=Xnp)
310-
311-
Y = dpt_call(X, out=X)
312-
assert Y is X
313-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
314-
315-
with np.errstate(all="ignore"):
316-
Ynp = np_call(Xnp, out=Xnp[::-1])
317-
Y = dpt_call(X, out=X[::-1])
318-
assert Y is not X
319-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
320-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)

dpctl/tests/elementwise/test_log.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,3 @@ def test_log_special_cases():
128128
)
129129

130130
assert_equal(dpt.asnumpy(Y), expected)
131-
132-
133-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
134-
def test_log_out_overlap(dtype):
135-
q = get_queue_or_skip()
136-
skip_if_dtype_not_supported(dtype, q)
137-
138-
X = dpt.linspace(5, 35, 60, dtype=dtype, sycl_queue=q)
139-
X = dpt.reshape(X, (3, 5, 4))
140-
141-
Xnp = dpt.asnumpy(X)
142-
Ynp = np.log(Xnp, out=Xnp)
143-
144-
Y = dpt.log(X, out=X)
145-
assert Y is X
146-
147-
tol = 8 * dpt.finfo(Y.dtype).resolution
148-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
149-
150-
Ynp = np.log(Xnp, out=Xnp[::-1])
151-
Y = dpt.log(X, out=X[::-1])
152-
assert Y is not X
153-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
154-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)

dpctl/tests/elementwise/test_round.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,3 @@ def test_round_complex_special_cases(dtype):
213213
tol = 8 * dpt.finfo(dtype).resolution
214214
assert_allclose(dpt.asnumpy(dpt.real(Y)), np.real(Ynp), atol=tol, rtol=tol)
215215
assert_allclose(dpt.asnumpy(dpt.imag(Y)), np.imag(Ynp), atol=tol, rtol=tol)
216-
217-
218-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
219-
def test_round_out_overlap(dtype):
220-
q = get_queue_or_skip()
221-
skip_if_dtype_not_supported(dtype, q)
222-
223-
X = dpt.linspace(0, 1, 15, dtype=dtype, sycl_queue=q)
224-
X = dpt.reshape(X, (3, 5))
225-
226-
Xnp = dpt.asnumpy(X)
227-
Ynp = np.round(Xnp, out=Xnp)
228-
229-
Y = dpt.round(X, out=X)
230-
tol = 8 * dpt.finfo(Y.dtype).resolution
231-
assert Y is X
232-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
233-
234-
Ynp = np.round(Xnp, out=Xnp[::-1])
235-
Y = dpt.round(X, out=X[::-1])
236-
assert Y is not X
237-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
238-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)

dpctl/tests/elementwise/test_sqrt.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,6 @@ def test_sqrt_order(dtype):
122122
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
123123

124124

125-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
126-
def test_sqrt_out_overlap(dtype):
127-
q = get_queue_or_skip()
128-
skip_if_dtype_not_supported(dtype, q)
129-
130-
X = dpt.linspace(0, 35, 60, dtype=dtype, sycl_queue=q)
131-
X = dpt.reshape(X, (3, 5, 4))
132-
133-
Xnp = dpt.asnumpy(X)
134-
Ynp = np.sqrt(Xnp, out=Xnp)
135-
136-
Y = dpt.sqrt(X, out=X)
137-
assert Y is X
138-
139-
tol = 8 * dpt.finfo(Y.dtype).resolution
140-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
141-
142-
Ynp = np.sqrt(Xnp, out=Xnp[::-1])
143-
Y = dpt.sqrt(X, out=X[::-1])
144-
assert Y is not X
145-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
146-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)
147-
148-
149125
@pytest.mark.usefixtures("suppress_invalid_numpy_warnings")
150126
def test_sqrt_special_cases():
151127
q = get_queue_or_skip()

dpctl/tests/elementwise/test_square.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,3 @@ def test_square_special_cases(dtype):
9797
rtol=tol,
9898
equal_nan=True,
9999
)
100-
101-
102-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
103-
def test_square_out_overlap(dtype):
104-
q = get_queue_or_skip()
105-
skip_if_dtype_not_supported(dtype, q)
106-
107-
X = dpt.linspace(0, 35, 60, dtype=dtype, sycl_queue=q)
108-
X = dpt.reshape(X, (3, 5, 4))
109-
110-
Xnp = dpt.asnumpy(X)
111-
Ynp = np.square(Xnp, out=Xnp)
112-
113-
Y = dpt.square(X, out=X)
114-
assert Y is X
115-
assert np.allclose(dpt.asnumpy(X), Xnp)
116-
117-
X = dpt.linspace(0, 35, 60, dtype=dtype, sycl_queue=q)
118-
X = dpt.reshape(X, (3, 5, 4))
119-
Xnp = dpt.asnumpy(X)
120-
121-
Ynp = np.square(Xnp, out=Xnp[::-1])
122-
Y = dpt.square(X, out=X[::-1])
123-
assert Y is not X
124-
assert np.allclose(dpt.asnumpy(X), Xnp)
125-
assert np.allclose(dpt.asnumpy(Y), Ynp)

dpctl/tests/elementwise/test_trigonometric.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,3 @@ def test_trig_complex_special_cases(np_call, dpt_call, dtype):
289289
assert_allclose(
290290
dpt.asnumpy(dpt.imag(dpt_call(Xc))), np.imag(Ynp), atol=tol, rtol=tol
291291
)
292-
293-
294-
@pytest.mark.parametrize("np_call, dpt_call", _all_funcs)
295-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
296-
def test_trig_out_overlap(np_call, dpt_call, dtype):
297-
q = get_queue_or_skip()
298-
skip_if_dtype_not_supported(dtype, q)
299-
300-
if np_call == np.tan:
301-
X = dpt.linspace(-np.pi / 2, np.pi / 2, 64, dtype=dtype, sycl_queue=q)[
302-
2:-2
303-
]
304-
tol = 50 * dpt.finfo(dtype).resolution
305-
else:
306-
X = dpt.linspace(-np.pi / 2, np.pi / 2, 60, dtype=dtype, sycl_queue=q)
307-
tol = 8 * dpt.finfo(dtype).resolution
308-
X = dpt.reshape(X, (3, 5, 4))
309-
310-
Xnp = dpt.asnumpy(X)
311-
with np.errstate(all="ignore"):
312-
Ynp = np_call(Xnp, out=Xnp)
313-
314-
Y = dpt_call(X, out=X)
315-
assert Y is X
316-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
317-
318-
with np.errstate(all="ignore"):
319-
Ynp = np_call(Xnp, out=Xnp[::-1])
320-
Y = dpt_call(X, out=X[::-1])
321-
assert Y is not X
322-
assert_allclose(dpt.asnumpy(X), Xnp, atol=tol, rtol=tol)
323-
assert_allclose(dpt.asnumpy(Y), Ynp, atol=tol, rtol=tol)

0 commit comments

Comments
 (0)