if (!centroids.remove(centroid, Constants.EPSILON)) { throw new RuntimeException("Unable to remove centroid");
if (!centroids.remove(centroid, Constants.EPSILON)) { throw new RuntimeException("Unable to remove centroid");
if (!centroids.remove(centroid, Constants.EPSILON)) { throw new RuntimeException("Unable to remove centroid");
searcher.remove(x.get(0), 1.0e-7); assertEquals(size0 - 1, searcher.size()); r.get(0).getValue().minus(r0.get(1).getValue()).norm (1), 1.0e-8); searcher.remove(x.get(1), 1.0e-7); assertEquals(size0 - 2, searcher.size()); try { List<Vector> x = Lists.newArrayList(Iterables.limit(searcher, 2)); searcher.remove(x.get(0), 1.0e-7); fail("Shouldn't be able to delete from " + searcher.getClass().getName()); } catch (UnsupportedOperationException e) {
@Test public void testRemove() { searcher.clear(); for (int i = 0; i < dataPoints.rowSize(); ++i) { Vector datapoint = dataPoints.viewRow(i); searcher.add(datapoint); // As long as points are not searched for right after being added, in FastProjectionSearch, points are not // merged with the main list right away, so if a search for a point occurs before it's merged the pendingAdditions // list also needs to be looked at. // This used to not be the case for searchFirst(), thereby causing removal failures. if (i % 2 == 0) { assertTrue("Failed to find self [search]", searcher.search(datapoint, 1).get(0).getWeight() < Constants.EPSILON); assertTrue("Failed to find self [searchFirst]", searcher.searchFirst(datapoint, false).getWeight() < Constants.EPSILON); assertTrue("Failed to remove self", searcher.remove(datapoint, Constants.EPSILON)); } } } }