Skip to content

Commit a6fd7e8

Browse files
committed
Remove unfortunate OffsetArrays specializations
1 parent ee6cf8e commit a6fd7e8

File tree

3 files changed

+2
-75
lines changed

3 files changed

+2
-75
lines changed

src/ImageFiltering.jl

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export Kernel, KernelFactors,
1919

2020
FixedColorant{T<:Normed} = Colorant{T}
2121
StaticOffsetArray{T,N,A<:StaticArray} = OffsetArray{T,N,A}
22-
OffsetVector{T} = OffsetArray{T,1}
2322

2423
# Add a fix that should have been included in julia-1.0.3
2524
if isdefined(Broadcast, :_sametype) && !isdefined(Broadcast, :axistype)

src/border.jl

-5
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,6 @@ function copydata!(dest, img, inds)
681681
dest
682682
end
683683

684-
function copydata!(dest::OffsetArray, img, inds::Tuple{Vararg{OffsetArray}})
685-
copydata!(parent(dest), img, map(parent, inds))
686-
dest
687-
end
688-
689684
Base.ndims(b::AbstractBorder) = ndims(typeof(b))
690685
Base.ndims(::Type{Pad{N}}) where {N} = N
691686

src/imfilter.jl

+2-69
Original file line numberDiff line numberDiff line change
@@ -1006,30 +1006,6 @@ function __imfilter_inbounds!(r, out, A, kern, border, R, z)
10061006
out
10071007
end
10081008

1009-
# This is unfortunate, but specializing this saves an add in the inner
1010-
# loop and results in a modest performance improvement. It would be
1011-
# nice if LLVM did this automatically. (@polly?)
1012-
function __imfilter_inbounds!(r, out, A::OffsetArray, kern::OffsetArray, border, R, z)
1013-
off, k = CartesianIndex(kern.offsets), parent(kern)
1014-
o, O = safehead(off), safetail(off)
1015-
Rnew = CartesianIndices(map((x,y)->x.+y, R.indices, Tuple(off)))
1016-
Rk = CartesianIndices(axes(k))
1017-
offA, pA = CartesianIndex(A.offsets), parent(A)
1018-
oA, OA = safehead(offA), safetail(offA)
1019-
for I in safetail(Rnew)
1020-
IA = I-OA
1021-
for i in safehead(Rnew)
1022-
tmp = z
1023-
iA = i-oA
1024-
@inbounds for J in safetail(Rk), j in safehead(Rk)
1025-
tmp += safe_for_prod(pA[iA+j,IA+J], tmp)*k[j,J]
1026-
end
1027-
@inbounds out[i-o,I-O] = tmp
1028-
end
1029-
end
1030-
out
1031-
end
1032-
10331009
function _imfilter_inbounds!(r::AbstractResource, out, A::AbstractArray, kern::ReshapedOneD, border::NoPad, inds)
10341010
Rpre, ind, Rpost = iterdims(inds, kern)
10351011
k = kern.data
@@ -1042,64 +1018,21 @@ function _imfilter_inbounds!(r::AbstractResource, out, A::AbstractArray, kern::R
10421018
_imfilter_inbounds!(r, z, out, A, k, Rpre, ind, Rpost)
10431019
end
10441020

1045-
# Many of the following are unfortunate specializations
1046-
function _imfilter_inbounds!(r::AbstractResource, z, out, A::AbstractArray, k::OffsetVector, Rpre::CartesianIndices, ind, Rpost::CartesianIndices)
1047-
_imfilter_inbounds!(r, z, out, A, parent(k), Rpre, ind, Rpost, k.offsets[1])
1048-
end
1049-
1050-
function _imfilter_inbounds!(r::AbstractResource, z, out, A::AbstractArray, k::AbstractVector, Rpre::CartesianIndices, ind, Rpost::CartesianIndices, koffset=0)
1051-
indsk = axes(k, 1)
1052-
for Ipost in Rpost
1053-
for i in ind
1054-
ik = i+koffset
1055-
for Ipre in Rpre
1056-
tmp = z
1057-
for j in indsk
1058-
@inbounds tmp += safe_for_prod(A[Ipre,ik+j,Ipost], tmp)*k[j]
1059-
end
1060-
@inbounds out[Ipre,i,Ipost] = tmp
1061-
end
1062-
end
1063-
end
1064-
out
1065-
end
1066-
1067-
function _imfilter_inbounds!(r::AbstractResource, out, A::OffsetArray, kern::ReshapedVector, border::NoPad, inds)
1068-
Rpre, ind, Rpost = iterdims(inds, kern)
1069-
k = kern.data
1070-
R, Rk = CartesianIndices(inds), CartesianIndices(axes(kern))
1071-
if isempty(R) || isempty(Rk)
1072-
return out
1073-
end
1074-
p = accumfilter(A[first(R)+first(Rk)], first(k))
1075-
z = zero(typeof(p+p))
1076-
Opre, o, Opost = KernelFactors.indexsplit(CartesianIndex(A.offsets), kern)
1077-
_imfilter_inbounds!(r, z, out, parent(A), k, Rpre, ind, Rpost, Opre, o, Opost)
1078-
end
1079-
1080-
function _imfilter_inbounds!(r::AbstractResource, z, out, A::AbstractArray, k::OffsetVector, Rpre::CartesianIndices, ind, Rpost::CartesianIndices, Opre, o, Opost)
1081-
_imfilter_inbounds!(r, z, out, A, parent(k), Rpre, ind, Rpost, Opre, o, Opost, k.offsets[1])
1082-
end
1083-
1084-
function _imfilter_inbounds!(r::AbstractResource, z, out, A::AbstractArray, k::AbstractVector, Rpre::CartesianIndices, ind, Rpost::CartesianIndices, Opre, o, Opost, koffset=0)
1021+
function _imfilter_inbounds!(r::AbstractResource, z, out, A::AbstractArray, k::AbstractVector, Rpre::CartesianIndices, ind, Rpost::CartesianIndices)
10851022
indsk = axes(k, 1)
10861023
for Ipost in Rpost
1087-
IOpost = Ipost - Opost
10881024
for i in ind
1089-
io = i-o+koffset
10901025
for Ipre in Rpre
1091-
IOpre = Ipre - Opre
10921026
tmp = z
10931027
for j in indsk
1094-
@inbounds tmp += safe_for_prod(A[IOpre,io+j,IOpost], tmp)*k[j]
1028+
@inbounds tmp += safe_for_prod(A[Ipre,i+j,Ipost], tmp)*k[j]
10951029
end
10961030
@inbounds out[Ipre,i,Ipost] = tmp
10971031
end
10981032
end
10991033
end
11001034
out
11011035
end
1102-
# end unfortunate specializations
11031036

11041037
## commented out because "virtual padding" is commented out
11051038
# function _imfilter_iter!(r::AbstractResource, out, padded, kernel::AbstractArray, iter)

0 commit comments

Comments
 (0)