Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using rvalue references to set a given reference tree in FastMKS and DualTreeBoruvka #799

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/mlpack/methods/fastmks/fastmks_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ template<typename KernelType,
typename TreeMatType> class TreeType>
void FastMKS<KernelType, MatType, TreeType>::Train(Tree* tree)
{
train(*tree);
Train(*tree);
}

template<typename KernelType,
Expand All @@ -232,9 +232,9 @@ void FastMKS<KernelType, MatType, TreeType>::Train(Tree& tree)
if (treeOwner && referenceTree)
delete referenceTree;

referenceTree = new Tree(tree);
referenceSet = &tree->Dataset();
metric = metric::IPMetric<KernelType>(tree->Metric().Kernel());
this->referenceTree = new Tree(tree);
this->referenceSet = &referenceTree->Dataset();
this->metric = metric::IPMetric<KernelType>(referenceTree->Metric().Kernel());
setOwner = false;
treeOwner = true;
}
Expand All @@ -253,14 +253,14 @@ void FastMKS<KernelType, MatType, TreeType>::Train(Tree&& tree)
if (setOwner)
delete this->referenceSet;

if (treeOwner && referenceTree)
delete referenceTree;
if (treeOwner && this->referenceTree)
delete this->referenceTree;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will delete the tree after it is moved!


this->referenceTree = new Tree(std::move(tree));
this->referenceSet = &this->referenceTree->Dataset();
this->metric = metric::IPMetric<KernelType>(tree.Metric().Kernel());
this->setOwner = false;
this->treeOwner = true;
this->referenceSet = &referenceTree->Dataset();
this->metric = metric::IPMetric<KernelType>(referenceTree->Metric().Kernel());
setOwner = false;
treeOwner = true;
}

template<typename KernelType,
Expand Down
2 changes: 1 addition & 1 deletion src/mlpack/methods/fastmks/fastmks_model_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void BuildFastMKSModel(FastMKS<KernelType>& f,
typename FastMKS<KernelType>::Tree tree(referenceData, metric, base);
Timer::Stop("tree_building");

f.Train(std::move(tree));
f.Train(tree);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use std::move(tree) here to avoid copying the entire tree---that will be a big speed improvement.

}
}

Expand Down