Skip to content

Commit

Permalink
Less alloc in TriggsSdika filtering (fix #243)
Browse files Browse the repository at this point in the history
Putting the string interpolation behind a `@noinline` is the key change,
but it doesn't hurt to hoise the range creation.

Of the few remaining allocations, about half will be fixed by
JuliaLang/julia#43990, as they are another
instance of JuliaLang/julia#35972
  • Loading branch information
timholy committed Feb 8, 2022
1 parent 424523c commit 8b4a2f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/imfilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1312,19 +1312,25 @@ _imfilter_inplace_tuple!(r, out, img, ::Tuple{}, Rbegin, inds, Rend, border) = o
out, img, kernel::TriggsSdika{T,k,l},
Rbegin::CartesianIndices, ind::AbstractUnitRange,
Rend::CartesianIndices, border::AbstractBorder) where {T,k,l}

@noinline function throw_imfilter_dim(R, n, l)
dim = ndims(R)+1
throw(DimensionMismatch("size $n of img along dimension $dim is too small for filtering with IIR kernel of length $l"))
end

if iscopy(kernel)
if !(out === img)
copyto!(out, img)
end
return out
end
if length(ind) <= max(k, l)
dim = ndims(Rbegin)+1
throw(DimensionMismatch("size of img along dimension $dim $(length(ind)) is too small for filtering with IIR kernel of length $(max(k,l))"))
throw_imfilter_dim(Rbegin, length(ind), max(k, l))
end
indleft = ind[begin:begin+k-1]
indright = ind[end-l+1:end]
for Iend in Rend
# Initialize the left border
indleft = collect(Iterators.take(ind,k))
for Ibegin in Rbegin
leftborder!(out, img, kernel, Ibegin, indleft, Iend, border)
end
Expand All @@ -1341,7 +1347,6 @@ _imfilter_inplace_tuple!(r, out, img, ::Tuple{}, Rbegin, inds, Rend, border) = o
end
end
# Initialize the right border
indright = ind[end-l+1:end]
for Ibegin in Rbegin
rightborder!(out, img, kernel, Ibegin, indright, Iend, border)
end
Expand Down

0 comments on commit 8b4a2f2

Please sign in to comment.