Add rvalue reference constructor.

This commit is contained in:
Ryan Curtin
2015-10-19 16:02:55 -04:00
parent 10d7140ef0
commit 7ec97d059f
3 changed files with 72 additions and 0 deletions
@@ -144,6 +144,27 @@ class RectangleTree
const size_t minNumChildren = 2,
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,
@@ -56,6 +56,45 @@ RectangleTree(const MatType& data,
root->InsertPoint(i);
}
template<typename MetricType,
typename StatisticType,
typename MatType,
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,
+12
View File
@@ -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();