@@ -1516,10 +1516,46 @@ def test_ndim(self, xp: ArrayNamespace):
15161516 padded = pad (a , 2 )
15171517 assert padded .shape == (6 , 7 , 8 )
15181518
1519+ def test_edge (self , xp : ArrayNamespace ):
1520+ a = xp .asarray ([1 , 2 , 3 ])
1521+ padded = pad (a , (2 , 1 ), mode = "edge" )
1522+ assert_equal (padded , xp .asarray ([1 , 1 , 1 , 2 , 3 , 3 ]))
1523+
1524+ def test_edge_ndim (self , xp : ArrayNamespace ):
1525+ a = xp .asarray ([[1 , 2 ], [3 , 4 ]])
1526+ padded = pad (a , ((1 , 2 ), (2 , 1 )), mode = "edge" )
1527+ expected = xp .asarray (
1528+ [
1529+ [1 , 1 , 1 , 2 , 2 ],
1530+ [1 , 1 , 1 , 2 , 2 ],
1531+ [3 , 3 , 3 , 4 , 4 ],
1532+ [3 , 3 , 3 , 4 , 4 ],
1533+ [3 , 3 , 3 , 4 , 4 ],
1534+ ]
1535+ )
1536+ assert_equal (padded , expected )
1537+
1538+ def test_wrap (self , xp : ArrayNamespace ):
1539+ a = xp .asarray ([1 , 2 , 3 ])
1540+ padded = pad (a , (5 , 4 ), mode = "wrap" )
1541+ assert_equal (padded , xp .asarray ([2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 , 1 ]))
1542+
1543+ def test_wrap_ndim (self , xp : ArrayNamespace ):
1544+ a = xp .asarray ([[1 , 2 ], [3 , 4 ]])
1545+ padded = pad (a , ((1 , 1 ), (1 , 1 )), mode = "wrap" )
1546+ expected = xp .asarray ([[4 , 3 , 4 , 3 ], [2 , 1 , 2 , 1 ], [4 , 3 , 4 , 3 ], [2 , 1 , 2 , 1 ]])
1547+ assert_equal (padded , expected )
1548+
1549+ @pytest .mark .parametrize ("mode" , ["edge" , "wrap" ])
1550+ def test_empty_axis (self , xp : ArrayNamespace , mode : str ):
1551+ a = xp .asarray ([])
1552+ with pytest .raises (ValueError , match = "can't extend empty axis" ):
1553+ _ = pad (a , 1 , mode = mode ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
1554+
15191555 def test_mode_not_implemented (self , xp : ArrayNamespace ):
15201556 a = xp .asarray ([1 , 2 , 3 ])
1521- with pytest .raises (NotImplementedError , match = "Only `'constant'` " ):
1522- _ = pad (a , 2 , mode = "edge " ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
1557+ with pytest .raises (NotImplementedError , match = "Unsupported padding mode " ):
1558+ _ = pad (a , 2 , mode = "reflect " ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
15231559
15241560 def test_device (self , xp : ArrayNamespace , device : Device ):
15251561 a = xp .asarray (0.0 , device = device )
0 commit comments