Skip to content

Radix sort is broken for OffsetArrays with negative offset #56

@LilithHafner

Description

@LilithHafner
using SortingAlgorithms, OffsetArrays
sort!(OffsetArray(rand(1000), -500);  alg=RadixSort)

With julia --check-bounds=yes, I get

ERROR: BoundsError: attempt to access 1000-element OffsetArray(::Vector{Float64}, -499:500) with eltype Float64 with indices -499:500 at index [770]
Stacktrace:
  [1] throw_boundserror(A::OffsetVector{Float64, Vector{Float64}}, I::Tuple{Int64})
    @ Base ./abstractarray.jl:691
  [2] checkbounds
    @ ./abstractarray.jl:656 [inlined]
  [3] setindex!
    @ ~/.julia/packages/OffsetArrays/aKeSs/src/OffsetArrays.jl:444 [inlined]
  [4] _setindex!
    @ ./abstractarray.jl:1334 [inlined]
  [5] setindex!
    @ ./abstractarray.jl:1315 [inlined]
  [6] sort!(vs::OffsetVector{Float64, Vector{Float64}}, lo::Int64, hi::Int64, ::SortingAlgorithms.RadixSortAlg, o::Base.Order.ForwardOrdering, ts::OffsetVector{Float64, Vector{Float64}})
    @ SortingAlgorithms ~/.julia/packages/SortingAlgorithms/PEcBU/src/SortingAlgorithms.jl:101
  [7] sort!
    @ ~/.julia/packages/SortingAlgorithms/PEcBU/src/SortingAlgorithms.jl:66 [inlined]
  [8] fpsort!
    @ ~/.julia/packages/SortingAlgorithms/PEcBU/src/SortingAlgorithms.jl:131 [inlined]
  [9] sort!
    @ ./sort.jl:1234 [inlined]
 [10] #sort!#8
    @ ./sort.jl:725 [inlined]
 [11] top-level scope
    @ REPL[5]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions