5
5
from pytensor .tensor .pad import PadMode , pad
6
6
7
7
8
+ floatX = pytensor .config .floatX
9
+
10
+
8
11
@pytest .mark .parametrize (
9
12
"size" , [(3 ,), (3 , 3 ), (3 , 3 , 3 )], ids = ["1d" , "2d square" , "3d square" ]
10
13
)
13
16
def test_constant_pad (
14
17
size : tuple , constant : int | float , pad_width : int | tuple [int , ...]
15
18
):
16
- x = np .random .normal (size = size )
19
+ x = np .random .normal (size = size ). astype ( floatX )
17
20
expected = np .pad (x , pad_width , mode = "constant" , constant_values = constant )
18
21
z = pad (x , pad_width , mode = "constant" , constant_values = constant )
19
22
f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -28,7 +31,7 @@ def test_constant_pad(
28
31
"pad_width" , [1 , (1 , 2 )], ids = ["symmetrical" , "asymmetrical_1d" ]
29
32
)
30
33
def 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 )
32
35
expected = np .pad (x , pad_width , mode = "edge" )
33
36
z = pad (x , pad_width , mode = "edge" )
34
37
f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -48,7 +51,7 @@ def test_linear_ramp_pad(
48
51
pad_width : int | tuple [int , ...],
49
52
end_values : int | float | tuple [int | float , ...],
50
53
):
51
- x = np .random .normal (size = size )
54
+ x = np .random .normal (size = size ). astype ( floatX )
52
55
expected = np .pad (x , pad_width , mode = "linear_ramp" , end_values = end_values )
53
56
z = pad (x , pad_width , mode = "linear_ramp" , end_values = end_values )
54
57
f = pytensor .function ([], z , mode = "FAST_COMPILE" )
@@ -70,9 +73,24 @@ def test_stat_pad(
70
73
stat : PadMode ,
71
74
stat_length : int | None ,
72
75
):
73
- x = np .random .normal (size = size )
76
+ x = np .random .normal (size = size ). astype ( floatX )
74
77
expected = np .pad (x , pad_width , mode = stat , stat_length = stat_length )
75
78
z = pad (x , pad_width , mode = stat , stat_length = stat_length )
76
79
f = pytensor .function ([], z , mode = "FAST_COMPILE" )
77
80
78
81
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