1
- const AA{N} = AbstractArray{Float32,N}
2
- const AA1 = Union{AA{2 }, AA{3 }, AA{4 }, AA{5 }}
3
-
4
1
# NOTE: Commenting out the activation functions until sure what to do
5
2
6
3
# relu(x::AA1) = nnp_relu_output(x, inplace ? x : similar(x), threadpool = shared_threadpool)
@@ -26,7 +23,7 @@ softmax(x::A) where A<:AbstractVecOrMat{Float32} =
26
23
maxpool (x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float64, 4} =
27
24
maxpool (Float32 .(x), k, pad = pad, stride = stride)
28
25
29
- function maxpool (x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AA{ 4}
26
+ function maxpool (x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float32, 4}
30
27
pad_, stride_ = expand (Val{length (k)}, pad), expand (Val{length (k)}, stride)
31
28
((size (x, 1 ) - k[1 ] + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - k[2 ] + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
32
29
maxpool! (similar (x, pdims (size (x), k, pad_, stride_)), x, k, pad = pad_, stride = stride_)
35
32
maxpool! (y:: A , x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float64, 4} =
36
33
maxpool! (Float32 .(y), Float32 .(x), k, pad = pad, stride = stride)
37
34
38
- maxpool! (y:: A , x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AA{ 4} =
35
+ maxpool! (y:: A , x:: A , k; pad = map (_-> 0 ,k), stride = k) where A<: AbstractArray{Float32, 4} =
39
36
nnp_max_pooling_output (x, y, k, padding = expand (Val{length (k)}, pad), stride = expand (Val{length (k)}, stride), threadpool = shared_threadpool)
40
37
41
38
conv (x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float64, 4} =
42
39
conv (Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
43
40
44
- function conv (x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AA{ 4}
41
+ function conv (x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
45
42
dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
46
43
pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
47
44
((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
53
50
conv (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
54
51
conv (Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo)
55
52
56
- function conv (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AA{ 4} , A2<: AA{ 1} }
53
+ function conv (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
57
54
dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
58
55
pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
59
56
((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
63
60
crosscor (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
64
61
crosscor (Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo)
65
62
66
- function crosscor (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AA{ 4} , A2<: AA{ 1} }
63
+ function crosscor (x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
67
64
dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
68
65
pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
69
66
((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
73
70
conv! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
74
71
conv (Float32 .(y), Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo, flipkernel = flipkernel)
75
72
76
- function conv! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where {A1<: AA{ 4} , A2<: AA{ 1} }
73
+ function conv! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} }
77
74
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
78
75
nnp_convolution_output (y, x, w, b, algo = algo, padding = pad, stride = stride, threadpool = shared_threadpool)
79
76
end
80
77
81
78
crosscor! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float64, 4} , A2<: AbstractArray{Float64, 1} } =
82
79
conv! (Float32 .(y), Float32 .(x), Float32 .(w), Float32 .(b), pad = pad, stride = stride, dilation = dilation, algo = algo, flipkernel = 1 )
83
80
84
- crosscor! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AA{ 4} , A2<: AA{ 1} } =
81
+ crosscor! (y:: A1 , x:: A1 , w:: A1 , b:: A2 ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where {A1<: AbstractArray{Float32, 4} , A2<: AbstractArray{Float32, 1} } =
85
82
conv! (y, x, w, b, pad = pad, stride = stride, dilation = dilation, algo = algo, flipkernel = 1 )
86
83
87
84
∇conv_data (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float64, 4} =
88
85
∇conv_data (Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
89
86
90
- function ∇conv_data (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AA{ 4}
87
+ function ∇conv_data (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
91
88
dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
92
89
pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
93
90
((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
97
94
∇conv_data! (dx:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float64, 4} =
98
95
∇conv_data! (Float32 .(dx), Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo, flipkernel = flipkernel)
99
96
100
- function ∇conv_data! (dx:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AA{ 4}
97
+ function ∇conv_data! (dx:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float32, 4}
101
98
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
102
99
nnp_convolution_input_gradient (dx, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool)
103
100
end
104
101
105
102
∇conv_filter (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float64, 4} =
106
103
∇conv_filter (Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo)
107
104
108
- function ∇conv_filter (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AA{ 4}
105
+ function ∇conv_filter (dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 )) where A<: AbstractArray{Float32, 4}
109
106
dilation == 1 || dilation == (1 , 1 ) || error (" NNPACK does not support dilation > 1" )
110
107
pad_, stride_ = padtuple (x, pad), padtuple (x, stride)
111
108
((size (x, 1 ) - size (w, 1 ) + 2 * pad_[1 ]) % stride_[1 ] == 0 && (size (x, 2 ) - size (w, 2 ) + 2 * pad_[2 ]) % stride_[2 ] == 0 ) || error (" Choose the stride, pad and kernel size properly" )
115
112
∇conv_filter! (dw:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float64, 4} =
116
113
∇conv_filter! (Float32 .(dw), Float32 .(dy), Float32 .(x), Float32 .(w), pad = pad, stride = stride, dilation = dilation, algo = algo, flipkernel = flipkernel)
117
114
118
- function ∇conv_filter! (dw:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AA{ 4}
115
+ function ∇conv_filter! (dw:: A , dy:: A , x:: A , w:: A ; pad = 0 , stride = 1 , dilation = 1 , algo = UInt32 (0 ), flipkernel = 0 ) where A<: AbstractArray{Float32, 4}
119
116
flipkernel == 0 && (w = reverse (reverse (w, dims= 1 ), dims= 2 ))
120
117
dw .= nnp_convolution_kernel_gradient (dw, x, dy, w, padding = pad, stride = stride, algo = algo, threadpool = shared_threadpool)
121
118
flipkernel == 0 ? reverse (reverse (dw, dims= 1 ), dims= 2 ) : dw
0 commit comments