Skip to content

Commit b7896b7

Browse files
Update test_singular_2D and test_singular_ND
1 parent 1979103 commit b7896b7

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

dpnp/tests/test_linalg.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,17 @@ def test_singular_2D(self, p):
330330
a = numpy.ones((2, 2))
331331
ia = dpnp.array(a)
332332

333-
# Unlike NumPy which returns `inf` for all norm orders,
333+
# NumPy returns `inf` for most norms on singular matrices,
334+
# and large (often meaningless) values for [None, 2, -2].
334335
# DPNP raises LinAlgError for 1, -1, inf, -inf, and 'fro'
335336
# due to use of gesv in 2D case.
336-
# For None, 2, and -2 DPNP matches NumPy behavior.
337+
# DPNP matches NumPy behavior for [None, 2, -2].
337338
if p in [None, 2, -2]:
339+
# Only ensure the function runs and returns non-infinite values.
338340
result = dpnp.linalg.cond(ia, p=p)
339341
expected = numpy.linalg.cond(a, p=p)
340-
assert_dtype_allclose(result, expected)
342+
assert not dpnp.any(dpnp.isinf(result))
343+
assert not numpy.any(numpy.isinf(expected))
341344
else:
342345
assert_raises(dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p)
343346

@@ -360,15 +363,19 @@ def test_singular_ND(self, shape, p):
360363
a = numpy.ones((shape))
361364
ia = dpnp.array(a)
362365

363-
# Unlike NumPy which returns `inf` for all norm orders,
366+
# NumPy returns `inf` for most norms on singular matrices,
367+
# and large (often meaningless) values for [None, 2, -2].
364368
# DPNP raises LinAlgError for 1, -1, inf, -inf, and 'fro'
365-
# due to use of dpnp.linalg.inv() with OneMKL >= 2025.2.
366-
# For None, 2, and -2 DPNP matches NumPy behavior.
369+
# due to use of dpnp.linalg.inv() with oneMKL >= 2025.2.
370+
# DPNP matches NumPy behavior for [None, 2, -2].
367371
if requires_intel_mkl_version("2025.2"):
368372
if p in [None, 2, -2]:
373+
# Only ensure the function runs and
374+
# returns non-infinite values.
369375
result = dpnp.linalg.cond(ia, p=p)
370376
expected = numpy.linalg.cond(a, p=p)
371-
assert_dtype_allclose(result, expected)
377+
assert not dpnp.any(dpnp.isinf(result))
378+
assert not numpy.any(numpy.isinf(expected))
372379
else:
373380
assert_raises(
374381
dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p

0 commit comments

Comments
 (0)