Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 5, 2015
2 parents 62ab5b3 + 624f497 commit 172f02b
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 99 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ Since this is a new project there are still some obvious improvements which are
## Author
Kristoffer Carlsson (@KristofferC)

## Requirements

Currently the "ArrayViews" package is required because `sub` in v0.3 of Julia
is quite bad.

## Examples

In the examples, notice that the module is called `KDtree` and the actual tree type is called `KDTree`. This is because modules and types can currently not have the same name in Julia.
Expand Down
48 changes: 31 additions & 17 deletions benchmark/bench_build_tree.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
using KDtree

dims = 1:6
n_points = [10^i for i in 1:5]

times = Array(Float64, length(dims), length(n_points))

# Compile
KDTree(randn(2,2))

i = 0
for dim in dims
j = 0
i+=1
for n_point in n_points
j+=1
data = randn(dim, n_point)
times[i,j] = @elapsed KDTree(data)

function run_bench_tree()
dims = 1:6
n_points = [10^i for i in 1:5]

times = fill(0.0, length(dims), length(n_points))

# Compile
KDTree(randn(2,2))

n_iters = 5

for (i, dim) in enumerate(dims)
for (j, n_point) in enumerate(n_points)
for z = 1:n_iters
data = rand(dim, n_point)
times[i,j] += @elapsed KDTree(data)
end
times[i,j] /= n_iters
end
end

println(times)
end

println(times)
run_bench_tree()

#=
2015-02-04: With type, no bounds, no views etc
[[3.11e-6 3.2033e-5 0.000296701 0.003287041 0.08933542
5.598e-6 3.2656e-5 0.000348329 0.004047143 0.049544467
6.22e-6 3.6077e-5 0.000363257 0.02172358 0.058261703
5.909e-6 3.8565e-5 0.000402444 0.004890908 0.080466724
6.842e-6 4.0431e-5 0.000430746 0.005446367 0.093348975
7.464e-6 4.3541e-5 0.000463091 0.005823931 0.103238088]
2015-02-03: (with ArrayViews)
[1.3373e-5 4.7584e-5 0.000489836 0.005438274 0.063624952
7.775e-6 5.4737e-5 0.000640676 0.007319247 0.083582606
Expand Down
47 changes: 34 additions & 13 deletions benchmark/bench_knn.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
using KDtree

dims = 3
n_points = [10^i for i in 3:6]
ks = [1, 3, 10, 50, 100, 500]

times = Array(Float64, length(ks), length(n_points))
function run_bench_knn()
dims = 3
n_points = [10^i for i in 3:5]
ks = [1, 3, 10, 50, 100, 500]

# Compile it
tree = KDTree(randn(2,2))
k_nearest_neighbour(tree, zeros(2), 1)
n_iters = 10

for (i, k) in enumerate(ks)
for (j , n_point) in enumerate(n_points)
data = randn(dims, n_point)
tree = KDTree(data)
times[i,j] = @elapsed k_nearest_neighbour(tree, zeros(dims), k)
times = fill(0.0, length(ks), length(n_points))

# Compile it
tree = KDTree(randn(2,2))
k_nearest_neighbour(tree, zeros(2), 1)

for (i, k) in enumerate(ks)
for (j , n_point) in enumerate(n_points)
data = rand(dims, n_point)
tree = KDTree(data)
for z in 1:n_iters
p = rand(dims)
times[i,j] += @elapsed k_nearest_neighbour(tree, p, k)
end
times[i,j] /= n_iters
end
end

println(times)
return
end

println(times)
run_bench_knn()

#=
2015-02-04 No bounds, type fixes
[4.139509999999997e-6 6.266810000000003e-6 1.1824519999999996e-5 1.2813520000000002e-5
6.926150000000001e-6 8.745540000000002e-6 1.5848950000000007e-5 1.9322909999999995e-5
1.2340789999999995e-5 1.7301359999999997e-5 2.9695020000000008e-5 3.380342999999999e-5
3.891018e-5 5.718188999999997e-5 8.192254999999999e-5 0.00010137918999999997
6.649346000000001e-5 9.620713999999998e-5 0.00014474611999999997 0.00016459152000000002
0.0004432140299999998 0.0006229702799999999 0.0008457700199999998 0.0009439302800000001]
2015-02-03: ArrayViews:
[1.3996e-5 2.1771e-5 5.1316e-5 4.4474e-5
2.0837e-5 2.5502e-5 5.9402e-5 6.8732e-5
Expand Down
45 changes: 29 additions & 16 deletions benchmark/bench_query_ball.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
using KDtree

dims = 3
n_points = [10^i for i in 3:5]
rs = [0.1 0.2 0.3 0.4]

times = Array(Float64, length(rs), length(n_points))

# Compile it
tree = KDTree(randn(2,2))
query_ball_point(tree, zeros(2), 0.1)


for (i, r) in enumerate(rs)
for (j , n_point) in enumerate(n_points)
data = randn(dims, n_point)
tree = KDTree(data)
times[i,j] = @elapsed query_ball_point(tree, zeros(dims), r)
function run_bench_query_ball()
dims = 3
n_points = [10^i for i in 3:5]
rs = [0.1 0.2 0.3 0.4]

times = fill(0.0, length(rs), length(n_points))

# Compile it
n_iters = 1000

tree = KDTree(randn(2,2))
query_ball_point(tree, zeros(2), 0.1)

for (i, r) in enumerate(rs)
for (j , n_point) in enumerate(n_points)
data = rand(dims, n_point)
tree = KDTree(data)
for z = 1:n_iters
p = rand(dims)
times[i,j] += @elapsed query_ball_point(tree, p, r)
end
times[i,j] /= n_iters
end
end

println(times)
end

println(times)
run_bench_query_ball()


#=
2015-02-03: ArrayViews + no sqrt
[1.1196e-5 1.9593e-5 7.5885e-5
1.5239e-5 4.1986e-5 0.000167011
Expand Down
2 changes: 2 additions & 0 deletions src/KDtree.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module KDtree

import Base.show

using ArrayViews

export KDTree
Expand Down
Loading

0 comments on commit 172f02b

Please sign in to comment.