How do you use RadixSort in the Julia v1.9?

using Base.Sort: RadixSort;
x = rand(100)
sort(x, alg=RadixSort())

This should sort x but is giving me the error and I don’t understand the issue here. Also, the doc doesn’t currently list RadixSort yet Sorting and Related Functions · The Julia Language

        
ERROR: ArgumentError: mn is needed but has not been computed
Stacktrace:
 [1] _mn(v::Vector{Float64}, o::Base.Order.ForwardOrdering, kw::NamedTuple{(:scratch, :lo, :hi), Tuple{Nothing, Int64, Int64}})
   @ Base.Sort .\sort.jl:430
 [2] _sort!(v::Vector{Float64}, a::RadixSort, o::Base.Order.ForwardOrdering, kw::NamedTuple{(:scratch,), Tuple{Nothing}})
   @ Base.Sort .\sort.jl:924
 [3] sort!(v::Vector{Float64}; alg::RadixSort, lt::Function, by::Function, rev::Nothing, order::Base.Order.ForwardOrdering, scratch::Nothing)
   @ Base.Sort .\sort.jl:1374
 [4] sort(v::Vector{Float64}; kws::Base.Pairs{Symbol, RadixSort, Tuple{Symbol}, NamedTuple{(:alg,), Tuple{RadixSort}}})
   @ Base.Sort .\sort.jl:1400
 [5] top-level scope
   @ c:\git\SortingLab\test\tests.jl:8

Context

RadixSort is an internal performance optimization. There’s no extensible API to define radixing on custom types and no public way to opt-in to using it when Julia thinks it’s not the best algorithm for the task at hand.

“How do you use RadixSort in Julia v1.9?”

This will use RadixSort in Julia 1.9:

x = rand(1000)
sort(x)

The reason we need x = rand(1000) instead of x = rand(100) is because RadixSort is not a great algorithm for small inputs and so we don’t use it for small inputs.

How can I tell Julia to use RadixSort even when Julia thinks it’s not the right choice

The only good reason I can think of to do this is if you are investigating sorting performance for sorting-related research (e.g. trying to make Base.sort faster). However, if you insist, it is possible to do this, while depending on Julia internals (i.e. your code may break in a minor release)

Here are a couple ways to do this:

x = rand(100)
@assert v"1.9" <= VERSION < v"1.13"
sort(x, alg=Base.Sort.IEEEFloatOptimization(Base.Sort.ComputeExtrema(Base.Sort.RadixSort())))

# or

x = rand(UInt, 100)
@assert v"1.9" <= VERSION < v"1.13"
Base.Sort.radix_sort!(x, extrema(eachindex(x))..., unsigned(8*Base.elsize(x)), similar(x), 0)