Skip to content

Commit 3edc9d3

Browse files
authored
Reduce unnecessary allocations in filtfft (#231)
1 parent 6b51789 commit 3edc9d3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/imfilter.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,17 @@ function _imfilter_fft!(r::AbstractCPU{FFT},
12071207
out
12081208
end
12091209

1210-
filtfft(A, krn) = irfft(rfft(A).*conj(rfft(krn)), length(axes(A,1)))
1210+
function filtfft(A, krn)
1211+
B = rfft(A)
1212+
B .*= conj!(rfft(krn))
1213+
irfft(B, length(axes(A,1)))
1214+
end
12111215
function filtfft(A::AbstractArray{C}, krn) where C<:Colorant
12121216
Av, dims = channelview_dims(A)
12131217
kernrs = kreshape(C, krn)
1214-
Avf = irfft(rfft(Av, dims).*conj(rfft(kernrs, dims)), length(axes(Av, dims[1])), dims)
1218+
B = rfft(Av, dims)
1219+
B .*= conj!(rfft(kernrs, dims))
1220+
Avf = irfft(B, length(axes(Av, dims[1])), dims)
12151221
colorview(base_colorant_type(C){eltype(Avf)}, Avf)
12161222
end
12171223
channelview_dims(A::AbstractArray{C,N}) where {C<:Colorant,N} = channelview(A), ntuple(d->d+1, Val(N))

0 commit comments

Comments
 (0)