@@ -16,35 +16,35 @@ and a potential inverse of `unfold`.
1616The below example demonstrates that `unfold` uses the same sliding windows as `conv`.
1717In general [`batched_mul`](@ref) + `unfold` should not be used to achieve convolution.
1818```jldoctest
19- julia> x = reshape([100 2 3 40 5 6 700], 7, 1, 1); # 1D data, 1 channel, batch of 1
19+ julia> x = reshape(Float32 [100 2 3 40 5 6 700], 7, 1, 1); # 1D data, 1 channel, batch of 1
2020
21- julia> w = reshape([1 0 -1], 3, 1, 1); # 1D conv kernel of length 3
21+ julia> w = reshape(Float32 [1 0 -1], 3, 1, 1); # 1D conv kernel of length 3
2222
2323julia> kws = (pad=1, stride=2, flipped=true); # use same args for conv and unfold
2424
2525julia> z = NNlib.unfold(x, size(w); kws...)
26- 4×3×1 Array{Int64 , 3}:
26+ 4×3×1 Array{Float32 , 3}:
2727[:, :, 1] =
28- 0 100 2
29- 2 3 40
30- 40 5 6
31- 6 700 0
28+ 0.0 100.0 2.0
29+ 2.0 3.0 40.0
30+ 40.0 5.0 6.0
31+ 6.0 700.0 0. 0
3232
3333julia> y1 = conv(x, w; kws...)
34- 4×1×1 Array{Int64 , 3}:
34+ 4×1×1 Array{Float32 , 3}:
3535[:, :, 1] =
36- -2
37- -38
38- 34
39- 6
36+ -2.0
37+ -38.0
38+ 34.0
39+ 6.0
4040
4141julia> y2 = z ⊠ w # ⊠ (\\ boxtimes) is NNlib.batched_mul
42- 4×1×1 Array{Int64 , 3}:
42+ 4×1×1 Array{Float32 , 3}:
4343[:, :, 1] =
44- -2
45- -38
46- 34
47- 6
44+ -2.0
45+ -38.0
46+ 34.0
47+ 6.0
4848```
4949"""
5050function unfold(x:: AbstractArray{T, N} , kernel_size:: NTuple{K} ; stride = 1 , pad = 0 , dilation = 1 , flipped = true ) where {T, K, N}
0 commit comments