2424 get_unsigned_dtypes ,
2525 has_support_aspect64 ,
2626)
27- from .third_party .cupy import testing
2827from .tensor .helper import get_queue_or_skip
28+ from .third_party .cupy import testing
2929
3030
3131def _compare_results (result , expected ):
@@ -307,7 +307,7 @@ def test_no_copy(self):
307307 assert_array_equal (b , a )
308308
309309
310- class TestBroadcast :
310+ class TestBroadcastShapes :
311311 @pytest .mark .parametrize (
312312 "shape" ,
313313 [
@@ -2095,12 +2095,14 @@ def test_broadcast_three_arrays(self):
20952095 assert bc .numiter == 3
20962096
20972097 def test_broadcast_ndim_property (self ):
2098- # Test that ndim property equals nd property
2098+ # Test that ndim property matches numpy and equals nd property
20992099 a = dpnp .array ([[1 , 2 ], [3 , 4 ]])
21002100 b = dpnp .array ([5 , 6 ])
21012101
21022102 bc = dpnp .broadcast (a , b )
2103+ bc_np = numpy .broadcast (a .asnumpy (), b .asnumpy ())
21032104
2105+ assert bc .ndim == bc_np .ndim
21042106 assert bc .ndim == bc .nd
21052107
21062108 def test_broadcast_complex_shapes (self ):
@@ -2116,13 +2118,19 @@ def test_broadcast_complex_shapes(self):
21162118 assert bc .nd == bc_np .nd
21172119 assert bc .size == bc_np .size
21182120
2119- def test_broadcast_with_array_like (self ):
2120- # Conversion from array-like inputs is not implemented for broadcast yet.
2121+ @pytest .mark .parametrize (
2122+ "arg" ,
2123+ [[[1 ], [2 ]], 3 , numpy .ones ((2 , 1 ))],
2124+ ids = ["list" , "scalar" , "numpy" ],
2125+ )
2126+ def test_broadcast_unsupported_type (self , arg ):
2127+ # unlike numpy, input arrays are not coerced, so array-like objects,
2128+ # scalars and host arrays are rejected the same way as they are by
2129+ # dpnp.broadcast_to and dpnp.broadcast_arrays
21212130 a = dpnp .array ([1 , 2 , 3 ])
2122- b = [[1 ], [2 ]]
21232131
21242132 with pytest .raises (TypeError ):
2125- dpnp .broadcast (a , b )
2133+ dpnp .broadcast (a , arg )
21262134
21272135 @pytest .mark .parametrize (
21282136 "shapes" ,
@@ -2171,21 +2179,20 @@ def test_broadcast_no_args(self):
21712179 assert bc .size == 1
21722180 assert bc .numiter == 0
21732181
2174- def test_broadcast_argument_without_shape (self ):
2175- a = dpnp .array ([1 , 2 , 3 ])
2176-
2177- with pytest .raises (TypeError ):
2178- dpnp .broadcast (a , 3 )
2179-
2180- def test_broadcast_compute_follows_data (self ):
2182+ def test_broadcast_different_queues (self ):
2183+ # Broadcasting is a shape-only query, so inputs are not required
2184+ # to share a common execution placement
21812185 q1 = get_queue_or_skip ()
21822186 q2 = get_queue_or_skip ()
21832187
21842188 a = dpt .ones ((2 , 1 ), sycl_queue = q1 )
21852189 b = dpt .ones ((1 , 2 ), sycl_queue = q2 )
21862190
2187- with pytest .raises (dpt .ExecutionPlacementError ):
2188- dpnp .broadcast (a , b )
2191+ bc = dpnp .broadcast (a , b )
2192+
2193+ assert bc .shape == (2 , 2 )
2194+ assert bc .size == 4
2195+ assert bc .nd == 2
21892196
21902197 def test_broadcast_repr (self ):
21912198 # Test __repr__ method
0 commit comments