[mlpack-git] master: Doesn't copy the dataset in the copy constructor when it is not necessary. (8a5ec21)
gitdub at mlpack.org
gitdub at mlpack.org
Thu Aug 18 12:02:19 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/0f4b25acd6aaa14294c044874ba6cc0751712baa...0a19d07bd39e6223991976474bc79671ba8aa0f0
>---------------------------------------------------------------
commit 8a5ec211cb8d68e1364fe0e79a2871c66b1cd1b6
Author: MarcosPividori <marcos.pividori at gmail.com>
Date: Thu Aug 18 13:02:19 2016 -0300
Doesn't copy the dataset in the copy constructor when it is not necessary.
>---------------------------------------------------------------
8a5ec211cb8d68e1364fe0e79a2871c66b1cd1b6
src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp | 5 +++--
src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp | 10 ++++++----
2 files changed, 9 insertions(+), 6 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 7c6de7f..4279d62 100644
--- a/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
+++ b/src/mlpack/core/tree/cover_tree/cover_tree_impl.hpp
@@ -479,7 +479,8 @@ template<
>
CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
const CoverTree& other) :
- dataset((other.parent == NULL) ? new MatType(*other.dataset) : NULL),
+ dataset((other.parent == NULL && other.localDataset) ?
+ new MatType(*other.dataset) : other.dataset),
point(other.point),
scale(other.scale),
base(other.base),
@@ -489,7 +490,7 @@ CoverTree<MetricType, StatisticType, MatType, RootPointPolicy>::CoverTree(
parentDistance(other.parentDistance),
furthestDescendantDistance(other.furthestDescendantDistance),
localMetric(false),
- localDataset(other.parent == NULL),
+ localDataset(other.parent == NULL && other.localDataset),
metric(other.metric),
distanceComps(0)
{
diff --git a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp
index 29ef325..1776cff 100644
--- a/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp
+++ b/src/mlpack/core/tree/spill_tree/spill_tree_impl.hpp
@@ -140,9 +140,11 @@ SpillTree(const SpillTree& other) :
stat(other.stat),
parentDistance(other.parentDistance),
furthestDescendantDistance(other.furthestDescendantDistance),
- // Copy matrix, but only if we are the root.
- dataset((other.parent == NULL) ? new MatType(*other.dataset) : NULL),
- localDataset(other.parent == NULL)
+ // Copy matrix, but only if we are the root and the other tree has its own
+ // copy of the dataset.
+ dataset((other.parent == NULL && other.localDataset) ?
+ new MatType(*other.dataset) : other.dataset),
+ localDataset(other.parent == NULL && other.localDataset)
{
// Create left and right children (if any).
if (other.Left())
@@ -162,7 +164,7 @@ SpillTree(const SpillTree& other) :
pointsIndex = new arma::Col<size_t>(*other.pointsIndex);
// Propagate matrix, but only if we are the root.
- if (parent == NULL)
+ if (parent == NULL && localDataset)
{
std::queue<SpillTree*> queue;
if (left)
More information about the mlpack-git
mailing list