public void search(@NonNull INDArray target, int k, List<DataPoint> results, List<Double> distances) {
if (items != null)
if (!target.isVector() || target.columns() != items.columns() || target.rows() > 1)
throw new ND4JIllegalStateException("Target for search should have shape of [" + 1 + ", "
+ items.columns() + "] but got " + Arrays.toString(target.shape()) + " instead");
k = Math.min(k, items.rows());
results.clear();
distances.clear();
PriorityQueue<HeapObject> pq = new PriorityQueue<>(items.rows(), new HeapObjectComparator());
search(root, target, k + 1, pq, Double.MAX_VALUE);
if (pq.size() > k)
pq.poll();
while (!pq.isEmpty()) {
HeapObject ho = pq.peek();
results.add(new DataPoint(ho.getIndex(), ho.getPoint()));
distances.add(ho.getDistance());
pq.poll();
}
if (invert) {
Collections.reverse(results);
Collections.reverse(distances);
}
}