Skip to content

MAINT: changes to test_log.py to avoid RuntimeErrors #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions dpctl/tests/elementwise/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_log_out_type(dtype):
q = get_queue_or_skip()
skip_if_dtype_not_supported(dtype, q)

X = dpt.asarray(0, dtype=dtype, sycl_queue=q)
expected_dtype = np.log(np.array(0, dtype=dtype)).dtype
X = dpt.asarray(1, dtype=dtype, sycl_queue=q)
expected_dtype = np.log(np.array(1, dtype=dtype)).dtype
expected_dtype = _map_to_device_dtype(expected_dtype, q.sycl_device)
assert dpt.log(X).dtype == expected_dtype

Expand All @@ -44,7 +44,7 @@ def test_log_output_contig(dtype):

n_seq = 1027

X = dpt.linspace(0, 13, num=n_seq, dtype=dtype, sycl_queue=q)
X = dpt.linspace(1, 13, num=n_seq, dtype=dtype, sycl_queue=q)
Xnp = dpt.asnumpy(X)

Y = dpt.log(X)
Expand All @@ -60,7 +60,7 @@ def test_log_output_strided(dtype):

n_seq = 2 * 1027

X = dpt.linspace(0, 13, num=n_seq, dtype=dtype, sycl_queue=q)[::-2]
X = dpt.linspace(1, 13, num=n_seq, dtype=dtype, sycl_queue=q)[::-2]
Xnp = dpt.asnumpy(X)

Y = dpt.log(X)
Expand Down Expand Up @@ -119,11 +119,15 @@ def test_log_special_cases():
q = get_queue_or_skip()

X = dpt.asarray(
[dpt.nan, -1.0, 0.0, -0.0, dpt.inf, -dpt.inf], dtype="f4", sycl_queue=q
[dpt.nan, -dpt.inf, -1.0, -0.0, 0.0, dpt.inf], dtype="f4", sycl_queue=q
)
Y = dpt.log(X)

expected = np.array(
[np.nan, np.nan, np.nan, -np.inf, -np.inf, np.inf], dtype="f4"
)
Xnp = dpt.asnumpy(X)

assert_equal(dpt.asnumpy(dpt.log(X)), np.log(Xnp))
assert_equal(dpt.asnumpy(Y), expected)


@pytest.mark.parametrize("dtype", ["f2", "f4", "f8", "c8", "c16"])
Expand Down