Skip to content

Commit

Permalink
revert "vectorize the compute_bbox function (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Sep 23, 2024
1 parent a20c107 commit be5b3a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/hyperrectangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/test_knn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit be5b3a6

Please sign in to comment.