Skip to content

Commit 0ae368d

Browse files
authored
Fix some ambiguities on nightly (#191)
The new algorithm for detecting ambiguities picked up some real ones that, surprisingly, were not detected previously.
1 parent 5f4769e commit 0ae368d

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1616
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
1717
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1818
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
19+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1920
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2021
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
2122
TiledIteration = "06e1c1a7-607b-532d-9fad-de7d9aa2abac"

src/ImageFiltering.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using ColorVectorSpace # for filtering RGB arrays
77
using Base: Indices, tail, fill_to_length, @pure, depwarn, @propagate_inbounds
88
using OffsetArrays: IdentityUnitRange # using the one in OffsetArrays makes this work with multiple Julia versions
99
using Requires
10+
using SparseArrays # only needed to fix an ambiguity in borderarray
1011

1112
export Kernel, KernelFactors,
1213
Pad, Fill, Inner, NA, NoPad,

src/border.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Pad(style::Symbol, lo::Dims{N}, hi::Tuple{}) where {N} = Pad(style, lo, ntuple(d
204204
Pad(style::Symbol, lo::Tuple{}, hi::Dims{N}) where {N} = Pad(style, ntuple(d->0,Val(N)), hi)
205205
Pad(style::Symbol, lo::AbstractVector{Int}, hi::AbstractVector{Int}) = Pad(style, (lo...,), (hi...,))
206206

207+
Pad(style::Symbol, ::Tuple{}) = Pad(style, (), ()) # ambiguity resolution
207208
Pad(style::Symbol, inds::Indices) = Pad(style, map(lo,inds), map(hi,inds))
208209

209210
"""
@@ -706,6 +707,7 @@ struct Inner{N} <: AbstractBorder
706707
end
707708

708709
Inner(both::Int...) = Inner(both, both)
710+
Inner(::Tuple{}) = Inner((), ()) # ambiguity resolution
709711
Inner(both::Dims{N}) where {N} = Inner(both, both)
710712
Inner(lo::Tuple{}, hi::Tuple{}) = Inner{0}(lo, hi)
711713
Inner(lo::Dims{N}, hi::Tuple{}) where {N} = Inner{N}(lo, ntuple(d->0,Val(N)))
@@ -856,6 +858,7 @@ zero.
856858
Fill(value::T, both::Dims{N}) where {T,N} = Fill{T,N}(value, both, both)
857859

858860
Fill(value, lo::AbstractVector, hi::AbstractVector) = Fill(value, (lo...,), (hi...,))
861+
Fill(value::T, ::Tuple{}) where {T} = Fill{T,0}(value, (), ()) # ambiguity resolution
859862
Fill(value::T, inds::Base.Indices{N}) where {T,N} = Fill{T,N}(value, map(lo,inds), map(hi,inds))
860863

861864
"""

src/borderarray.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,17 @@ struct BorderArray{T,N,A,B} <: AbstractArray{T,N}
6767
new{T,N,A,B}(inner, border)
6868
end
6969
end
70+
BorderVector{T,A,B} = BorderArray{T,1,A,B}
7071

71-
# these are adapted from OffsetArrays
7272
function Base.similar(A::BorderArray, ::Type{T}, dims::Dims) where T
7373
B = similar(A.inner, T, dims)
7474
end
75-
const OffsetAxis = Union{Integer, UnitRange, Base.OneTo, IdentityUnitRange}
76-
function Base.similar(A::BorderArray, ::Type{T}, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where T
77-
similar(A.inner, T, inds)
75+
const BaseAxisTypes = Union{Integer, Base.OneTo}
76+
const OffsetAxisTypes = Union{StaticArrays.HeterogeneousShape, OffsetArrays.IdOffsetRange}
77+
for Ax in (BaseAxisTypes, StaticArrays.HeterogeneousShape, OffsetAxisTypes)
78+
@eval function Base.similar(A::BorderArray, ::Type{T}, inds::Tuple{$Ax,Vararg{$Ax}}) where T
79+
similar(A.inner, T, inds)
80+
end
7881
end
7982

8083
@inline function Base.axes(o::BorderArray)
@@ -156,6 +159,10 @@ function Base.checkbounds(::Type{Bool}, arr::BorderArray, index::CartesianIndex)
156159
end |> all
157160
end
158161

162+
function Base.copy!(dst::SparseVector, src::BorderVector) # ambiguity resolution
163+
axes(dst) == axes(src) || throw(DimensionMismatch("axes(dst) == axes(src) must hold."))
164+
_copy!(dst, src, src.border)
165+
end
159166
function Base.copy!(dst::AbstractArray, src::BorderArray)
160167
axes(dst) == axes(src) || throw(DimensionMismatch("axes(dst) == axes(src) must hold."))
161168
_copy!(dst, src, src.border)

test/runtests.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ using ImageFiltering, Test
22
import StaticArrays
33
using Random
44

5-
aif = detect_ambiguities(ImageFiltering, Kernel, KernelFactors, Base)
6-
# Because StaticArrays has ambiguities with Base, we have to "subtract" these
7-
asa = detect_ambiguities(StaticArrays, Base)
8-
@test isempty(setdiff(aif, asa))
5+
# Ambiguity test
6+
if Base.VERSION >= v"1.6.0-DEV.1005" # julia #37616
7+
@test isempty(detect_ambiguities(ImageFiltering, Kernel, KernelFactors))
8+
else
9+
# Because StaticArrays may have ambiguities with Base, we have to "subtract" these
10+
aif = detect_ambiguities(ImageFiltering, Kernel, KernelFactors, Base)
11+
asa = detect_ambiguities(StaticArrays, Base)
12+
@test isempty(setdiff(aif, asa))
13+
end
914

1015
function typestring(::Type{T}) where T # from https://github.com/JuliaImages/ImageCore.jl/pull/133
1116
buf = IOBuffer()

0 commit comments

Comments
 (0)