|
25 | 25 | has_support_aspect64, |
26 | 26 | is_cpu_device, |
27 | 27 | is_cuda_device, |
| 28 | + numpy_version, |
28 | 29 | ) |
29 | 30 | from .third_party.cupy import testing |
30 | 31 |
|
@@ -2299,27 +2300,48 @@ def test_matrix_norm(self, ord, keepdims): |
2299 | 2300 | expected = numpy.linalg.matrix_norm(a, ord=ord, keepdims=keepdims) |
2300 | 2301 | assert_dtype_allclose(result, expected) |
2301 | 2302 |
|
| 2303 | + @pytest.mark.parametrize( |
| 2304 | + "xp", |
| 2305 | + [ |
| 2306 | + dpnp, |
| 2307 | + pytest.param( |
| 2308 | + numpy, |
| 2309 | + marks=pytest.mark.skipif( |
| 2310 | + numpy_version() < "2.3.0", |
| 2311 | + reason="numpy raises an error", |
| 2312 | + ), |
| 2313 | + ), |
| 2314 | + ], |
| 2315 | + ) |
2302 | 2316 | @pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32]) |
2303 | 2317 | @pytest.mark.parametrize( |
2304 | 2318 | "shape_axis", [[(2, 0), None], [(2, 0), (0, 1)], [(0, 2), (0, 1)]] |
2305 | 2319 | ) |
2306 | 2320 | @pytest.mark.parametrize("ord", [None, "fro", "nuc", 1, 2, dpnp.inf]) |
2307 | | - def test_matrix_norm_empty(self, dtype, shape_axis, ord): |
| 2321 | + def test_matrix_norm_empty(self, xp, dtype, shape_axis, ord): |
2308 | 2322 | shape, axis = shape_axis[0], shape_axis[1] |
2309 | | - x = dpnp.zeros(shape, dtype=dtype) |
2310 | | - |
2311 | | - # TODO: when similar changes in numpy are available, |
2312 | | - # instead of assert_equal with zero, we should compare with numpy |
2313 | | - assert_equal(dpnp.linalg.norm(x, axis=axis, ord=ord), 0) |
| 2323 | + x = xp.zeros(shape, dtype=dtype) |
| 2324 | + assert_equal(xp.linalg.norm(x, axis=axis, ord=ord), 0) |
2314 | 2325 |
|
| 2326 | + @pytest.mark.parametrize( |
| 2327 | + "xp", |
| 2328 | + [ |
| 2329 | + dpnp, |
| 2330 | + pytest.param( |
| 2331 | + numpy, |
| 2332 | + marks=pytest.mark.skipif( |
| 2333 | + numpy_version() < "2.3.0", |
| 2334 | + reason="numpy raises an error", |
| 2335 | + ), |
| 2336 | + ), |
| 2337 | + ], |
| 2338 | + ) |
2315 | 2339 | @pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32]) |
2316 | 2340 | @pytest.mark.parametrize("axis", [None, 0]) |
2317 | 2341 | @pytest.mark.parametrize("ord", [None, 1, 2, dpnp.inf]) |
2318 | | - def test_vector_norm_empty(self, dtype, axis, ord): |
2319 | | - x = dpnp.zeros(0, dtype=dtype) |
2320 | | - # TODO: when similar changes in numpy are available, |
2321 | | - # instead of assert_equal with zero, we should compare with numpy |
2322 | | - assert_equal(dpnp.linalg.vector_norm(x, axis=axis, ord=ord), 0) |
| 2342 | + def test_vector_norm_empty(self, xp, dtype, axis, ord): |
| 2343 | + x = xp.zeros(0, dtype=dtype) |
| 2344 | + assert_equal(xp.linalg.vector_norm(x, axis=axis, ord=ord), 0) |
2323 | 2345 |
|
2324 | 2346 | @testing.with_requires("numpy>=2.0") |
2325 | 2347 | @pytest.mark.parametrize( |
|
0 commit comments