@@ -6,37 +6,40 @@ using NNlib: conv, ∇conv_filter, ∇conv_data, ∇maxpool, maxpool, depthwisec
6
6
w = reshape (Float32[1 : 9 ;], 3 , 3 , 1 , 1 )
7
7
8
8
@test dropdims (conv (x, w, pad= 1 ), dims= (3 ,4 )) ≈ Float32 .([
9
- 29.0 99.0 207.0 263.0
10
- 62.0 192.0 372.0 446.0
11
- 83.0 237.0 417.0 485.0
12
- 75.0 198.0 330.0 365.0 ])
9
+ 29 99 207 263
10
+ 62 192 372 446
11
+ 83 237 417 485
12
+ 75 198 330 365 ])
13
13
14
14
x = reshape (Float64[1 : 20 ;], 5 , 4 , 1 , 1 )
15
15
w = reshape (Float64[1 : 4 ;], 2 , 2 , 1 , 1 )
16
16
17
- @test dropdims (conv (x, w), dims = (3 ,4 )) == [
18
- 29 79 129 ;
19
- 39 89 139 ;
20
- 49 99 149 ;
21
- 59 109 159. ]
17
+ @test dropdims (conv (x, w), dims = (3 ,4 )) ≈ Float32 .([
18
+ 29 79 129 ;
19
+ 39 89 139 ;
20
+ 49 99 149 ;
21
+ 59 109 159
22
+ ])
22
23
23
- @test dropdims (conv (x, w; stride= 2 ), dims = (3 ,4 )) == [
24
+ @test dropdims (conv (x, w; stride= 2 ), dims = (3 ,4 )) ≈ Float32 .( [
24
25
29 129 ;
25
- 49 149. ]
26
+ 49 149
27
+ ])
26
28
27
- @test dropdims (conv (x, w; pad= 1 ), dims = (3 ,4 )) == [
28
- 1.0 9.0 29.0 49.0 48.0 ;
29
- 4.0 29.0 79.0 129.0 115.0 ;
30
- 7.0 39.0 89.0 139.0 122.0 ;
31
- 10.0 49.0 99.0 149.0 129.0 ;
32
- 13.0 59.0 109.0 159.0 136.0 ;
33
- 10.0 40.0 70.0 100.0 80.0
34
- ]
29
+ @test dropdims (conv (x, w; pad= 1 ), dims = (3 ,4 )) ≈ Float32 .( [
30
+ 1 9 29 49 48 ;
31
+ 4 29 79 129 115 ;
32
+ 7 39 89 139 122 ;
33
+ 10 49 99 149 129 ;
34
+ 13 59 109 159 136 ;
35
+ 10 40 70 100 80
36
+ ])
35
37
36
- @test dropdims (conv (x, w; dilation= 2 ), dims = (3 ,4 )) == [
37
- 48 98 ;
38
+ @test dropdims (conv (x, w; dilation= 2 ), dims = (3 ,4 )) ≈ Float32 .( [
39
+ 48 98 ;
38
40
58 108 ;
39
- 68 118. ]
41
+ 68 118
42
+ ])
40
43
41
44
# NaN tests for dilation forward pass
42
45
99
102
W = copy (permutedims (w[:,:,:,i: i],[1 ,2 ,4 ,3 ]));
100
103
DY = copy (dy[:,:,2 i- 1 : 2 i,:]);
101
104
res = ∇conv_data (DY,X,W)
102
- @test dropdims (z[:,:,i: i,:], dims= (3 ,4 )) == dropdims (res, dims= (3 ,4 ))
105
+ @test dropdims (z[:,:,i: i,:], dims= (3 ,4 )) ≈ Float32 .( dropdims (res, dims= (3 ,4 ) ))
103
106
end
104
107
105
108
z = ∇depthwiseconv_filter (dy, x, w)
108
111
W = copy (permutedims (w[:,:,:,i: i],[1 ,2 ,4 ,3 ]))
109
112
DY = copy (dy[:,:,2 i- 1 : 2 i,:])
110
113
res = ∇conv_filter (DY,X,W)
111
- @test dropdims (z[:,:,:,i: i]; dims= (4 )) == dropdims (res; dims= (3 ))
114
+ @test dropdims (z[:,:,:,i: i]; dims= (4 )) ≈ Float32 .( dropdims (res; dims= (3 ) ))
112
115
end
113
116
114
117
@test size (∇depthwiseconv_filter (rand (2 ,2 ,4 ,1 ), x, w)) == size (w)
@@ -125,17 +128,20 @@ end
125
128
126
129
x = reshape (Float32[1 : 16 ;], 4 , 4 , 1 , 1 )
127
130
128
- @test dropdims (maxpool (x, (2 ,2 )), dims = (3 ,4 )) == Float32 .([6.0 14.0 ; 8.0 16.0 ])
131
+ @test dropdims (maxpool (x, (2 ,2 )), dims = (3 ,4 )) ≈ Float32 .([
132
+ 6.0 14.0 ;
133
+ 8.0 16.0
134
+ ])
129
135
130
136
x = reshape (Float64[1 : 20 ;], 5 , 4 , 1 , 1 )
131
137
132
- @test dropdims (maxpool (x, (2 ,2 )), dims = (3 ,4 )) == [7 17 ; 9 19 ]
133
- @test dropdims (maxpool (x, (2 ,2 ); stride= (2 ,2 )), dims = (3 ,4 )) == [7 17 ; 9 19 ]
134
- @test dropdims (maxpool (x, (2 ,2 ); pad= (1 ,1 )), dims = (3 ,4 )) == [
135
- 1.0 11.0 16.0 ;
136
- 3.0 13.0 18.0 ;
137
- 5.0 15.0 20.0 ;
138
- ]
138
+ @test dropdims (maxpool (x, (2 ,2 )), dims = (3 ,4 )) ≈ Float32 .( [7 17 ; 9 19 ])
139
+ @test dropdims (maxpool (x, (2 ,2 ); stride= (2 ,2 )), dims = (3 ,4 )) ≈ Float32 .( [7 17 ; 9 19 ])
140
+ @test dropdims (maxpool (x, (2 ,2 ); pad= (1 ,1 )), dims = (3 ,4 )) ≈ Float32 .( [
141
+ 1 11 16 ;
142
+ 3 13 18 ;
143
+ 5 15 20 ;
144
+ ])
139
145
140
146
# for gradients, check only size
141
147
# correctness of gradients is cross-checked with CUDNN.jl
0 commit comments