KristofferC / NearestNeighbors.jl

High performance nearest neighbor data structures (KDTree and BallTree) and algorithms for Julia.
Other
413 stars 65 forks source link

Add generic constructor to `HyperSphere` #154

Closed eliascarv closed 1 year ago

eliascarv commented 1 year ago

This PR adds a constructor to HyperSphere that accepts an AbstractVector. This constructor is needed because of this function:

function _inrange(tree::BallTree{V},
                  point::AbstractVector,
                  radius::Number,
                  idx_in_ball::Union{Nothing, Vector{Int}}) where {V}
    ball = HyperSphere(convert(V, point), convert(eltype(V), radius))  # The "query ball"
    return inrange_kernel!(tree, 1, point, ball, idx_in_ball)  # Call the recursive range finder
end

The type parameter V of BallTree accepts any subtype of AbstractVector, but in the current code, HyperSphere does not have a constructor that accepts AbstractVectors.

eliascarv commented 1 year ago

Dear maintainers, appreciate if you can review and merge this small non-breaking generalization, it is holding back some advancements downstream. It would be great if you could release a patch as well. Thanks in advance.

juliohm commented 1 year ago

@KristofferC can you please take a look at this PR?

We are suffering from the issue and the proposed change seems to address it nicely for other types of StaticVector.