Skip to content

Commit 69feed8

Browse files
author
Vahid Tavanashad
committed
update test_nanfunctions.py
1 parent edf2dbf commit 69feed8

File tree

8 files changed

+210
-233
lines changed

8 files changed

+210
-233
lines changed

dpnp/tests/conftest.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import numpy
3333
import pytest
3434

35+
from . import config as dtype_config
36+
3537
if numpy.lib.NumpyVersion(numpy.__version__) >= "2.0.0b1":
3638
from numpy.exceptions import ComplexWarning
3739
else:
@@ -128,20 +130,25 @@ def pytest_collection_modifyitems(config, items):
128130

129131
dev = dpctl.select_default_device()
130132
is_cpu = dev.is_cpu
131-
is_gpu_no_fp64 = not dev.has_aspect_fp64
133+
is_gpu = dev.is_gpu
134+
is_gpu_w_fp64 = dev.has_aspect_fp64
132135
is_cuda = dpnp.is_cuda_backend(dev)
133136

134137
print("")
138+
print(
139+
f"DPNP Test scope includes all integer dtypes: {bool(dtype_config.all_int_types)}"
140+
)
135141
print(f"DPNP current device is CPU: {is_cpu}")
136-
print(f"DPNP current device is GPU without fp64 support: {is_gpu_no_fp64}")
142+
print(f"DPNP current device is GPU: {is_gpu}")
143+
print(f"DPNP current device is GPU with fp64 support: {is_gpu_w_fp64}")
137144
print(f"DPNP current device is GPU with cuda backend: {is_cuda}")
138145
print(f"DPNP version: {dpnp.__version__}, location: {dpnp}")
139146
print(f"NumPy version: {numpy.__version__}, location: {numpy}")
140147
print(f"Python version: {sys.version}")
141148
print("")
142-
if not is_cpu or os.getenv("DPNP_QUEUE_GPU") == "1":
149+
if is_gpu or os.getenv("DPNP_QUEUE_GPU") == "1":
143150
excluded_tests.extend(get_excluded_tests(test_exclude_file_gpu))
144-
if is_gpu_no_fp64:
151+
if not is_gpu_w_fp64:
145152
excluded_tests.extend(
146153
get_excluded_tests(test_exclude_file_gpu_no_fp64)
147154
)

dpnp/tests/test_indexing.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,15 +1200,17 @@ def test_empty_indices_error(self):
12001200
)
12011201

12021202
def test_empty_indices(self):
1203-
assert_equal(
1204-
dpnp.ravel_multi_index(
1205-
(dpnp.array([], dtype=int), dpnp.array([], dtype=int)), (5, 3)
1206-
),
1207-
[],
1208-
)
1209-
assert_equal(
1210-
dpnp.ravel_multi_index(dpnp.array([[], []], dtype=int), (5, 3)), []
1211-
)
1203+
a = numpy.array([], dtype=int)
1204+
ia = dpnp.array(a)
1205+
result = dpnp.ravel_multi_index((ia, ia), (5, 3))
1206+
expected = numpy.ravel_multi_index((a, a), (5, 3))
1207+
assert_equal(result, expected)
1208+
1209+
a = numpy.array([[], []], dtype=int)
1210+
ia = dpnp.array(a)
1211+
result = dpnp.ravel_multi_index(ia, (5, 3))
1212+
expected = numpy.ravel_multi_index(a, (5, 3))
1213+
assert_equal(result, expected)
12121214

12131215

12141216
class TestUnravelIndex:

dpnp/tests/test_linalg.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ def test_empty(self, shape, p):
293293
expected = numpy.linalg.cond(a, p=p)
294294
assert_dtype_allclose(result, expected)
295295

296-
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
296+
@pytest.mark.parametrize(
297+
"dtype", get_all_dtypes(no_none=True, no_bool=True)
298+
)
297299
@pytest.mark.parametrize(
298300
"shape", [(4, 4), (2, 4, 3, 3)], ids=["(4, 4)", "(2, 4, 3, 3)"]
299301
)
@@ -2408,11 +2410,7 @@ def test_qr(self, dtype, shape, mode):
24082410
if mode in ("complete", "reduced"):
24092411
result = dpnp.linalg.qr(ia, mode)
24102412
dpnp_q, dpnp_r = result.Q, result.R
2411-
assert_almost_equal(
2412-
dpnp.matmul(dpnp_q, dpnp_r),
2413-
a,
2414-
decimal=5,
2415-
)
2413+
assert dpnp.allclose(dpnp.matmul(dpnp_q, dpnp_r), ia)
24162414
else: # mode=="raw"
24172415
dpnp_q, dpnp_r = dpnp.linalg.qr(ia, mode)
24182416
assert_dtype_allclose(dpnp_q, np_q, factor=24)
@@ -2424,15 +2422,13 @@ def test_qr(self, dtype, shape, mode):
24242422
@pytest.mark.parametrize(
24252423
"shape",
24262424
[(32, 32), (8, 16, 16)],
2427-
ids=[
2428-
"(32, 32)",
2429-
"(8, 16, 16)",
2430-
],
2425+
ids=["(32, 32)", "(8, 16, 16)"],
24312426
)
24322427
@pytest.mark.parametrize("mode", ["r", "raw", "complete", "reduced"])
24332428
def test_qr_large(self, dtype, shape, mode):
24342429
a = generate_random_numpy_array(shape, dtype, seed_value=81)
24352430
ia = dpnp.array(a)
2431+
24362432
if mode == "r":
24372433
np_r = numpy.linalg.qr(a, mode)
24382434
dpnp_r = dpnp.linalg.qr(ia, mode)
@@ -2443,11 +2439,7 @@ def test_qr_large(self, dtype, shape, mode):
24432439
if mode in ("complete", "reduced"):
24442440
result = dpnp.linalg.qr(ia, mode)
24452441
dpnp_q, dpnp_r = result.Q, result.R
2446-
assert_almost_equal(
2447-
dpnp.matmul(dpnp_q, dpnp_r),
2448-
a,
2449-
decimal=5,
2450-
)
2442+
assert dpnp.allclose(dpnp.matmul(dpnp_q, dpnp_r), ia, atol=1e-4)
24512443
else: # mode=="raw"
24522444
dpnp_q, dpnp_r = dpnp.linalg.qr(ia, mode)
24532445
assert_allclose(dpnp_q, np_q, atol=1e-4)
@@ -3169,9 +3161,7 @@ def test_test_tensorinv_errors(self):
31693161
class TestTensorsolve:
31703162
@pytest.mark.parametrize("dtype", get_all_dtypes())
31713163
@pytest.mark.parametrize(
3172-
"axes",
3173-
[None, (1,), (2,)],
3174-
ids=["None", "(1,)", "(2,)"],
3164+
"axes", [None, (1,), (2,)], ids=["None", "(1,)", "(2,)"]
31753165
)
31763166
def test_tensorsolve_axes(self, dtype, axes):
31773167
a = numpy.eye(12).reshape(12, 3, 4).astype(dtype)

0 commit comments

Comments
 (0)