|
| 1 | +using NearestNeighborDescent: sample_neighbors, make_knn_heaps |
1 | 2 |
|
2 | 3 | @testset "sample neighbors tests" begin
|
3 | 4 | @testset "sample_rate = 1. tests" begin
|
4 | 5 | points = collect(1:10)
|
5 | 6 | n_neighbors = 4
|
6 | 7 |
|
7 | 8 | # zero neighbors
|
8 |
| - idxs = NNDescent.sample_neighbors(length(points), 0) |
| 9 | + idxs = sample_neighbors(length(points), 0) |
9 | 10 | @test length(idxs) == 0
|
10 | 11 |
|
11 | 12 | # k < n
|
12 |
| - idxs = NNDescent.sample_neighbors(length(points), n_neighbors) |
| 13 | + idxs = sample_neighbors(length(points), n_neighbors) |
13 | 14 | @test length(idxs) == n_neighbors
|
14 | 15 | @test issubset(idxs, points)
|
15 | 16 |
|
16 | 17 | # k > n
|
17 |
| - idxs = NNDescent.sample_neighbors(length(points), length(points)+5) |
| 18 | + idxs = sample_neighbors(length(points), length(points)+5) |
18 | 19 | @test length(idxs) == length(points)
|
19 | 20 | end
|
20 | 21 | @testset "sample_rate = .5 tests" begin
|
|
23 | 24 | ρ = .5
|
24 | 25 |
|
25 | 26 | # zero neighbors
|
26 |
| - idxs = NNDescent.sample_neighbors(length(points), 0, ρ) |
| 27 | + idxs = sample_neighbors(length(points), 0, ρ) |
27 | 28 | @test length(idxs) == 0
|
28 | 29 |
|
29 | 30 | # k < n
|
30 |
| - idxs = NNDescent.sample_neighbors(length(points), n_neighbors, ρ) |
| 31 | + idxs = sample_neighbors(length(points), n_neighbors, ρ) |
31 | 32 | @test ρ*n_neighbors ≥ length(idxs)
|
32 | 33 | @test issubset(idxs, points)
|
33 | 34 |
|
34 | 35 | # k > n
|
35 |
| - idxs = NNDescent.sample_neighbors(length(points), 2*length(points), ρ) |
| 36 | + idxs = sample_neighbors(length(points), 2*length(points), ρ) |
36 | 37 | @test length(idxs) == length(points)
|
37 | 38 | end
|
38 | 39 | @testset "exclude set tests" begin
|
39 | 40 | points = collect(1:10)
|
40 | 41 |
|
41 | 42 | # exclude 1
|
42 |
| - idxs = NNDescent.sample_neighbors(length(points), |
| 43 | + idxs = sample_neighbors(length(points), |
43 | 44 | length(points),
|
44 | 45 | exclude=[1])
|
45 | 46 | @test idxs ⊊ points
|
46 | 47 | @test !(1 ∈ idxs)
|
47 | 48 |
|
48 | 49 | # exclude all
|
49 |
| - idxs = NNDescent.sample_neighbors(length(points), |
| 50 | + idxs = sample_neighbors(length(points), |
50 | 51 | length(points),
|
51 | 52 | exclude=points)
|
52 | 53 | @test length(idxs) == 0
|
|
59 | 60 | data = [rand(3) for _ in 1:10]
|
60 | 61 | n_neighbors = 3
|
61 | 62 |
|
62 |
| - knn_heaps = NNDescent.make_knn_heaps(data, n_neighbors, Euclidean()) |
| 63 | + knn_heaps = make_knn_heaps(data, n_neighbors, Euclidean()) |
63 | 64 |
|
64 | 65 | @test length(knn_heaps) == length(data)
|
65 | 66 | for p in 1:length(knn_heaps)
|
|
75 | 76 | @testset "Int tests" begin
|
76 | 77 | data = [rand([0, 1], 3) for _ in 1:10]
|
77 | 78 | n_neighbors = 2
|
78 |
| - knn_heaps = NNDescent.make_knn_heaps(data, n_neighbors, Hamming()) |
| 79 | + knn_heaps = make_knn_heaps(data, n_neighbors, Hamming()) |
79 | 80 |
|
80 | 81 | @test length(knn_heaps) == length(data)
|
81 | 82 | for p in 1:length(knn_heaps)
|
|
0 commit comments