Skip to content

Commit

Permalink
Limit searchsorted specializations to julia versions < v"1.12" (#364)
Browse files Browse the repository at this point in the history
These are unnecessary on a recent master, as the methods in `Base` correctly account for offset indices.
  • Loading branch information
jishnub authored Dec 4, 2024
1 parent 7d3ea6c commit 8decfce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "OffsetArrays"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "1.14.1"
version = "1.14.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
31 changes: 18 additions & 13 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -824,24 +824,29 @@ centered(A::AbstractArray, cp::Dims=center(A)) = OffsetArray(A, .-cp)

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

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

if VERSION <= v"1.2"
# ambiguity warnings in earlier versions
# we may pass the searchsorted* functions to the parent, and wrap the offset
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
_safe_f = Symbol("_safe_" * String(f))
@eval Base.$f(v::OffsetVector, x, ilo::Int, ihi::Int, o::Base.Ordering) =
@eval function $_safe_f(v::OffsetVector, x, ilo, ihi, o::Base.Ordering)
offset = v.offsets[1]
$f(parent(v), x, ilo - offset, ihi - offset, o) .+ offset
end
@eval Base.$f(v::OffsetVector, x, ilo::T, ihi::T, o::Base.Ordering) where T<:Integer =
$_safe_f(v, x, ilo, ihi, o)
end

if VERSION <= v"1.2"
# ambiguity warnings in earlier versions
for f in [:searchsortedfirst, :searchsortedlast, :searchsorted]
_safe_f = Symbol("_safe_" * String(f))
@eval Base.$f(v::OffsetVector, x, ilo::Int, ihi::Int, o::Base.Ordering) =
$_safe_f(v, x, ilo, ihi, o)
end
end
end

if VERSION < v"1.1.0-DEV.783"
Expand Down

2 comments on commit 8decfce

@jishnub
Copy link
Member Author

@jishnub jishnub commented on 8decfce Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/120802

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.14.2 -m "<description of version>" 8decfce50edeeab1694232f80427ea66c6afc023
git push origin v1.14.2

Please sign in to comment.