src/mlpack/tests/knn_test.cpp
BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest)
{
  arma::mat dataset = arma::randu<arma::mat>(5, 100);

  // Build the tree ourselves.
  std::vector<size_t> oldFromNewReferences;
  KNN::Tree tree(dataset);
  KNN knn(std::move(tree));

  // Now make a query set.
  arma::mat queryset = arma::randu<arma::mat>(5, 50);
  arma::mat distances;
  arma::Mat<size_t> neighbors;
  knn.Search(queryset, 3, neighbors, distances);

  // These will (hopefully) fail is either the neighbors or the distances matrix
  // has been accidentally deleted.
  BOOST_REQUIRE_EQUAL(neighbors.n_cols, 50);
  BOOST_REQUIRE_EQUAL(neighbors.n_rows, 3);
  BOOST_REQUIRE_EQUAL(distances.n_cols, 50);
  BOOST_REQUIRE_EQUAL(distances.n_rows, 3);
}
/**
 * Make sure that the neighborPtr matrix isn't accidentally deleted.
 * See issue #478.
 */
Make sure that the neighborPtr matrix isn't accidentally deleted.
Make sure that the neighborPtr matrix isn ' t accidentally deleted .
BOOST_AUTO_TEST_CASE(NeighborPtrDeleteTest)
{
  arma::mat dataset = arma::randu<arma::mat>(5, 100);
  std::vector<size_t> oldFromNewReferences;
  KNN::Tree tree(dataset);
  KNN knn(std::move(tree));
  arma::mat queryset = arma::randu<arma::mat>(5, 50);
  arma::mat distances;
  arma::Mat<size_t> neighbors;
  knn.Search(queryset, 3, neighbors, distances);
  BOOST_REQUIRE_EQUAL(neighbors.n_cols, 50);
  BOOST_REQUIRE_EQUAL(neighbors.n_rows, 3);
  BOOST_REQUIRE_EQUAL(distances.n_cols, 50);
  BOOST_REQUIRE_EQUAL(distances.n_rows, 3);
}
BOOST_AUTO_TEST_CASE ( NeighborPtrDeleteTest ) { arma :: mat dataset = arma :: randu < arma :: mat > ( 5 , 100 ) ; std :: vector < size_t > oldFromNewReferences ; KNN :: Tree tree ( dataset ) ; KNN knn ( std :: move ( tree ) ) ; arma :: mat queryset = arma :: randu < arma :: mat > ( 5 , 50 ) ; arma :: mat distances ; arma :: Mat < size_t > neighbors ; knn . Search ( queryset , 3 , neighbors , distances ) ; BOOST_REQUIRE_EQUAL ( neighbors . n_cols , 50 ) ; BOOST_REQUIRE_EQUAL ( neighbors . n_rows , 3 ) ; BOOST_REQUIRE_EQUAL ( distances . n_cols , 50 ) ; BOOST_REQUIRE_EQUAL ( distances . n_rows , 3 ) ; }
Make sure that the neighborPtr matrix isn't accidentally deleted.
Make sure that the neighborPtr matrix isn ' t accidentally deleted .
// Build the tree ourselves. // Now make a query set. // These will (hopefully) fail is either the neighbors or the distances matrix // has been accidentally deleted.