Skip to content

Commit e97a5d8

Browse files
committed
Update tests
1 parent 101365d commit e97a5d8

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

dpnp/tests/test_linalg.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,15 @@ def test_cholesky_errors(self):
278278

279279

280280
class TestCond:
281+
_norms = [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
282+
281283
def setup_method(self):
282284
numpy.random.seed(70)
283285

284286
@pytest.mark.parametrize(
285-
"shape", [(0, 4, 4), (4, 0, 3, 3)], ids=["(0, 5, 3)", "(4, 0, 2, 3)"]
286-
)
287-
@pytest.mark.parametrize(
288-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
287+
"shape", [(0, 4, 4), (4, 0, 3, 3)], ids=["(0, 4, 4)", "(4, 0, 3, 3)"]
289288
)
289+
@pytest.mark.parametrize("p", _norms)
290290
def test_empty(self, shape, p):
291291
a = numpy.empty(shape)
292292
ia = dpnp.array(a)
@@ -295,26 +295,27 @@ def test_empty(self, shape, p):
295295
expected = numpy.linalg.cond(a, p=p)
296296
assert_dtype_allclose(result, expected)
297297

298+
# TODO: uncomment once numpy 2.3.3 release is published
299+
# @testing.with_requires("numpy>=2.3.3")
298300
@pytest.mark.parametrize(
299301
"dtype", get_all_dtypes(no_none=True, no_bool=True)
300302
)
301303
@pytest.mark.parametrize(
302304
"shape", [(4, 4), (2, 4, 3, 3)], ids=["(4, 4)", "(2, 4, 3, 3)"]
303305
)
304-
@pytest.mark.parametrize(
305-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
306-
)
306+
@pytest.mark.parametrize("p", _norms)
307307
def test_basic(self, dtype, shape, p):
308308
a = generate_random_numpy_array(shape, dtype)
309309
ia = dpnp.array(a)
310310

311311
result = dpnp.linalg.cond(ia, p=p)
312312
expected = numpy.linalg.cond(a, p=p)
313+
# TODO: remove when numpy#29333 is released
314+
if numpy_version() < "2.3.3":
315+
expected = expected.real
313316
assert_dtype_allclose(result, expected, factor=16)
314317

315-
@pytest.mark.parametrize(
316-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
317-
)
318+
@pytest.mark.parametrize("p", _norms)
318319
def test_bool(self, p):
319320
a = numpy.array([[True, True], [True, False]])
320321
ia = dpnp.array(a)
@@ -323,9 +324,7 @@ def test_bool(self, p):
323324
expected = numpy.linalg.cond(a, p=p)
324325
assert_dtype_allclose(result, expected)
325326

326-
@pytest.mark.parametrize(
327-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
328-
)
327+
@pytest.mark.parametrize("p", _norms)
329328
def test_nan_to_inf(self, p):
330329
a = numpy.zeros((2, 2))
331330
ia = dpnp.array(a)
@@ -343,9 +342,7 @@ def test_nan_to_inf(self, p):
343342
else:
344343
assert_raises(dpnp.linalg.LinAlgError, dpnp.linalg.cond, ia, p=p)
345344

346-
@pytest.mark.parametrize(
347-
"p", [None, -dpnp.inf, -2, -1, 1, 2, dpnp.inf, "fro"]
348-
)
345+
@pytest.mark.parametrize("p", _norms)
349346
@pytest.mark.parametrize(
350347
"stride",
351348
[(-2, -3, 2, -2), (-2, 4, -4, -4), (2, 3, 4, 4), (-1, 3, 3, -3)],
@@ -367,11 +364,12 @@ def test_strided(self, p, stride):
367364
expected = numpy.linalg.cond(a, p=p)
368365
assert_dtype_allclose(result, expected, factor=24)
369366

370-
def test_error(self):
367+
@pytest.mark.parametrize("xp", [dpnp, numpy])
368+
def test_error(self, xp):
371369
# cond is not defined on empty arrays
372-
ia = dpnp.empty((2, 0))
370+
a = xp.empty((2, 0))
373371
with pytest.raises(ValueError):
374-
dpnp.linalg.cond(ia, p=1)
372+
xp.linalg.cond(a, p=1)
375373

376374

377375
class TestDet:

0 commit comments

Comments
 (0)