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

Fix breakage from the new ReinterpretArray #60

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ball_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# The tree uses the triangle inequality to prune the search space
# when finding the neighbors to a point,
struct BallTree{V <: AbstractVector,N,T,M <: Metric} <: NNTree{V,M}
data::Vector{V}
data::AbstractVector{V}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be bad for performance because this is an abstract field. See (https://docs.julialang.org/en/stable/manual/performance-tips/#Avoid-containers-with-abstract-type-parameters-1),

Perhaps we need to just do like

BallTree{V <: AbstractVector, ...}
    data::V
    .
    .
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this was a mistake on my part. I intended to leave data::Vector{V} there, like in BruteTree. In the latter it was necessary to do a convert in the BruteTree constructor, but not with BallTree I think.

hyper_spheres::Vector{HyperSphere{N,T}} # Each hyper sphere bounds its children
indices::Vector{Int} # Translates from tree index -> point index
metric::M # Metric used for tree
Expand All @@ -28,7 +28,7 @@ end

Creates a `BallTree` from the data using the given `metric` and `leafsize`.
"""
function BallTree(data::Vector{V},
function BallTree(data::AbstractVector{V},
metric::M = Euclidean();
leafsize::Int = 10,
reorder::Bool = true,
Expand Down Expand Up @@ -95,7 +95,7 @@ end

# Recursive function to build the tree.
function build_BallTree(index::Int,
data::Vector{V},
data::AbstractVector{V},
data_reordered::Vector{V},
hyper_spheres::Vector{HyperSphere{N,T}},
metric::Metric,
Expand Down
4 changes: 2 additions & 2 deletions src/brute_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ end

Creates a `BruteTree` from the data using the given `metric`.
"""
function BruteTree(data::Vector{V}, metric::Metric = Euclidean();
function BruteTree(data::AbstractVector{V}, metric::Metric = Euclidean();
reorder::Bool=false, leafsize::Int=0, storedata::Bool=true) where {V <: AbstractVector}
BruteTree(storedata ? data : Vector{V}(), metric, reorder)
BruteTree(storedata ? convert(Vector{V}, data) : Vector{V}(), metric, reorder)
end

function BruteTree(data::Matrix{T}, metric::Metric = Euclidean();
Expand Down
2 changes: 1 addition & 1 deletion src/datafreetree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function injectdata(datafreetree::DataFreeTree, data::Matrix{T}) where {T}
injectdata(datafreetree, new_data, new_hash)
end

function injectdata(datafreetree::DataFreeTree, data::Vector{V}, new_hash::UInt64=0) where {V <: AbstractVector}
function injectdata(datafreetree::DataFreeTree, data::AbstractVector{V}, new_hash::UInt64=0) where {V <: AbstractVector}
if new_hash == 0
new_hash = hash(data)
end
Expand Down
2 changes: 1 addition & 1 deletion src/hyperrectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct HyperRectangle{T}
end

# Computes a bounding box around a point cloud
function compute_bbox(data::Vector{V}) where {V <: AbstractVector}
function compute_bbox(data::AbstractVector{V}) where {V <: AbstractVector}
T = eltype(V)
n_dim = length(V)
maxes = Vector{T}(n_dim)
Expand Down
2 changes: 1 addition & 1 deletion src/hyperspheres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
return c1, false
end

function create_bsphere(data::Vector{V}, metric::Metric, indices::Vector{Int}, low, high, ab) where {V}
function create_bsphere(data::AbstractVector{V}, metric::Metric, indices::Vector{Int}, low, high, ab) where {V}
n_dim = size(data, 1)
n_points = high - low + 1
# First find center of all points
Expand Down
2 changes: 1 addition & 1 deletion src/inrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Find all the points in the tree which is closer than `radius` to `points`. If
`sortres = true` the resulting indices are sorted.
"""
function inrange(tree::NNTree,
points::Vector{T},
points::AbstractVector{T},
radius::Number,
sortres=false) where {T <: AbstractVector}
check_input(tree, points)
Expand Down
4 changes: 2 additions & 2 deletions src/kd_tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
Creates a `KDTree` from the data using the given `metric` and `leafsize`.
The `metric` must be a `MinkowskiMetric`.
"""
function KDTree(data::Vector{V},
function KDTree(data::AbstractVector{V},
metric::M = Euclidean();
leafsize::Int = 10,
storedata::Bool = true,
Expand Down Expand Up @@ -87,7 +87,7 @@ function KDTree(data::Matrix{T},
end

function build_KDTree(index::Int,
data::Vector{V},
data::AbstractVector{V},
data_reordered::Vector{V},
hyper_rec::HyperRectangle,
nodes::Vector{KDNode{T}},
Expand Down
2 changes: 1 addition & 1 deletion src/knn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ in the `tree`. If `sortres = true` the result is sorted such that the results ar
in the order of increasing distance to the point. `skip` is an optional predicate
to determine if a point that would be returned should be skipped.
"""
function knn(tree::NNTree{V}, points::Vector{T}, k::Int, sortres=false, skip::Function=always_false) where {V, T <: AbstractVector}
function knn(tree::NNTree{V}, points::AbstractVector{T}, k::Int, sortres=false, skip::Function=always_false) where {V, T <: AbstractVector}
check_input(tree, points)
check_k(tree, k)
n_points = length(points)
Expand Down
2 changes: 1 addition & 1 deletion src/tree_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct TreeData
end


function TreeData{V}(data::Vector{V}, leafsize)
function TreeData{V}(data::AbstractVector{V}, leafsize)
n_dim, n_p = length(V), length(data)

# If number of points is zero
Expand Down
2 changes: 1 addition & 1 deletion src/tree_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end

# Store all the points in a leaf node continuously in memory in data_reordered to improve cache locality.
# Also stores the mapping to get the index into the original data from the reordered data.
function reorder_data!(data_reordered::Vector{V}, data::Vector{V}, index::Int,
function reorder_data!(data_reordered::Vector{V}, data::AbstractVector{V}, index::Int,
indices::Vector{Int}, indices_reordered::Vector{Int}, tree_data::TreeData) where {V}

for i in get_leaf_range(tree_data, index)
Expand Down
4 changes: 2 additions & 2 deletions src/utilities.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Find the dimension witht the largest spread.
function find_largest_spread(data::Vector{V}, indices, low, high) where {V}
function find_largest_spread(data::AbstractVector{V}, indices, low, high) where {V}
T = eltype(V)
n_points = high - low + 1
n_dim = length(V)
Expand All @@ -25,7 +25,7 @@ end
# Taken from https://github.com/JuliaLang/julia/blob/v0.3.5/base/sort.jl
# and modified to compare against a matrix
@inline function select_spec!(v::Vector{Int}, k::Int, lo::Int,
hi::Int, data::Vector, dim::Int)
hi::Int, data::AbstractVector, dim::Int)
@inbounds lo <= k <= hi || error("select index $k is out of range $lo:$hi")
while lo < hi
if hi - lo == 1
Expand Down