55from pytensor .tensor .pad import PadMode , pad
66
77
8+ floatX = pytensor .config .floatX
9+
10+
811@pytest .mark .parametrize (
912 "size" , [(3 ,), (3 , 3 ), (3 , 3 , 3 )], ids = ["1d" , "2d square" , "3d square" ]
1013)
1316def test_constant_pad (
1417 size : tuple , constant : int | float , pad_width : int | tuple [int , ...]
1518):
16- x = np .random .normal (size = size )
19+ x = np .random .normal (size = size ). astype ( floatX )
1720 expected = np .pad (x , pad_width , mode = "constant" , constant_values = constant )
1821 z = pad (x , pad_width , mode = "constant" , constant_values = constant )
1922 f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -28,7 +31,7 @@ def test_constant_pad(
2831 "pad_width" , [1 , (1 , 2 )], ids = ["symmetrical" , "asymmetrical_1d" ]
2932)
3033def test_edge_pad (size : tuple , pad_width : int | tuple [int , ...]):
31- x = np .random .normal (size = size )
34+ x = np .random .normal (size = size ). astype ( floatX )
3235 expected = np .pad (x , pad_width , mode = "edge" )
3336 z = pad (x , pad_width , mode = "edge" )
3437 f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -48,7 +51,7 @@ def test_linear_ramp_pad(
4851 pad_width : int | tuple [int , ...],
4952 end_values : int | float | tuple [int | float , ...],
5053):
51- x = np .random .normal (size = size )
54+ x = np .random .normal (size = size ). astype ( floatX )
5255 expected = np .pad (x , pad_width , mode = "linear_ramp" , end_values = end_values )
5356 z = pad (x , pad_width , mode = "linear_ramp" , end_values = end_values )
5457 f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -70,9 +73,24 @@ def test_stat_pad(
7073 stat : PadMode ,
7174 stat_length : int | None ,
7275):
73- x = np .random .normal (size = size )
76+ x = np .random .normal (size = size ). astype ( floatX )
7477 expected = np .pad (x , pad_width , mode = stat , stat_length = stat_length )
7578 z = pad (x , pad_width , mode = stat , stat_length = stat_length )
7679 f = pytensor .function ([], z , mode = "FAST_COMPILE" )
7780
7881 np .testing .assert_allclose (expected , f ())
82+
83+
84+ @pytest .mark .parametrize (
85+ "size" , [(3 ,), (3 , 3 ), (3 , 5 , 5 )], ids = ["1d" , "2d square" , "3d square" ]
86+ )
87+ @pytest .mark .parametrize (
88+ "pad_width" , [1 , (1 , 2 )], ids = ["symmetrical" , "asymmetrical_1d" ]
89+ )
90+ def test_wrap_pad (size : tuple , pad_width : int | tuple [int , ...]):
91+ x = np .random .normal (size = size ).astype (floatX )
92+ expected = np .pad (x , pad_width , mode = "wrap" )
93+ z = pad (x , pad_width , mode = "wrap" )
94+ f = pytensor .function ([], z , mode = "FAST_COMPILE" )
95+
96+ np .testing .assert_allclose (expected , f ())
0 commit comments