[mlpack-svn] r16367 - mlpack/trunk/src/mlpack/tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Mar 11 14:53:35 EDT 2014


Author: rcurtin
Date: Tue Mar 11 14:53:34 2014
New Revision: 16367

Log:
Through the magic of regular expressions, I've refactored this test to use
kd-trees with one-point leaves.


Modified:
   mlpack/trunk/src/mlpack/tests/allkfn_test.cpp

Modified: mlpack/trunk/src/mlpack/tests/allkfn_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/allkfn_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/allkfn_test.cpp	Tue Mar 11 14:53:34 2014
@@ -10,6 +10,8 @@
 
 using namespace mlpack;
 using namespace mlpack::neighbor;
+using namespace mlpack::tree;
+using namespace mlpack::bound;
 
 BOOST_AUTO_TEST_SUITE(AllkFNTest);
 
@@ -37,19 +39,26 @@
   data[9] = 0.90;
   data[10] = 1.00;
 
+  typedef BinarySpaceTree<HRectBound<2>,
+      NeighborSearchStat<FurthestNeighborSort> > TreeType;
+
   // We will loop through three times, one for each method of performing the
   // calculation.  We'll always use 10 neighbors, so set that parameter.
+  arma::mat dataMutable = data;
+  std::vector<size_t> oldFromNew;
+  std::vector<size_t> newFromOld;
+  TreeType* tree = new TreeType(dataMutable, oldFromNew, newFromOld, 1);
   for (int i = 0; i < 3; i++)
   {
     AllkFN* allkfn;
-    arma::mat dataMutable = data;
+
     switch (i)
     {
       case 0: // Use the dual-tree method.
-        allkfn = new AllkFN(dataMutable, false, false);
+        allkfn = new AllkFN(tree, dataMutable, false);
         break;
       case 1: // Use the single-tree method.
-        allkfn = new AllkFN(dataMutable, false, true);
+        allkfn = new AllkFN(tree, dataMutable, true);
         break;
       case 2: // Use the naive method.
         allkfn = new AllkFN(dataMutable, true);
@@ -67,250 +76,253 @@
     // readability.
 
     // Neighbors of point 0.
-    BOOST_REQUIRE(neighbors(9, 0) == 2);
-    BOOST_REQUIRE_CLOSE(distances(9, 0), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 0) == 5);
-    BOOST_REQUIRE_CLOSE(distances(8, 0), 0.27, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 0) == 1);
-    BOOST_REQUIRE_CLOSE(distances(7, 0), 0.30, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 0) == 8);
-    BOOST_REQUIRE_CLOSE(distances(6, 0), 0.40, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 0) == 9);
-    BOOST_REQUIRE_CLOSE(distances(5, 0), 0.85, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 0) == 10);
-    BOOST_REQUIRE_CLOSE(distances(4, 0), 0.95, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 0) == 3);
-    BOOST_REQUIRE_CLOSE(distances(3, 0), 1.20, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 0) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 0), 1.35, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 0) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 0), 2.05, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 0) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 0), 5.00, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[0]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[0]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[0]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[0]), 0.27, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[0]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[0]), 0.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[0]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[0]), 0.40, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[0]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[0]), 0.85, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[0]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[0]), 0.95, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[0]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[0]), 1.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[0]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[0]), 1.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[0]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[0]), 2.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[0]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[0]), 5.00, 1e-5);
 
     // Neighbors of point 1.
-    BOOST_REQUIRE(neighbors(9, 1) == 8);
-    BOOST_REQUIRE_CLOSE(distances(9, 1), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 1) == 2);
-    BOOST_REQUIRE_CLOSE(distances(8, 1), 0.20, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 1) == 0);
-    BOOST_REQUIRE_CLOSE(distances(7, 1), 0.30, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 1) == 9);
-    BOOST_REQUIRE_CLOSE(distances(6, 1), 0.55, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 1) == 5);
-    BOOST_REQUIRE_CLOSE(distances(5, 1), 0.57, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 1) == 10);
-    BOOST_REQUIRE_CLOSE(distances(4, 1), 0.65, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 1) == 3);
-    BOOST_REQUIRE_CLOSE(distances(3, 1), 0.90, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 1) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 1), 1.65, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 1) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 1), 2.35, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 1) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 1), 4.70, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[1]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[1]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[1]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[1]), 0.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[1]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[1]), 0.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[1]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[1]), 0.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[1]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[1]), 0.57, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[1]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[1]), 0.65, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[1]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[1]), 0.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[1]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[1]), 1.65, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[1]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[1]), 2.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[1]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[1]), 4.70, 1e-5);
 
     // Neighbors of point 2.
-    BOOST_REQUIRE(neighbors(9, 2) == 0);
-    BOOST_REQUIRE_CLOSE(distances(9, 2), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 2) == 1);
-    BOOST_REQUIRE_CLOSE(distances(8, 2), 0.20, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 2) == 8);
-    BOOST_REQUIRE_CLOSE(distances(7, 2), 0.30, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 2) == 5);
-    BOOST_REQUIRE_CLOSE(distances(6, 2), 0.37, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 2) == 9);
-    BOOST_REQUIRE_CLOSE(distances(5, 2), 0.75, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 2) == 10);
-    BOOST_REQUIRE_CLOSE(distances(4, 2), 0.85, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 2) == 3);
-    BOOST_REQUIRE_CLOSE(distances(3, 2), 1.10, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 2) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 2), 1.45, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 2) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 2), 2.15, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 2) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 2), 4.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[2]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[2]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[2]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[2]), 0.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[2]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[2]), 0.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[2]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[2]), 0.37, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[2]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[2]), 0.75, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[2]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[2]), 0.85, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[2]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[2]), 1.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[2]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[2]), 1.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[2]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[2]), 2.15, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[2]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[2]), 4.90, 1e-5);
 
     // Neighbors of point 3.
-    BOOST_REQUIRE(neighbors(9, 3) == 10);
-    BOOST_REQUIRE_CLOSE(distances(9, 3), 0.25, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 3) == 9);
-    BOOST_REQUIRE_CLOSE(distances(8, 3), 0.35, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 3) == 8);
-    BOOST_REQUIRE_CLOSE(distances(7, 3), 0.80, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 3) == 1);
-    BOOST_REQUIRE_CLOSE(distances(6, 3), 0.90, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 3) == 2);
-    BOOST_REQUIRE_CLOSE(distances(5, 3), 1.10, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 3) == 0);
-    BOOST_REQUIRE_CLOSE(distances(4, 3), 1.20, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 3) == 5);
-    BOOST_REQUIRE_CLOSE(distances(3, 3), 1.47, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 3) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 3), 2.55, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 3) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 3), 3.25, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 3) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 3), 3.80, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[3]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[3]), 0.25, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[3]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[3]), 0.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[3]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[3]), 0.80, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[3]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[3]), 0.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[3]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[3]), 1.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[3]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[3]), 1.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[3]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[3]), 1.47, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[3]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[3]), 2.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[3]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[3]), 3.25, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[3]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[3]), 3.80, 1e-5);
 
     // Neighbors of point 4.
-    BOOST_REQUIRE(neighbors(9, 4) == 3);
-    BOOST_REQUIRE_CLOSE(distances(9, 4), 3.80, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 4) == 10);
-    BOOST_REQUIRE_CLOSE(distances(8, 4), 4.05, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 4) == 9);
-    BOOST_REQUIRE_CLOSE(distances(7, 4), 4.15, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 4) == 8);
-    BOOST_REQUIRE_CLOSE(distances(6, 4), 4.60, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 4) == 1);
-    BOOST_REQUIRE_CLOSE(distances(5, 4), 4.70, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 4) == 2);
-    BOOST_REQUIRE_CLOSE(distances(4, 4), 4.90, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 4) == 0);
-    BOOST_REQUIRE_CLOSE(distances(3, 4), 5.00, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 4) == 5);
-    BOOST_REQUIRE_CLOSE(distances(2, 4), 5.27, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 4) == 7);
-    BOOST_REQUIRE_CLOSE(distances(1, 4), 6.35, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 4) == 6);
-    BOOST_REQUIRE_CLOSE(distances(0, 4), 7.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[4]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[4]), 3.80, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[4]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[4]), 4.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[4]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[4]), 4.15, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[4]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[4]), 4.60, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[4]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[4]), 4.70, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[4]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[4]), 4.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[4]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[4]), 5.00, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[4]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[4]), 5.27, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[4]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[4]), 6.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[4]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[4]), 7.05, 1e-5);
 
     // Neighbors of point 5.
-    BOOST_REQUIRE(neighbors(9, 5) == 0);
-    BOOST_REQUIRE_CLOSE(distances(9, 5), 0.27, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 5) == 2);
-    BOOST_REQUIRE_CLOSE(distances(8, 5), 0.37, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 5) == 1);
-    BOOST_REQUIRE_CLOSE(distances(7, 5), 0.57, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 5) == 8);
-    BOOST_REQUIRE_CLOSE(distances(6, 5), 0.67, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 5) == 7);
-    BOOST_REQUIRE_CLOSE(distances(5, 5), 1.08, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 5) == 9);
-    BOOST_REQUIRE_CLOSE(distances(4, 5), 1.12, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 5) == 10);
-    BOOST_REQUIRE_CLOSE(distances(3, 5), 1.22, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 5) == 3);
-    BOOST_REQUIRE_CLOSE(distances(2, 5), 1.47, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 5) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 5), 1.78, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 5) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 5), 5.27, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[5]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[5]), 0.27, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[5]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[5]), 0.37, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[5]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[5]), 0.57, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[5]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[5]), 0.67, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[5]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[5]), 1.08, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[5]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[5]), 1.12, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[5]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[5]), 1.22, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[5]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[5]), 1.47, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[5]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[5]), 1.78, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[5]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[5]), 5.27, 1e-5);
 
     // Neighbors of point 6.
-    BOOST_REQUIRE(neighbors(9, 6) == 7);
-    BOOST_REQUIRE_CLOSE(distances(9, 6), 0.70, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 6) == 5);
-    BOOST_REQUIRE_CLOSE(distances(8, 6), 1.78, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 6) == 0);
-    BOOST_REQUIRE_CLOSE(distances(7, 6), 2.05, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 6) == 2);
-    BOOST_REQUIRE_CLOSE(distances(6, 6), 2.15, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 6) == 1);
-    BOOST_REQUIRE_CLOSE(distances(5, 6), 2.35, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 6) == 8);
-    BOOST_REQUIRE_CLOSE(distances(4, 6), 2.45, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 6) == 9);
-    BOOST_REQUIRE_CLOSE(distances(3, 6), 2.90, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 6) == 10);
-    BOOST_REQUIRE_CLOSE(distances(2, 6), 3.00, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 6) == 3);
-    BOOST_REQUIRE_CLOSE(distances(1, 6), 3.25, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 6) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 6), 7.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[6]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[6]), 0.70, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[6]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[6]), 1.78, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[6]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[6]), 2.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[6]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[6]), 2.15, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[6]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[6]), 2.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[6]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[6]), 2.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[6]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[6]), 2.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[6]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[6]), 3.00, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[6]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[6]), 3.25, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[6]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[6]), 7.05, 1e-5);
 
     // Neighbors of point 7.
-    BOOST_REQUIRE(neighbors(9, 7) == 6);
-    BOOST_REQUIRE_CLOSE(distances(9, 7), 0.70, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 7) == 5);
-    BOOST_REQUIRE_CLOSE(distances(8, 7), 1.08, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 7) == 0);
-    BOOST_REQUIRE_CLOSE(distances(7, 7), 1.35, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 7) == 2);
-    BOOST_REQUIRE_CLOSE(distances(6, 7), 1.45, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 7) == 1);
-    BOOST_REQUIRE_CLOSE(distances(5, 7), 1.65, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 7) == 8);
-    BOOST_REQUIRE_CLOSE(distances(4, 7), 1.75, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 7) == 9);
-    BOOST_REQUIRE_CLOSE(distances(3, 7), 2.20, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 7) == 10);
-    BOOST_REQUIRE_CLOSE(distances(2, 7), 2.30, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 7) == 3);
-    BOOST_REQUIRE_CLOSE(distances(1, 7), 2.55, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 7) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 7), 6.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[7]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[7]), 0.70, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[7]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[7]), 1.08, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[7]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[7]), 1.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[7]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[7]), 1.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[7]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[7]), 1.65, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[7]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[7]), 1.75, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[7]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[7]), 2.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[7]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[7]), 2.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[7]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[7]), 2.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[7]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[7]), 6.35, 1e-5);
 
     // Neighbors of point 8.
-    BOOST_REQUIRE(neighbors(9, 8) == 1);
-    BOOST_REQUIRE_CLOSE(distances(9, 8), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 8) == 2);
-    BOOST_REQUIRE_CLOSE(distances(8, 8), 0.30, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 8) == 0);
-    BOOST_REQUIRE_CLOSE(distances(7, 8), 0.40, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 8) == 9);
-    BOOST_REQUIRE_CLOSE(distances(6, 8), 0.45, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 8) == 10);
-    BOOST_REQUIRE_CLOSE(distances(5, 8), 0.55, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 8) == 5);
-    BOOST_REQUIRE_CLOSE(distances(4, 8), 0.67, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 8) == 3);
-    BOOST_REQUIRE_CLOSE(distances(3, 8), 0.80, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 8) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 8), 1.75, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 8) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 8), 2.45, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 8) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 8), 4.60, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[8]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[8]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[8]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[8]), 0.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[8]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[8]), 0.40, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[8]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[8]), 0.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[8]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[8]), 0.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[8]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[8]), 0.67, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[8]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[8]), 0.80, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[8]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[8]), 1.75, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[8]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[8]), 2.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[8]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[8]), 4.60, 1e-5);
 
     // Neighbors of point 9.
-    BOOST_REQUIRE(neighbors(9, 9) == 10);
-    BOOST_REQUIRE_CLOSE(distances(9, 9), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 9) == 3);
-    BOOST_REQUIRE_CLOSE(distances(8, 9), 0.35, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 9) == 8);
-    BOOST_REQUIRE_CLOSE(distances(7, 9), 0.45, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 9) == 1);
-    BOOST_REQUIRE_CLOSE(distances(6, 9), 0.55, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 9) == 2);
-    BOOST_REQUIRE_CLOSE(distances(5, 9), 0.75, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 9) == 0);
-    BOOST_REQUIRE_CLOSE(distances(4, 9), 0.85, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 9) == 5);
-    BOOST_REQUIRE_CLOSE(distances(3, 9), 1.12, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 9) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 9), 2.20, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 9) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 9), 2.90, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 9) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 9), 4.15, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[9]), newFromOld[10]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[9]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[9]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[9]), 0.35, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[9]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[9]), 0.45, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[9]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[9]), 0.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[9]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[9]), 0.75, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[9]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[9]), 0.85, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[9]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[9]), 1.12, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[9]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[9]), 2.20, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[9]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[9]), 2.90, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[9]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[9]), 4.15, 1e-5);
 
     // Neighbors of point 10.
-    BOOST_REQUIRE(neighbors(9, 10) == 9);
-    BOOST_REQUIRE_CLOSE(distances(9, 10), 0.10, 1e-5);
-    BOOST_REQUIRE(neighbors(8, 10) == 3);
-    BOOST_REQUIRE_CLOSE(distances(8, 10), 0.25, 1e-5);
-    BOOST_REQUIRE(neighbors(7, 10) == 8);
-    BOOST_REQUIRE_CLOSE(distances(7, 10), 0.55, 1e-5);
-    BOOST_REQUIRE(neighbors(6, 10) == 1);
-    BOOST_REQUIRE_CLOSE(distances(6, 10), 0.65, 1e-5);
-    BOOST_REQUIRE(neighbors(5, 10) == 2);
-    BOOST_REQUIRE_CLOSE(distances(5, 10), 0.85, 1e-5);
-    BOOST_REQUIRE(neighbors(4, 10) == 0);
-    BOOST_REQUIRE_CLOSE(distances(4, 10), 0.95, 1e-5);
-    BOOST_REQUIRE(neighbors(3, 10) == 5);
-    BOOST_REQUIRE_CLOSE(distances(3, 10), 1.22, 1e-5);
-    BOOST_REQUIRE(neighbors(2, 10) == 7);
-    BOOST_REQUIRE_CLOSE(distances(2, 10), 2.30, 1e-5);
-    BOOST_REQUIRE(neighbors(1, 10) == 6);
-    BOOST_REQUIRE_CLOSE(distances(1, 10), 3.00, 1e-5);
-    BOOST_REQUIRE(neighbors(0, 10) == 4);
-    BOOST_REQUIRE_CLOSE(distances(0, 10), 4.05, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(9, newFromOld[10]), newFromOld[9]);
+    BOOST_REQUIRE_CLOSE(distances(9, newFromOld[10]), 0.10, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(8, newFromOld[10]), newFromOld[3]);
+    BOOST_REQUIRE_CLOSE(distances(8, newFromOld[10]), 0.25, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(7, newFromOld[10]), newFromOld[8]);
+    BOOST_REQUIRE_CLOSE(distances(7, newFromOld[10]), 0.55, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(6, newFromOld[10]), newFromOld[1]);
+    BOOST_REQUIRE_CLOSE(distances(6, newFromOld[10]), 0.65, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(5, newFromOld[10]), newFromOld[2]);
+    BOOST_REQUIRE_CLOSE(distances(5, newFromOld[10]), 0.85, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(4, newFromOld[10]), newFromOld[0]);
+    BOOST_REQUIRE_CLOSE(distances(4, newFromOld[10]), 0.95, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(3, newFromOld[10]), newFromOld[5]);
+    BOOST_REQUIRE_CLOSE(distances(3, newFromOld[10]), 1.22, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(2, newFromOld[10]), newFromOld[7]);
+    BOOST_REQUIRE_CLOSE(distances(2, newFromOld[10]), 2.30, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(1, newFromOld[10]), newFromOld[6]);
+    BOOST_REQUIRE_CLOSE(distances(1, newFromOld[10]), 3.00, 1e-5);
+    BOOST_REQUIRE_EQUAL(neighbors(0, newFromOld[10]), newFromOld[4]);
+    BOOST_REQUIRE_CLOSE(distances(0, newFromOld[10]), 4.05, 1e-5);
 
     // Clean the memory.
     delete allkfn;
   }
+
+  // We are responsible for the tree, too.
+  delete tree;
 }
 
 /**



More information about the mlpack-svn mailing list