Skip to content

Commit 8decfce

Browse files
authored
Limit searchsorted specializations to julia versions < v"1.12" (#364)
These are unnecessary on a recent master, as the methods in `Base` correctly account for offset indices.
1 parent 7d3ea6c commit 8decfce

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OffsetArrays"
22
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3-
version = "1.14.1"
3+
version = "1.14.2"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

Diff for: src/OffsetArrays.jl

+18-13
Original file line numberDiff line numberDiff line change
@@ -824,24 +824,29 @@ centered(A::AbstractArray, cp::Dims=center(A)) = OffsetArray(A, .-cp)
824824

825825
centered(A::AbstractArray, i::CartesianIndex) = centered(A, Tuple(i))
826826

827-
# we may pass the searchsorted* functions to the parent, and wrap the offset
828-
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
829-
_safe_f = Symbol("_safe_" * String(f))
830-
@eval function $_safe_f(v::OffsetVector, x, ilo, ihi, o::Base.Ordering)
831-
offset = v.offsets[1]
832-
$f(parent(v), x, ilo - offset, ihi - offset, o) .+ offset
833-
end
834-
@eval Base.$f(v::OffsetVector, x, ilo::T, ihi::T, o::Base.Ordering) where T<:Integer =
835-
$_safe_f(v, x, ilo, ihi, o)
836-
end
827+
if VERSION < v"1.12.0-DEV.1713"
828+
# The Base implementations are fixed in https://github.com/JuliaLang/julia/pull/56464 and https://github.com/JuliaLang/julia/pull/56474
829+
# we therefore limit these specializations to older versions of julia
837830

838-
if VERSION <= v"1.2"
839-
# ambiguity warnings in earlier versions
831+
# we may pass the searchsorted* functions to the parent, and wrap the offset
840832
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
841833
_safe_f = Symbol("_safe_" * String(f))
842-
@eval Base.$f(v::OffsetVector, x, ilo::Int, ihi::Int, o::Base.Ordering) =
834+
@eval function $_safe_f(v::OffsetVector, x, ilo, ihi, o::Base.Ordering)
835+
offset = v.offsets[1]
836+
$f(parent(v), x, ilo - offset, ihi - offset, o) .+ offset
837+
end
838+
@eval Base.$f(v::OffsetVector, x, ilo::T, ihi::T, o::Base.Ordering) where T<:Integer =
843839
$_safe_f(v, x, ilo, ihi, o)
844840
end
841+
842+
if VERSION <= v"1.2"
843+
# ambiguity warnings in earlier versions
844+
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
845+
_safe_f = Symbol("_safe_" * String(f))
846+
@eval Base.$f(v::OffsetVector, x, ilo::Int, ihi::Int, o::Base.Ordering) =
847+
$_safe_f(v, x, ilo, ihi, o)
848+
end
849+
end
845850
end
846851

847852
if VERSION < v"1.1.0-DEV.783"

0 commit comments

Comments
 (0)