Skip to content

Commit 8cef740

Browse files
authored
Apply w/a for expected result in spacing test only on non-Intel NumPy (#2453)
The stock NumPy returns incorrect result for `numpy.spacing(-0.0)`, while Intel NumPy returns the expected one (the same as dpnp also). It might be the case when dpnp test is running with the stock NumPy. Thus the PR add a conditional check to update expected result in `TestSpacing::test_zeros` in case when non-Intel NumPy is used. Previously the same logic was based on NumPy version, assuming Intel NumPy has always `version < "2.0.0"`, but it is not the case anymore.
1 parent fdf9ba7 commit 8cef740

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

dpnp/tests/helper.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,26 @@ def is_gpu_device(device=None):
414414
return dev.has_aspect_gpu
415415

416416

417+
def is_intel_numpy():
418+
"""
419+
Return True if Intel NumPy is used during testing.
420+
421+
The check is based on MKL backend name stored in Build Dependencies, where
422+
in case of Intel Numpy there "mkl" is expected at the beginning of the name
423+
for both BLAS and LAPACK (the full name is "mkl-dynamic-ilp64-iomp").
424+
425+
"""
426+
427+
build_deps = numpy.show_config(mode="dicts")["Build Dependencies"]
428+
blas = build_deps["blas"]
429+
lapack = build_deps["lapack"]
430+
431+
if numpy_version() < "2.0.0":
432+
# numpy 1.26.4 has LAPACK name equals to 'dep140030038112336'
433+
return blas["name"].startswith("mkl")
434+
return all(dep["name"].startswith("mkl") for dep in [blas, lapack])
435+
436+
417437
def is_win_platform():
418438
"""
419439
Return True if a test is running on Windows OS, False otherwise.

dpnp/tests/test_mathematical.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
get_integer_float_dtypes,
3333
has_support_aspect16,
3434
has_support_aspect64,
35+
is_intel_numpy,
3536
numpy_version,
3637
)
3738
from .third_party.cupy import testing
@@ -1751,11 +1752,11 @@ def test_zeros(self, dt):
17511752

17521753
result = dpnp.spacing(ia)
17531754
expected = numpy.spacing(a)
1754-
if numpy_version() < "2.0.0":
1755+
if is_intel_numpy():
17551756
assert_allclose(result, expected)
17561757
else:
1757-
# numpy.spacing(-0.0) == numpy.spacing(0.0), i.e. NumPy returns
1758-
# positive value (looks as a bug in NumPy), because for any other
1758+
# numpy.spacing(-0.0) == numpy.spacing(0.0), i.e. the stock NumPy
1759+
# returns positive value (looks as a bug), because for any other
17591760
# negative input the NumPy result will be also a negative value.
17601761
expected[1] *= -1
17611762
assert_allclose(result, expected)

0 commit comments

Comments
 (0)