@Test(expected = Test.None.class) public void testBenchmark() throws Exception { System.out.println("----- Benchmark -----"); int N = 40000; int scale = 100; int numTests = 100_000; double[][] coords = new double[N][3]; for (int i = 0; i < N; i++) { coords[i][0] = MathEx.random() * scale; coords[i][1] = MathEx.random() * scale; coords[i][2] = MathEx.random() * scale; } KDTree<double[]> kdt = new KDTree<>(coords, coords); long start = System.currentTimeMillis(); double[] q = new double[3]; for (int i = 0; i < numTests; i++) { q[0] = MathEx.random() * scale; q[1] = MathEx.random() * scale; q[2] = MathEx.random() * scale; kdt.nearest(q); } double time = (System.currentTimeMillis() - start) / 1000.0; System.out.format("Benchmark: %.2fs%n", time); assertTrue(time < 0.25); }
@Override public Neighbor<double[], E> nearest(double[] q) { NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>(); search(q, root, neighbor); neighbor.key = keys[neighbor.index]; neighbor.value = data[neighbor.index]; return neighbor.toNeighbor(); }
KDTree implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>(); search(q, root, neighbor); neighbor.key = keys[neighbor.index]; neighbor.value = data[neighbor.index]; return neighbor.toNeighbor(); } }
KDTree implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>(); search(q, root, neighbor); neighbor.key = keys[neighbor.index]; neighbor.value = data[neighbor.index]; return neighbor.toNeighbor(); } KDTree(double[][] key, E[] data); }
KDTree implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>(); search(q, root, neighbor); neighbor.key = keys[neighbor.index]; neighbor.value = data[neighbor.index]; return neighbor.toNeighbor(); } KDTree(double[][] key, E[] data); @Override String toString(); @Override Neighbor<double[], E> nearest(double[] q); @Override @SuppressWarnings("unchecked") Neighbor<double[], E>[] knn(double[] q, int k); @Override void range(double[] q, double radius, List<Neighbor<double[], E>> neighbors); }
KDTree implements NearestNeighborSearch<double[], E>, KNNSearch<double[], E>, RNNSearch<double[], E>, Serializable { @Override public Neighbor<double[], E> nearest(double[] q) { NeighborBuilder<double[], E> neighbor = new NeighborBuilder<>(); search(q, root, neighbor); neighbor.key = keys[neighbor.index]; neighbor.value = data[neighbor.index]; return neighbor.toNeighbor(); } KDTree(double[][] key, E[] data); @Override String toString(); @Override Neighbor<double[], E> nearest(double[] q); @Override @SuppressWarnings("unchecked") Neighbor<double[], E>[] knn(double[] q, int k); @Override void range(double[] q, double radius, List<Neighbor<double[], E>> neighbors);  }