Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less alloc in TriggsSdika filtering (fix #243) #244

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[firstindex(ind):firstindex(ind)+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