[mlpack-git] master: Add rvalue reference constructor. (7ec97d0)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Mon Oct 19 16:04:36 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/09cd0d67f2fdae252a8ab85324e71dbb4dfe0010...fecf1194c123ced12d56e7daad761c7b9aaac262
>---------------------------------------------------------------
commit 7ec97d059f4de60cd3d7a1fa240a28ecaaa78fbc
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Oct 19 10:16:32 2015 -0400
Add rvalue reference constructor.
>---------------------------------------------------------------
7ec97d059f4de60cd3d7a1fa240a28ecaaa78fbc
.../core/tree/rectangle_tree/rectangle_tree.hpp | 21 ++++++++++++
.../tree/rectangle_tree/rectangle_tree_impl.hpp | 39 ++++++++++++++++++++++
src/mlpack/tests/rectangle_tree_test.cpp | 12 +++++++
3 files changed, 72 insertions(+)
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
index 2d60f39..77021cd 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree.hpp
@@ -145,6 +145,27 @@ class RectangleTree
const size_t firstDataIndex = 0);
/**
+ * Construct this as the root node of a rectangle tree type using the given
+ * dataset, and taking ownership of the given dataset.
+ *
+ * @param data Dataset from which to create the tree.
+ * @param maxLeafSize Maximum size of each leaf in the tree.
+ * @param minLeafSize Minimum size of each leaf in the tree.
+ * @param maxNumChildren The maximum number of child nodes a non-leaf node may
+ * have.
+ * @param minNumChildren The minimum number of child nodes a non-leaf node may
+ * have.
+ * @param firstDataIndex The index of the first data point. UNUSED UNLESS WE
+ * ADD SUPPORT FOR HAVING A "CENTERAL" DATA MATRIX.
+ */
+ RectangleTree(MatType&& data,
+ const size_t maxLeafSize = 20,
+ const size_t minLeafSize = 8,
+ const size_t maxNumChildren = 5,
+ const size_t minNumChildren = 2,
+ const size_t firstDataIndex = 0);
+
+ /**
* Construct this as an empty node with the specified parent. Copying the
* parameters (maxLeafSize, minLeafSize, maxNumChildren, minNumChildren,
* firstDataIndex) from the parent.
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
index cbf870e..f8650cb 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
@@ -62,6 +62,45 @@ template<typename MetricType,
typename SplitType,
typename DescentType>
RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType>::
+RectangleTree(MatType&& data,
+ const size_t maxLeafSize,
+ const size_t minLeafSize,
+ const size_t maxNumChildren,
+ const size_t minNumChildren,
+ const size_t firstDataIndex) :
+ maxNumChildren(maxNumChildren),
+ minNumChildren(minNumChildren),
+ numChildren(0),
+ children(maxNumChildren + 1), // Add one to make splitting the node simpler.
+ parent(NULL),
+ begin(0),
+ count(0),
+ maxLeafSize(maxLeafSize),
+ minLeafSize(minLeafSize),
+ bound(data.n_rows),
+ splitHistory(bound.Dim()),
+ parentDistance(0),
+ dataset(new MatType(std::move(data))),
+ ownsDataset(true),
+ points(maxLeafSize + 1), // Add one to make splitting the node simpler.
+ localDataset(new MatType(arma::zeros<MatType>(data.n_rows,
+ maxLeafSize + 1)))
+{
+ stat = StatisticType(*this);
+
+ // For now, just insert the points in order.
+ RectangleTree* root = this;
+
+ for (size_t i = firstDataIndex; i < data.n_cols; i++)
+ root->InsertPoint(i);
+}
+
+template<typename MetricType,
+ typename StatisticType,
+ typename MatType,
+ typename SplitType,
+ typename DescentType>
+RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType>::
RectangleTree(
RectangleTree<MetricType, StatisticType, MatType, SplitType, DescentType>*
parentNode) :
diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp
index 9f42c15..15f859e 100644
--- a/src/mlpack/tests/rectangle_tree_test.cpp
+++ b/src/mlpack/tests/rectangle_tree_test.cpp
@@ -823,4 +823,16 @@ BOOST_AUTO_TEST_CASE(RStarTreeSplitTest)
0.9, 1e-15);
}
+BOOST_AUTO_TEST_CASE(RectangleTreeMoveDatasetTest)
+{
+ arma::mat dataset = arma::randu<arma::mat>(3, 1000);
+ typedef RTree<EuclideanDistance, EmptyStatistic, arma::mat> TreeType;
+
+ TreeType tree(std::move(dataset));
+
+ BOOST_REQUIRE_EQUAL(dataset.n_elem, 0);
+ BOOST_REQUIRE_EQUAL(tree.Dataset().n_rows, 3);
+ BOOST_REQUIRE_EQUAL(tree.Dataset().n_cols, 1000);
+}
+
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list