diff --git a/src/hyperrectangles.jl b/src/hyperrectangles.jl index 261fac1..1254ff4 100644 --- a/src/hyperrectangles.jl +++ b/src/hyperrectangles.jl @@ -4,9 +4,21 @@ struct HyperRectangle{V <: AbstractVector} end function compute_bbox(data::AbstractVector{V}) where {V <: AbstractVector} - mins = mapreduce(identity, (a, b) -> min.(a, b), data; init=fill(Inf,V)) - maxes = mapreduce(identity, (a, b) -> max.(a, b), data; init=fill(-Inf,V)) - return HyperRectangle(mins, maxes) + T = eltype(V) + n_dim = length(V) + maxes = zeros(MVector{n_dim, T}) + mins = zeros(MVector{n_dim, T}) + @inbounds for j in 1:n_dim + dim_max = typemin(T) + dim_min = typemax(T) + for k in eachindex(data) + dim_max = max(data[k][j], dim_max) + dim_min = min(data[k][j], dim_min) + end + maxes[j] = dim_max + mins[j] = dim_min + end + return HyperRectangle(SVector(mins), SVector(maxes)) end @inline distance_function_max(vald, maxd, mind) = max(abs(maxd - vald), abs(vald - mind)) diff --git a/test/test_knn.jl b/test/test_knn.jl index 99d96a5..4298409 100644 --- a/test/test_knn.jl +++ b/test/test_knn.jl @@ -105,7 +105,7 @@ end import Tensors @testset "Tensors.Vec (no `StaticArrays.setindex` defined)" begin - vdata = [rand(Tensors.Vec{2}) for _ in 1:10] + vdata = [rand(Tensors.Vec{2}) for _ in 1:30] # should be bigger than leaf size sdata = SVector{2}.(vdata) vpoints = [rand(Tensors.Vec{2}) for _ in 1:2] spoints = SVector{2}.(vpoints)