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

Package calling searchsortedfirst with non sorted ranges #57

Open
KristofferC opened this issue Apr 14, 2021 · 1 comment
Open

Package calling searchsortedfirst with non sorted ranges #57

KristofferC opened this issue Apr 14, 2021 · 1 comment

Comments

@KristofferC
Copy link

In 1.6.1 the following behavior changed:

1.6.0:

julia> searchsortedfirst(1.0:-0.1:0.1, 0.3)
8

julia> searchsortedfirst(collect(1.0:-0.1:0.1), 0.3)
1

1.6.1:

julia> searchsortedfirst(1.0:-0.1:0.1, 0.3)
1

julia> searchsortedfirst(collect(1.0:-0.1:0.1), 0.3)
1

This causes the test here

@test [V4[Near(x)] for x in xs] == [V5[Near(x)] for x in xs]
to fail.

The issue seems to be that the package is using searchsortedfirst but the range it passes in is not sorted:

iplus = searchsortedfirst(range, sel.val)

4|debug> st
In findindex(sel, range) at /Users/kristoffercarlsson/.julia/packages/AxisKeys/G3Okw/src/selectors.jl:66
 66  function findindex(sel::Near, range::AbstractRange)
 67      iplus = searchsortedfirst(range, sel.val)
 68      # "index of the first value in a greater than or equal to x"
>69      if abs(range[iplus]-sel.val) < abs(range[iplus-1]-sel.val)
 70          return iplus
 71      else
 72          return iplus-1
 73      end
 74  end

About to run: (getindex)(1.0:-0.1:0.1, 0)
4|julia> range
1.0:-0.1:0.1

4|julia> issorted(range)
false

Perhaps a rev was forgotten to be passed to searchsortedfirst?

@mcabbott
Copy link
Owner

Thanks, that does look wrong.

Looks like it has other bugs, too, when I try to test it more deeply:

julia> AxisKeys.findindex(Near(0.1), 3:0.1:4)
ERROR: BoundsError: attempt to access 11-element StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}} at index [0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants