@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();
    }
@Test
    public void testNearest() {
        System.out.println("nearest");

        double[][] data = Matrix.randn(1000, 10).toArray();
        KDTree<double[]> kdtree = new KDTree<>(data, data);
        LinearSearch<double[], double[]> naive = LinearSearch.of(data, new EuclideanDistance());

        for (int i = 0; i < data.length; i++) {
            Neighbor<double[], double[]> n1 = naive.nearest(data[i]);
            Neighbor<double[], double[]> n2 = kdtree.nearest(data[i]);
            assertEquals(n1.index, n2.index);
            assertEquals(n1.value, n2.value);
            assertEquals(n1.distance, n2.distance, 1E-7);
        }
    }