### Question:
KDTree implements Serializable { public INDArray delete(INDArray point) { KDNode node = root; int _disc = 0; while (node != null) { if (node.point == point) break; int successor = successor(node, point, _disc); if (successor < 1) node = node.getLeft(); else node = node.getRight(); _disc = (_disc + 1) % dims; } if (node != null) { if (node == root) { root = delete(root, _disc); } else node = delete(node, _disc); size--; if (size == 1) { rect = new HyperRect(HyperRect.point(point)); } else if (size == 0) rect = null; } return node.getPoint(); } KDTree(int dims); void insert(INDArray point); INDArray delete(INDArray point); List<Pair<Float, INDArray>> knn(INDArray point, float distance); Pair<Double, INDArray> nn(INDArray point); int size(); final static int GREATER; final static int LESS; }### Answer:
@Test public void testDelete() { int elements = 10; List<Double> digits = Arrays.asList(1.0, 0.0, 2.0, 3.0); KDTree kdTree = new KDTree(digits.size()); List<List<Double>> lists = new ArrayList<>(); for (int i = 0; i < elements; i++) { List<Double> thisList = new ArrayList<>(digits.size()); for (int k = 0; k < digits.size(); k++) { thisList.add(digits.get(k) + i); } lists.add(thisList); } INDArray toDelete = Nd4j.empty(DataType.DOUBLE), leafToDelete = Nd4j.empty(DataType.DOUBLE); for (int i = 0; i < elements; i++) { double[] features = Doubles.toArray(lists.get(i)); INDArray ind = Nd4j.create(features, new long[]{1, features.length}, DataType.FLOAT); if (i == 1) toDelete = ind; if (i == elements - 1) { leafToDelete = ind; } kdTree.insert(ind); assertEquals(i + 1, kdTree.size()); } kdTree.delete(toDelete); assertEquals(9, kdTree.size()); kdTree.delete(leafToDelete); assertEquals(8, kdTree.size()); }