@@ -409,3 +409,65 @@ def fancy_strided_output(inputs, output_indices, stride=1):
409409 output_indices = [800 , 74 , 671 , 132 , 818 ]
410410 out = fancy_strided_output (arr , output_indices , stride = 16 )
411411 assert out .shape == (2 , 12 , 5 , 10 , 8 , 3 )
412+
413+
414+ dtypes = [np .int32 , np .float32 , np .float64 , np .uint8 ]
415+
416+ # Shapes for broadcast_to
417+ broadcast_shapes = [
418+ ((10 ,), (50 ,), (4 ,), (3 ,)),
419+ ((8 , 6 ), (16 , 12 ), (4 , 3 ), (1 , 3 )),
420+ ((2 , 6 ), (2 , 30 ), (3 , 2 ), (1 , 1 )),
421+ ((1 , 1 , 3 ), (2 , 4 , 3 ), (1 , 1 , 2 ), (1 , 1 , 1 )),
422+ ]
423+
424+ meshgrid_shapes = [
425+ ((10 , 20 ), (3 ,), (1 ,)),
426+ ((8 , 6 ), (4 ,), (3 ,)),
427+ ((2 , 30 ), (2 ,), (1 ,)),
428+ ((20 , 4 , 3 ), (4 ,), (1 ,)),
429+ ]
430+
431+
432+ @pytest .mark .parametrize ("dtype" , dtypes )
433+ @pytest .mark .parametrize (("src_shape" , "dst_shape" , "chunks" , "blocks" ), broadcast_shapes )
434+ def test_broadcast_to (dtype , src_shape , dst_shape , chunks , blocks ):
435+ arr_np = np .arange (np .prod (src_shape ), dtype = dtype ).reshape (src_shape )
436+ arr_b2 = blosc2 .asarray (arr_np , chunks = chunks , blocks = blocks )
437+
438+ try :
439+ np_broadcast = np .broadcast_to (arr_np , dst_shape )
440+ np_error = None
441+ except ValueError as e :
442+ np_broadcast = None
443+ np_error = e
444+
445+ if np_error is not None :
446+ with pytest .raises (type (np_error )):
447+ blosc2 .broadcast_to (arr_b2 , dst_shape )
448+ else :
449+ b2_broadcast = blosc2 .broadcast_to (arr_b2 , dst_shape )
450+ assert np .array_equal (b2_broadcast [:], np_broadcast )
451+
452+
453+ @pytest .mark .parametrize ("dtype" , dtypes )
454+ @pytest .mark .parametrize (("shapes" , "chunks" , "blocks" ), meshgrid_shapes )
455+ @pytest .mark .parametrize ("indexing" , ["xy" , "ij" ])
456+ def test_meshgrid (dtype , shapes , chunks , blocks , indexing ):
457+ arrays_np = [np .arange (np .prod (shape ), dtype = dtype ).reshape (shape ) for shape in shapes ]
458+ arrays_b2 = [blosc2 .asarray (a , chunks = chunks , blocks = blocks ) for a in arrays_np ]
459+ try :
460+ np_grids = np .meshgrid (* arrays_np , indexing = indexing )
461+ np_error = None
462+ except ValueError as e :
463+ np_grids = None
464+ np_error = e
465+
466+ if np_error is not None :
467+ with pytest .raises (type (np_error )):
468+ blosc2 .meshgrid (* arrays_b2 , indexing = indexing )
469+ else :
470+ b2_grids = blosc2 .meshgrid (* arrays_b2 , indexing = indexing )
471+ assert len (b2_grids ) == len (np_grids )
472+ for g_b2 , g_np in zip (b2_grids , np_grids , strict = False ):
473+ assert np .array_equal (g_b2 [:], g_np )
0 commit comments