@@ -49,7 +49,7 @@ pub fn test_pooling_max<T, F: IFramework>(backend: Backend<F>)
49
49
50
50
let x = filled_tensor ( & backend, & [ 4 , 4 , 4 , 4 ] , & inp) ;
51
51
let mut r = SharedTensor :: < T > :: new ( & [ 4 , 4 , 2 , 4 ] ) ;
52
- let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 0 , 0 ] , & [ 2 , 1 ] )
52
+ let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 2 , 1 ] , & [ 0 , 0 ] )
53
53
. unwrap ( ) ;
54
54
55
55
backend. pooling_max ( & x, & mut r, & conf) . unwrap ( ) ;
@@ -69,7 +69,7 @@ pub fn test_pooling_max_grad<T, F: IFramework>(backend: Backend<F>)
69
69
let dx = filled_tensor ( & backend, & [ 4 , 4 , 4 , 4 ] , & inp) ;
70
70
let r = filled_tensor ( & backend, & [ 4 , 4 , 2 , 2 ] , & inp[ 0 ..64 ] ) ;
71
71
let mut dr = SharedTensor :: < T > :: new ( & [ 4 , 4 , 2 , 2 ] ) ;
72
- let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 0 , 0 ] , & [ 2 , 2 ] )
72
+ let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 2 , 2 ] , & [ 0 , 0 ] )
73
73
. unwrap ( ) ;
74
74
75
75
backend. pooling_max_grad ( & x, & dx, & r, & mut dr, & conf) . unwrap ( ) ;
@@ -90,7 +90,7 @@ pub fn test_pooling_avg<T, F: IFramework>(backend: Backend<F>)
90
90
91
91
let x = filled_tensor ( & backend, & [ 4 , 4 , 4 , 4 ] , & inp) ;
92
92
let mut r = SharedTensor :: < T > :: new ( & [ 4 , 4 , 2 , 2 ] ) ;
93
- let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 0 , 0 ] , & [ 2 , 2 ] )
93
+ let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 2 , 2 ] , & [ 0 , 0 ] )
94
94
. unwrap ( ) ;
95
95
96
96
backend. pooling_avg ( & x, & mut r, & conf) . unwrap ( ) ;
@@ -111,7 +111,7 @@ pub fn test_pooling_avg_grad<T, F: IFramework>(backend: Backend<F>)
111
111
let dx = filled_tensor ( & backend, & [ 8 , 4 , 4 , 4 ] , & inp) ;
112
112
let r = filled_tensor ( & backend, & [ 8 , 4 , 2 , 2 ] , & inp[ 0 ..128 ] ) ;
113
113
let mut dr = SharedTensor :: < T > :: new ( & [ 8 , 4 , 2 , 2 ] ) ;
114
- let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 0 , 0 ] , & [ 2 , 2 ] )
114
+ let conf = Pooling :: < T > :: new_pooling_config ( & backend, & [ 2 , 2 ] , & [ 2 , 2 ] , & [ 0 , 0 ] )
115
115
. unwrap ( ) ;
116
116
117
117
backend. pooling_avg_grad ( & x, & dx, & r, & mut dr, & conf) . unwrap ( ) ;
@@ -124,6 +124,36 @@ pub fn test_pooling_avg_grad<T, F: IFramework>(backend: Backend<F>)
124
124
tensor_assert_eq ( & dr, & dr_test, 1.0 ) ;
125
125
}
126
126
127
+ pub fn cross_test_pooling_max < F : IFramework , G : IFramework > ( backend_a : Backend < F > , backend_b : Backend < G > )
128
+ where
129
+ Backend < F > : Pooling < f32 > + IBackend ,
130
+ Backend < G > : Pooling < f32 > + IBackend {
131
+
132
+ let mut inp = vec ! [ 1.0 ; 256 ] ;
133
+ inp[ 0 ] = 2.0 ;
134
+
135
+ let lower : f32 = -128. ;
136
+ let upper : f32 = 127. ;
137
+ let x = uniformly_random_tensor ( & backend_a, & [ 4 , 4 , 4 , 4 ] , lower, upper) ;
138
+
139
+ let mut r_a = SharedTensor :: < f32 > :: new ( & [ 4 , 4 , 2 , 4 ] ) ;
140
+ let mut r_b = SharedTensor :: < f32 > :: new ( & [ 4 , 4 , 2 , 4 ] ) ;
141
+
142
+ let conf_a = Pooling :: < f32 > :: new_pooling_config ( & backend_a, & [ 2 , 2 ] , & [ 2 , 1 ] , & [ 0 , 0 ] )
143
+ . unwrap ( ) ;
144
+ let conf_b = Pooling :: < f32 > :: new_pooling_config ( & backend_b, & [ 2 , 2 ] , & [ 2 , 1 ] , & [ 0 , 0 ] )
145
+ . unwrap ( ) ;
146
+
147
+ backend_a. pooling_max ( & x, & mut r_a, & conf_a) . unwrap ( ) ;
148
+ backend_b. pooling_max ( & x, & mut r_b, & conf_b) . unwrap ( ) ;
149
+ tensor_assert_eq_tensor ( & r_a, & r_b, 3.0 ) ;
150
+ }
151
+
152
+ mod cross {
153
+ use super :: * ;
154
+ test_cross ! ( cross_test_pooling_max, cross_test_pooling_max_f32) ;
155
+ }
156
+
127
157
mod cuda {
128
158
use super :: * ;
129
159
test_cuda ! ( test_pooling_avg, pooling_avg_f32, pooling_avg_f64) ;
0 commit comments