Skip to content

partial sort functionality? #1

@jacob-roth

Description

@jacob-roth

I think this project is really cool! I have an application where I need to perform partial sorting (per here and here) and was trying to adapt your code to handle this case. Would you have any suggestions on where to start? I naively tried to modify ssortperm!! to accept lo and hi based on the desired partial sort indices, e.g.,

function partialssortperm!!(ix::AbstractVector{Int}, v::AbstractVector, idxrange::UnitRange{Int}; lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward)
    axes(ix) == axes(v) || throw(ArgumentError("index array must have the same size/axes as the source array, $(axes(ix)) != $(axes(v))"))
    ix .= LinearIndices(v)
    vs = StructArray{Tuple{eltype(v),eltype(ix)}}(val=v, ix=ix)
    o = ord(lt, by, rev ? true : nothing, order)
    lo = idxrange[1] # <- new
    hi = idxrange[end] # <- new
    _sortperm_inplace_small_optimization!(ix, v, vs, lo, hi, o::Ordering)
    ix
end

but I failed to get a correct implementation.

Do you think there's an easy fix? Or do you think it involve digging into the internals of _sortperm_inplace_small_optimization!?

Thanks!
Jake

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions