@@ -278,15 +278,15 @@ def test_cholesky_errors(self):
278
278
279
279
280
280
class TestCond :
281
+ _norms = [None , - dpnp .inf , - 2 , - 1 , 1 , 2 , dpnp .inf , "fro" ]
282
+
281
283
def setup_method (self ):
282
284
numpy .random .seed (70 )
283
285
284
286
@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)" ]
289
288
)
289
+ @pytest .mark .parametrize ("p" , _norms )
290
290
def test_empty (self , shape , p ):
291
291
a = numpy .empty (shape )
292
292
ia = dpnp .array (a )
@@ -295,26 +295,27 @@ def test_empty(self, shape, p):
295
295
expected = numpy .linalg .cond (a , p = p )
296
296
assert_dtype_allclose (result , expected )
297
297
298
+ # TODO: uncomment once numpy 2.3.3 release is published
299
+ # @testing.with_requires("numpy>=2.3.3")
298
300
@pytest .mark .parametrize (
299
301
"dtype" , get_all_dtypes (no_none = True , no_bool = True )
300
302
)
301
303
@pytest .mark .parametrize (
302
304
"shape" , [(4 , 4 ), (2 , 4 , 3 , 3 )], ids = ["(4, 4)" , "(2, 4, 3, 3)" ]
303
305
)
304
- @pytest .mark .parametrize (
305
- "p" , [None , - dpnp .inf , - 2 , - 1 , 1 , 2 , dpnp .inf , "fro" ]
306
- )
306
+ @pytest .mark .parametrize ("p" , _norms )
307
307
def test_basic (self , dtype , shape , p ):
308
308
a = generate_random_numpy_array (shape , dtype )
309
309
ia = dpnp .array (a )
310
310
311
311
result = dpnp .linalg .cond (ia , p = p )
312
312
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
313
316
assert_dtype_allclose (result , expected , factor = 16 )
314
317
315
- @pytest .mark .parametrize (
316
- "p" , [None , - dpnp .inf , - 2 , - 1 , 1 , 2 , dpnp .inf , "fro" ]
317
- )
318
+ @pytest .mark .parametrize ("p" , _norms )
318
319
def test_bool (self , p ):
319
320
a = numpy .array ([[True , True ], [True , False ]])
320
321
ia = dpnp .array (a )
@@ -323,9 +324,7 @@ def test_bool(self, p):
323
324
expected = numpy .linalg .cond (a , p = p )
324
325
assert_dtype_allclose (result , expected )
325
326
326
- @pytest .mark .parametrize (
327
- "p" , [None , - dpnp .inf , - 2 , - 1 , 1 , 2 , dpnp .inf , "fro" ]
328
- )
327
+ @pytest .mark .parametrize ("p" , _norms )
329
328
def test_nan_to_inf (self , p ):
330
329
a = numpy .zeros ((2 , 2 ))
331
330
ia = dpnp .array (a )
@@ -343,9 +342,7 @@ def test_nan_to_inf(self, p):
343
342
else :
344
343
assert_raises (dpnp .linalg .LinAlgError , dpnp .linalg .cond , ia , p = p )
345
344
346
- @pytest .mark .parametrize (
347
- "p" , [None , - dpnp .inf , - 2 , - 1 , 1 , 2 , dpnp .inf , "fro" ]
348
- )
345
+ @pytest .mark .parametrize ("p" , _norms )
349
346
@pytest .mark .parametrize (
350
347
"stride" ,
351
348
[(- 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):
367
364
expected = numpy .linalg .cond (a , p = p )
368
365
assert_dtype_allclose (result , expected , factor = 24 )
369
366
370
- def test_error (self ):
367
+ @pytest .mark .parametrize ("xp" , [dpnp , numpy ])
368
+ def test_error (self , xp ):
371
369
# cond is not defined on empty arrays
372
- ia = dpnp .empty ((2 , 0 ))
370
+ a = xp .empty ((2 , 0 ))
373
371
with pytest .raises (ValueError ):
374
- dpnp .linalg .cond (ia , p = 1 )
372
+ xp .linalg .cond (a , p = 1 )
375
373
376
374
377
375
class TestDet :
0 commit comments