Skip to content

Commit d1ee2b0

Browse files
committed
remove unnecessary tests related to exponential and logarithm functions
1 parent 539634e commit d1ee2b0

File tree

8 files changed

+16
-610
lines changed

8 files changed

+16
-610
lines changed

dpctl/tests/elementwise/test_exp.py

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +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 _all_dtypes, _map_to_device_dtype, _usm_types
26+
from .utils import _all_dtypes, _map_to_device_dtype
2727

2828

2929
@pytest.mark.parametrize("dtype", _all_dtypes)
@@ -38,7 +38,7 @@ def test_exp_out_type(dtype):
3838

3939

4040
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8"])
41-
def test_exp_real_contig(dtype):
41+
def test_exp_real(dtype):
4242
q = get_queue_or_skip()
4343
skip_if_dtype_not_supported(dtype, q)
4444

@@ -60,7 +60,7 @@ def test_exp_real_contig(dtype):
6060

6161

6262
@pytest.mark.parametrize("dtype", ["c8", "c16"])
63-
def test_exp_complex_contig(dtype):
63+
def test_exp_complex(dtype):
6464
q = get_queue_or_skip()
6565
skip_if_dtype_not_supported(dtype, q)
6666

@@ -88,52 +88,6 @@ def test_exp_complex_contig(dtype):
8888
)
8989

9090

91-
@pytest.mark.parametrize("usm_type", _usm_types)
92-
def test_exp_usm_type(usm_type):
93-
q = get_queue_or_skip()
94-
95-
arg_dt = np.dtype("f4")
96-
input_shape = (10, 10, 10, 10)
97-
X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q)
98-
X[..., 0::2] = 16.0
99-
X[..., 1::2] = 23.0
100-
101-
Y = dpt.exp(X)
102-
assert Y.usm_type == X.usm_type
103-
assert Y.sycl_queue == X.sycl_queue
104-
assert Y.flags.c_contiguous
105-
106-
expected_Y = np.empty(input_shape, dtype=arg_dt)
107-
expected_Y[..., 0::2] = np.exp(np.float32(16.0))
108-
expected_Y[..., 1::2] = np.exp(np.float32(23.0))
109-
tol = 8 * dpt.finfo(Y.dtype).resolution
110-
111-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
112-
113-
114-
@pytest.mark.parametrize("dtype", _all_dtypes)
115-
def test_exp_order(dtype):
116-
q = get_queue_or_skip()
117-
skip_if_dtype_not_supported(dtype, q)
118-
119-
arg_dt = np.dtype(dtype)
120-
input_shape = (10, 10, 10, 10)
121-
X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q)
122-
X[..., 0::2] = 8.0
123-
X[..., 1::2] = 11.0
124-
125-
for perms in itertools.permutations(range(4)):
126-
U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms)
127-
expected_Y = np.exp(dpt.asnumpy(U))
128-
for ord in ["C", "F", "A", "K"]:
129-
Y = dpt.exp(U, order=ord)
130-
tol = 8 * max(
131-
dpt.finfo(Y.dtype).resolution,
132-
np.finfo(expected_Y.dtype).resolution,
133-
)
134-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
135-
136-
13791
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8"])
13892
def test_exp_analytical_values(dtype):
13993
q = get_queue_or_skip()
@@ -163,57 +117,6 @@ def test_exp_real_special_cases(dtype):
163117
assert_array_equal(np.signbit(Y), np.signbit(Ynp))
164118

165119

166-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8"])
167-
def test_exp_real_strided(dtype):
168-
q = get_queue_or_skip()
169-
skip_if_dtype_not_supported(dtype, q)
170-
171-
np.random.seed(42)
172-
strides = np.array([-4, -3, -2, -1, 1, 2, 3, 4])
173-
sizes = [2, 4, 6, 8, 9, 24, 72]
174-
tol = 8 * dpt.finfo(dtype).resolution
175-
176-
for ii in sizes:
177-
Xnp = np.random.uniform(low=0.01, high=88.1, size=ii)
178-
Xnp.astype(dtype)
179-
X = dpt.asarray(Xnp)
180-
Ynp = np.exp(Xnp)
181-
for jj in strides:
182-
assert_allclose(
183-
dpt.asnumpy(dpt.exp(X[::jj])),
184-
Ynp[::jj],
185-
atol=tol,
186-
rtol=tol,
187-
)
188-
189-
190-
@pytest.mark.parametrize("dtype", ["c8", "c16"])
191-
def test_exp_complex_strided(dtype):
192-
q = get_queue_or_skip()
193-
skip_if_dtype_not_supported(dtype, q)
194-
195-
np.random.seed(42)
196-
strides = np.array([-4, -3, -2, -1, 1, 2, 3, 4])
197-
sizes = [2, 4, 6, 8, 9, 24, 72]
198-
tol = 8 * dpt.finfo(dtype).resolution
199-
200-
low = -88.0
201-
high = 88.0
202-
for ii in sizes:
203-
x1 = np.random.uniform(low=low, high=high, size=ii)
204-
x2 = np.random.uniform(low=low, high=high, size=ii)
205-
Xnp = np.array([complex(v1, v2) for v1, v2 in zip(x1, x2)], dtype=dtype)
206-
X = dpt.asarray(Xnp)
207-
Ynp = np.exp(Xnp)
208-
for jj in strides:
209-
assert_allclose(
210-
dpt.asnumpy(dpt.exp(X[::jj])),
211-
Ynp[::jj],
212-
atol=tol,
213-
rtol=tol,
214-
)
215-
216-
217120
@pytest.mark.parametrize("dtype", ["c8", "c16"])
218121
def test_exp_complex_special_cases(dtype):
219122
q = get_queue_or_skip()

dpctl/tests/elementwise/test_exp2.py

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

17-
import itertools
18-
1917
import numpy as np
2018
import pytest
2119
from numpy.testing import assert_allclose
2220

2321
import dpctl.tensor as dpt
2422
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
2523

26-
from .utils import _all_dtypes, _map_to_device_dtype, _usm_types
24+
from .utils import _all_dtypes, _map_to_device_dtype
2725

2826

2927
@pytest.mark.parametrize("dtype", _all_dtypes)
@@ -38,7 +36,7 @@ def test_exp2_out_type(dtype):
3836

3937

4038
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
41-
def test_exp2_output_contig(dtype):
39+
def test_exp2_basic(dtype):
4240
q = get_queue_or_skip()
4341
skip_if_dtype_not_supported(dtype, q)
4442

@@ -53,68 +51,6 @@ def test_exp2_output_contig(dtype):
5351
assert_allclose(dpt.asnumpy(Y), np.exp2(Xnp), atol=tol, rtol=tol)
5452

5553

56-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
57-
def test_exp2_output_strided(dtype):
58-
q = get_queue_or_skip()
59-
skip_if_dtype_not_supported(dtype, q)
60-
61-
n_seq = 2 * 1027
62-
63-
X = dpt.linspace(1, 5, num=n_seq, dtype=dtype, sycl_queue=q)[::-2]
64-
Xnp = dpt.asnumpy(X)
65-
66-
Y = dpt.exp2(X)
67-
tol = 8 * dpt.finfo(Y.dtype).resolution
68-
69-
assert_allclose(dpt.asnumpy(Y), np.exp2(Xnp), atol=tol, rtol=tol)
70-
71-
72-
@pytest.mark.parametrize("usm_type", _usm_types)
73-
def test_exp2_usm_type(usm_type):
74-
q = get_queue_or_skip()
75-
76-
arg_dt = np.dtype("f4")
77-
input_shape = (10, 10, 10, 10)
78-
X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q)
79-
X[..., 0::2] = 1 / 4
80-
X[..., 1::2] = 1 / 2
81-
82-
Y = dpt.exp2(X)
83-
assert Y.usm_type == X.usm_type
84-
assert Y.sycl_queue == X.sycl_queue
85-
assert Y.flags.c_contiguous
86-
87-
expected_Y = np.empty(input_shape, dtype=arg_dt)
88-
expected_Y[..., 0::2] = np.exp2(np.float32(1 / 4))
89-
expected_Y[..., 1::2] = np.exp2(np.float32(1 / 2))
90-
tol = 8 * dpt.finfo(Y.dtype).resolution
91-
92-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
93-
94-
95-
@pytest.mark.parametrize("dtype", _all_dtypes)
96-
def test_exp2_order(dtype):
97-
q = get_queue_or_skip()
98-
skip_if_dtype_not_supported(dtype, q)
99-
100-
arg_dt = np.dtype(dtype)
101-
input_shape = (10, 10, 10, 10)
102-
X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q)
103-
X[..., 0::2] = 1 / 4
104-
X[..., 1::2] = 1 / 2
105-
106-
for perms in itertools.permutations(range(4)):
107-
U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms)
108-
expected_Y = np.exp2(dpt.asnumpy(U))
109-
for ord in ["C", "F", "A", "K"]:
110-
Y = dpt.exp2(U, order=ord)
111-
tol = 8 * max(
112-
dpt.finfo(Y.dtype).resolution,
113-
np.finfo(expected_Y.dtype).resolution,
114-
)
115-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
116-
117-
11854
def test_exp2_special_cases():
11955
get_queue_or_skip()
12056

dpctl/tests/elementwise/test_expm1.py

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

17-
import itertools
18-
1917
import numpy as np
2018
import pytest
2119
from numpy.testing import assert_allclose
2220

2321
import dpctl.tensor as dpt
2422
from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported
2523

26-
from .utils import _all_dtypes, _map_to_device_dtype, _usm_types
24+
from .utils import _all_dtypes, _map_to_device_dtype
2725

2826

2927
@pytest.mark.parametrize("dtype", _all_dtypes)
@@ -38,7 +36,7 @@ def test_expm1_out_type(dtype):
3836

3937

4038
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
41-
def test_expm1_output_contig(dtype):
39+
def test_expm1_basic(dtype):
4240
q = get_queue_or_skip()
4341
skip_if_dtype_not_supported(dtype, q)
4442

@@ -53,68 +51,6 @@ def test_expm1_output_contig(dtype):
5351
assert_allclose(dpt.asnumpy(Y), np.expm1(Xnp), atol=tol, rtol=tol)
5452

5553

56-
@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
57-
def test_expm1_output_strided(dtype):
58-
q = get_queue_or_skip()
59-
skip_if_dtype_not_supported(dtype, q)
60-
61-
n_seq = 2 * 1027
62-
63-
X = dpt.linspace(-2, 2, num=n_seq, dtype=dtype, sycl_queue=q)[::-2]
64-
Xnp = dpt.asnumpy(X)
65-
66-
Y = dpt.expm1(X)
67-
tol = 8 * dpt.finfo(Y.dtype).resolution
68-
69-
assert_allclose(dpt.asnumpy(Y), np.expm1(Xnp), atol=tol, rtol=tol)
70-
71-
72-
@pytest.mark.parametrize("usm_type", _usm_types)
73-
def test_expm1_usm_type(usm_type):
74-
q = get_queue_or_skip()
75-
76-
arg_dt = np.dtype("f4")
77-
input_shape = (10, 10, 10, 10)
78-
X = dpt.empty(input_shape, dtype=arg_dt, usm_type=usm_type, sycl_queue=q)
79-
X[..., 0::2] = 1 / 50
80-
X[..., 1::2] = 1 / 25
81-
82-
Y = dpt.expm1(X)
83-
assert Y.usm_type == X.usm_type
84-
assert Y.sycl_queue == X.sycl_queue
85-
assert Y.flags.c_contiguous
86-
87-
expected_Y = np.empty(input_shape, dtype=arg_dt)
88-
expected_Y[..., 0::2] = np.expm1(np.float32(1 / 50))
89-
expected_Y[..., 1::2] = np.expm1(np.float32(1 / 25))
90-
tol = 8 * dpt.finfo(Y.dtype).resolution
91-
92-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
93-
94-
95-
@pytest.mark.parametrize("dtype", _all_dtypes)
96-
def test_expm1_order(dtype):
97-
q = get_queue_or_skip()
98-
skip_if_dtype_not_supported(dtype, q)
99-
100-
arg_dt = np.dtype(dtype)
101-
input_shape = (10, 10, 10, 10)
102-
X = dpt.empty(input_shape, dtype=arg_dt, sycl_queue=q)
103-
X[..., 0::2] = 1 / 50
104-
X[..., 1::2] = 1 / 25
105-
106-
for perms in itertools.permutations(range(4)):
107-
U = dpt.permute_dims(X[:, ::-1, ::-1, :], perms)
108-
expected_Y = np.expm1(dpt.asnumpy(U))
109-
for ord in ["C", "F", "A", "K"]:
110-
Y = dpt.expm1(U, order=ord)
111-
tol = 8 * max(
112-
dpt.finfo(Y.dtype).resolution,
113-
np.finfo(expected_Y.dtype).resolution,
114-
)
115-
assert_allclose(dpt.asnumpy(Y), expected_Y, atol=tol, rtol=tol)
116-
117-
11854
def test_expm1_special_cases():
11955
get_queue_or_skip()
12056

0 commit comments

Comments
 (0)