Skip to content

Commit bee99fa

Browse files
Ad test_nan_to_inf to improve coverage
1 parent ca1a118 commit bee99fa

File tree

1 file changed

+8
-42
lines changed

1 file changed

+8
-42
lines changed

dpnp/tests/test_linalg.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -326,62 +326,28 @@ def test_bool(self, p):
326326
@pytest.mark.parametrize(
327327
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
328328
)
329-
def test_singular_2D(self, p):
330-
a = numpy.array([[1, 2], [0, 0]])
329+
def test_nan_to_inf(self, p):
330+
a = numpy.zeros((2, 2))
331331
ia = dpnp.array(a)
332332

333333
# NumPy returns `inf` for most norms on singular matrices,
334334
# and zero for norm -2.
335335
# DPNP raises LinAlgError for 1, -1, inf, -inf, and 'fro'
336336
# due to use of gesv in 2D case.
337337
# DPNP matches NumPy behavior for [None, 2, -2].
338-
if p in [None, 2, -2]:
339-
result = dpnp.linalg.cond(ia, p=p)
340-
expected = numpy.linalg.cond(a, p=p)
341-
assert_dtype_allclose(result, expected)
342-
else:
343-
assert_raises(dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p)
344338

345-
@pytest.mark.parametrize(
346-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
347-
)
348-
def test_singular_ND(self, p):
349-
# dpnp.linalg.cond uses dpnp.linalg.inv()
350-
# for the case when p is not None or p != -2 or p != 2
351-
# For singular matrices cuSolver raises an error
352-
# while OneMKL < 2025.2 returns nans
353-
# TODO: remove it when mkl=2025.2 is released
354-
if (
355-
is_cuda_device()
356-
and not requires_intel_mkl_version("2025.2")
357-
and p in [-dpnp.inf, -1, 1, dpnp.inf, "fro"]
358-
):
359-
pytest.skip("Different behavior on CUDA")
360-
a = generate_random_numpy_array((2, 2, 2, 2))
361-
a[0, 0] = 0
362-
a[1, 1] = 1
363-
ia = dpnp.array(a)
364-
365-
# NumPy returns `inf` for most norms on singular matrices,
366-
# and zeros for norm -2.
339+
# NumPy does not raise LinAlgError on singular matrices.
340+
# It returns `inf`, `0`, or large/small finite values
341+
# depending on the norm and the matrix content.
367342
# DPNP raises LinAlgError for 1, -1, inf, -inf, and 'fro'
368-
# due to use of dpnp.linalg.inv() with oneMKL >= 2025.2.
369-
# DPNP matches NumPy behavior for [None, 2, -2].
343+
# due to use of gesv in the 2D case.
344+
# For [None, 2, -2], DPNP does not raise.
370345
if p in [None, 2, -2]:
371346
result = dpnp.linalg.cond(ia, p=p)
372347
expected = numpy.linalg.cond(a, p=p)
373348
assert_dtype_allclose(result, expected)
374-
elif requires_intel_mkl_version("2025.2"):
375-
assert_raises(dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p)
376-
# With oneMKL < 2025.2 and norms: 1, -1, inf, -inf, 'fro',
377-
# dpnp.linalg.inv() uses getrf_batch + getri_batch
378-
# which do not raise LinAlgError.
379-
# Instead, the result contains `inf` for each 2D batch
380-
# in the input array that is singular
381349
else:
382-
result = dpnp.linalg.cond(ia, p=p)
383-
expected = numpy.linalg.cond(a, p=p)
384-
assert_dtype_allclose(result, expected)
350+
assert_raises(dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p)
385351

386352
@pytest.mark.parametrize(
387353
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]

0 commit comments

Comments
 (0)