|
23 | 23 | get_integer_float_dtypes,
|
24 | 24 | has_support_aspect64,
|
25 | 25 | is_cpu_device,
|
26 |
| - is_cuda_device, |
27 | 26 | numpy_version,
|
28 | 27 | requires_intel_mkl_version,
|
29 | 28 | )
|
@@ -2104,11 +2103,14 @@ def test_empty(self, shape, ord, axis, keepdims):
|
2104 | 2103 | assert_raises(ValueError, dpnp.linalg.norm, ia, **kwarg)
|
2105 | 2104 | assert_raises(ValueError, numpy.linalg.norm, a, **kwarg)
|
2106 | 2105 | else:
|
2107 |
| - # TODO: when similar changes in numpy are available, instead |
2108 |
| - # of assert_equal with zero, we should compare with numpy |
2109 |
| - # ord in [None, 1, 2] |
2110 |
| - assert_equal(dpnp.linalg.norm(ia, **kwarg), 0.0) |
2111 |
| - assert_raises(ValueError, numpy.linalg.norm, a, **kwarg) |
| 2106 | + if numpy_version() >= "2.3.0": |
| 2107 | + result = dpnp.linalg.norm(ia, **kwarg) |
| 2108 | + expected = numpy.linalg.norm(a, **kwarg) |
| 2109 | + assert_dtype_allclose(result, expected) |
| 2110 | + else: |
| 2111 | + assert_equal( |
| 2112 | + dpnp.linalg.norm(ia, **kwarg), 0.0, strict=False |
| 2113 | + ) |
2112 | 2114 | else:
|
2113 | 2115 | result = dpnp.linalg.norm(ia, **kwarg)
|
2114 | 2116 | expected = numpy.linalg.norm(a, **kwarg)
|
@@ -2296,49 +2298,40 @@ def test_matrix_norm(self, ord, keepdims):
|
2296 | 2298 | expected = numpy.linalg.matrix_norm(a, ord=ord, keepdims=keepdims)
|
2297 | 2299 | assert_dtype_allclose(result, expected)
|
2298 | 2300 |
|
2299 |
| - @pytest.mark.parametrize( |
2300 |
| - "xp", |
2301 |
| - [ |
2302 |
| - dpnp, |
2303 |
| - pytest.param( |
2304 |
| - numpy, |
2305 |
| - marks=pytest.mark.skipif( |
2306 |
| - numpy_version() < "2.3.0", |
2307 |
| - reason="numpy raises an error", |
2308 |
| - ), |
2309 |
| - ), |
2310 |
| - ], |
2311 |
| - ) |
| 2301 | + @testing.with_requires("numpy>=2.3") |
2312 | 2302 | @pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32])
|
2313 | 2303 | @pytest.mark.parametrize(
|
2314 | 2304 | "shape, axis", [[(2, 0), None], [(2, 0), (0, 1)], [(0, 2), (0, 1)]]
|
2315 | 2305 | )
|
2316 | 2306 | @pytest.mark.parametrize("ord", [None, "fro", "nuc", 1, 2, dpnp.inf])
|
2317 |
| - def test_matrix_norm_empty(self, xp, dtype, shape, axis, ord): |
2318 |
| - x = xp.zeros(shape, dtype=dtype) |
2319 |
| - sc = dtype(0.0) if dtype == dpnp.float32 else 0.0 |
2320 |
| - assert_equal(xp.linalg.norm(x, axis=axis, ord=ord), sc) |
| 2307 | + @pytest.mark.parametrize("keepdims", [True, False]) |
| 2308 | + def test_matrix_norm_empty(self, dtype, shape, axis, ord, keepdims): |
| 2309 | + a = numpy.zeros(shape, dtype=dtype) |
| 2310 | + ia = dpnp.array(a) |
| 2311 | + result = dpnp.linalg.norm(ia, axis=axis, ord=ord, keepdims=keepdims) |
| 2312 | + expected = numpy.linalg.norm(a, axis=axis, ord=ord, keepdims=keepdims) |
| 2313 | + assert_dtype_allclose(result, expected) |
2321 | 2314 |
|
2322 |
| - @pytest.mark.parametrize( |
2323 |
| - "xp", |
2324 |
| - [ |
2325 |
| - dpnp, |
2326 |
| - pytest.param( |
2327 |
| - numpy, |
2328 |
| - marks=pytest.mark.skipif( |
2329 |
| - numpy_version() < "2.3.0", |
2330 |
| - reason="numpy raises an error", |
2331 |
| - ), |
2332 |
| - ), |
2333 |
| - ], |
2334 |
| - ) |
| 2315 | + @testing.with_requires("numpy>=2.3") |
2335 | 2316 | @pytest.mark.parametrize("dtype", [dpnp.float32, dpnp.int32])
|
2336 | 2317 | @pytest.mark.parametrize("axis", [None, 0])
|
2337 | 2318 | @pytest.mark.parametrize("ord", [None, 1, 2, dpnp.inf])
|
2338 |
| - def test_vector_norm_empty(self, xp, dtype, axis, ord): |
2339 |
| - x = xp.zeros(0, dtype=dtype) |
2340 |
| - sc = dtype(0.0) if dtype == dpnp.float32 else 0.0 |
2341 |
| - assert_equal(xp.linalg.vector_norm(x, axis=axis, ord=ord), sc) |
| 2319 | + @pytest.mark.parametrize("keepdims", [True, False]) |
| 2320 | + def test_vector_norm_empty(self, dtype, axis, ord, keepdims): |
| 2321 | + a = numpy.zeros(0, dtype=dtype) |
| 2322 | + ia = dpnp.array(a) |
| 2323 | + result = dpnp.linalg.vector_norm( |
| 2324 | + ia, axis=axis, ord=ord, keepdims=keepdims |
| 2325 | + ) |
| 2326 | + expected = numpy.linalg.vector_norm( |
| 2327 | + a, axis=axis, ord=ord, keepdims=keepdims |
| 2328 | + ) |
| 2329 | + assert_dtype_allclose(result, expected) |
| 2330 | + if keepdims: |
| 2331 | + # norm and vector_norm have different paths in dpnp when keepdims=True, |
| 2332 | + # to cover both of them test with norm as well |
| 2333 | + result = dpnp.linalg.norm(ia, axis=axis, ord=ord, keepdims=keepdims) |
| 2334 | + assert_dtype_allclose(result, expected) |
2342 | 2335 |
|
2343 | 2336 | @testing.with_requires("numpy>=2.0")
|
2344 | 2337 | @pytest.mark.parametrize(
|
|
0 commit comments