From 3f4e6a84e9cc42749fee0441675e8eae738ba330 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Mon, 19 Oct 2015 16:01:48 -0400 Subject: [PATCH] Handle zero-size cover trees... sort of. --- .../core/tree/cover_tree/cover_tree_impl.hpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp b/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp index 93d146e1db..65a2d63c67 100644 --- a/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp +++ b/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp @@ -44,8 +44,9 @@ CoverTree::CoverTree( if (localMetric) this->metric = new MetricType(); - // If there is only one point in the dataset... uh, we're done. - if (dataset.n_cols == 1) + // If there is only one point or zero points in the dataset... uh, we're done. + // Technically, if the dataset has zero points, our node is not correct... + if (dataset.n_cols <= 1) return; // Kick off the building. Create the indices array and the distances array. @@ -128,8 +129,9 @@ CoverTree::CoverTree( metric(&metric), distanceComps(0) { - // If there is only one point in the dataset, uh, we're done. - if (dataset.n_cols == 1) + // If there is only one point or zero points in the dataset... uh, we're done. + // Technically, if the dataset has zero points, our node is not correct... + if (dataset.n_cols <= 1) return; // Kick off the building. Create the indices array and the distances array. @@ -214,8 +216,9 @@ CoverTree::CoverTree( // We need to create a metric. We'll just do it on the heap. this->metric = new MetricType(); - // If there is only one point in the dataset... uh, we're done. - if (dataset->n_cols == 1) + // If there is only one point or zero points in the dataset... uh, we're done. + // Technically, if the dataset has zero points, our node is not correct... + if (dataset->n_cols <= 1) return; // Kick off the building. Create the indices array and the distances array. @@ -298,8 +301,9 @@ CoverTree::CoverTree( metric(&metric), distanceComps(0) { - // If there is only one point in the dataset... uh, we're done. - if (dataset->n_cols == 1) + // If there is only one point or zero points in the dataset... uh, we're done. + // Technically, if the dataset has zero points, our node is not correct... + if (dataset->n_cols <= 1) return; // Kick off the building. Create the indices array and the distances array.