@@ -2075,9 +2075,6 @@ def test_matrix_transpose():
20752075
20762076
20772077class TestNorm :
2078- def setup_method (self ):
2079- numpy .random .seed (42 )
2080-
20812078 @pytest .mark .usefixtures ("suppress_divide_numpy_warnings" )
20822079 @pytest .mark .parametrize (
20832080 "shape" , [(0 ,), (5 , 0 ), (2 , 0 , 3 )], ids = ["(0,)" , "(5, 0)" , "(2, 0, 3)" ]
@@ -2099,15 +2096,16 @@ def test_empty(self, shape, ord, axis, keepdims):
20992096 # Improper number of dimensions to norm
21002097 assert_raises (ValueError , dpnp .linalg .norm , ia , ** kwarg )
21012098 assert_raises (ValueError , numpy .linalg .norm , a , ** kwarg )
2102- elif (
2103- axis is None
2104- and ord in [- 2 , - 1 , 0 , 3 ]
2105- and a .ndim != 1
2106- and a .shape [- 1 ] == 0
2107- ):
2108- # reduction cannot be performed over zero-size axes
2109- assert_raises (ValueError , dpnp .linalg .norm , ia , ** kwarg )
2110- assert_raises (ValueError , numpy .linalg .norm , a , ** kwarg )
2099+ elif axis is None and a .ndim != 1 and a .shape [- 1 ] == 0 :
2100+ # TODO: when similar changes in numpy are available,
2101+ # instead of assert_equal with zero, we should compare with numpy
2102+ if ord in [- 2 , - 1 , 0 , 3 ]:
2103+ # reduction cannot be performed over zero-size axes
2104+ assert_raises (ValueError , dpnp .linalg .norm , ia , ** kwarg )
2105+ assert_raises (ValueError , numpy .linalg .norm , a , ** kwarg )
2106+ else :
2107+ # ord in [None, 1, 2]
2108+ assert_equal (dpnp .linalg .norm (ia , ** kwarg ), 0 )
21112109 else :
21122110 result = dpnp .linalg .norm (ia , ** kwarg )
21132111 expected = numpy .linalg .norm (a , ** kwarg )
@@ -2303,6 +2301,8 @@ def test_matrix_norm_empty(self, dtype, shape_axis):
23032301 shape , axis = shape_axis [0 ], shape_axis [1 ]
23042302 x = dpnp .zeros (shape , dtype = dtype )
23052303
2304+ # TODO: when similar changes in numpy are available,
2305+ # instead of assert_equal with zero, we should compare with numpy
23062306 assert_equal (dpnp .linalg .norm (x , axis = axis , ord = "fro" ), 0 )
23072307 assert_equal (dpnp .linalg .norm (x , axis = axis , ord = "nuc" ), 0 )
23082308 assert_equal (dpnp .linalg .norm (x , axis = axis , ord = 2 ), 0 )
@@ -2313,6 +2313,8 @@ def test_matrix_norm_empty(self, dtype, shape_axis):
23132313 @pytest .mark .parametrize ("axis" , [None , 0 ])
23142314 def test_vector_norm_empty (self , dtype , axis ):
23152315 x = dpnp .zeros (0 , dtype = dtype )
2316+ # TODO: when similar changes in numpy are available,
2317+ # instead of assert_equal with zero, we should compare with numpy
23162318 assert_equal (dpnp .linalg .vector_norm (x , axis = axis , ord = 1 ), 0 )
23172319 assert_equal (dpnp .linalg .vector_norm (x , axis = axis , ord = 2 ), 0 )
23182320 assert_equal (dpnp .linalg .vector_norm (x , axis = axis , ord = dpnp .inf ), 0 )
0 commit comments