[mlpack] 02/58: Typedef to the rescue! Much easier to read now.
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Tue Sep 9 13:19:38 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 553a0edeabb7390d865cb17033ec6bfbfa6e572e
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Sun Aug 17 04:52:51 2014 +0000
Typedef to the rescue! Much easier to read now.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17047 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../core/tree/rectangle_tree/r_tree_split.hpp | 52 ++++++++-----------
.../core/tree/rectangle_tree/r_tree_split_impl.hpp | 58 ++++++++++------------
2 files changed, 46 insertions(+), 64 deletions(-)
diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split.hpp
index 9750213..4b2baa2 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_tree_split.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split.hpp
@@ -24,67 +24,57 @@ template<typename DescentType,
class RTreeSplit
{
public:
+ // Convenience typedef to keep lines from being 1000 characters long.
+ typedef RectangleTree<RTreeSplit, DescentType, StatisticType, MatType>
+ TreeType;
+
/**
* Split a leaf node using the "default" algorithm. If necessary, this split
* will propagate upwards through the tree.
*/
- static void SplitLeafNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>,
- DescentType, StatisticType, MatType>* tree,
- std::vector<bool>& relevels);
+ static void SplitLeafNode(TreeType* tree,
+ std::vector<bool>& relevels);
/**
* Split a non-leaf node using the "default" algorithm. If this is a root
* node, the tree increases in depth.
*/
- static bool SplitNonLeafNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>,
- DescentType, StatisticType, MatType>* tree,
- std::vector<bool>& relevels);
+ static bool SplitNonLeafNode(TreeType* tree,
+ std::vector<bool>& relevels);
private:
/**
* Get the seeds for splitting a leaf node.
*/
- static void GetPointSeeds(
- const RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>& tree,
- int *i,
- int *j);
+ static void GetPointSeeds(const TreeType& tree, int* i, int* j);
/**
* Get the seeds for splitting a non-leaf node.
*/
- static void GetBoundSeeds(
- const RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>& tree,
- int *i,
- int *j);
+ static void GetBoundSeeds(const TreeType& tree, int* i, int* j);
/**
* Assign points to the two new nodes.
*/
- static void AssignPointDestNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* oldTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeOne,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeTwo,
- const int intI,
- const int intJ);
+ static void AssignPointDestNode(TreeType* oldTree,
+ TreeType* treeOne,
+ TreeType* treeTwo,
+ const int intI,
+ const int intJ);
/**
* Assign nodes to the two new nodes.
*/
- static void AssignNodeDestNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* oldTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType> *treeOne,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType> *treeTwo,
- const int intI,
- const int intJ);
+ static void AssignNodeDestNode(TreeType* oldTree,
+ TreeType* treeOne,
+ TreeType* treeTwo,
+ const int intI,
+ const int intJ);
/**
* Insert a node into another node.
*/
- static void InsertNodeIntoTree(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* destTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* srcNode);
+ static void InsertNodeIntoTree(TreeType* destTree, TreeType* srcNode);
};
}; // namespace tree
diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
index 03d43c4..1469fbe 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
@@ -24,7 +24,7 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* tree,
+ TreeType* tree,
std::vector<bool>& relevels)
{
// If we are splitting the root node, we need will do things differently so
@@ -33,15 +33,13 @@ void RTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
if (tree->Parent() == NULL)
{
// We actually want to copy this way. Pointers and everything.
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
- new RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(*tree, false);
+ TreeType* copy = new TreeType(*tree, false);
copy->Parent() = tree;
tree->Count() = 0;
tree->NullifyData();
// Because this was a leaf node, numChildren must be 0.
tree->Children()[(tree->NumChildren())++] = copy;
- RTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(copy,
- relevels);
+ SplitLeafNode(copy, relevels);
return;
}
@@ -54,16 +52,14 @@ void RTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
int j = 0;
GetPointSeeds(*tree, &i, &j);
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType> *treeOne = new
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(tree->Parent());
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType> *treeTwo = new
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(tree->Parent());
+ TreeType* treeOne = new TreeType(tree->Parent());
+ TreeType* treeTwo = new TreeType(tree->Parent());
// This will assign the ith and jth point appropriately.
AssignPointDestNode(tree, treeOne, treeTwo, i, j);
- //Remove this node and insert treeOne and treeTwo
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* par = tree->Parent();
+ // Remove this node and insert treeOne and treeTwo.
+ TreeType* par = tree->Parent();
int index = 0;
for (int i = 0; i < par->NumChildren(); i++)
{
@@ -102,22 +98,21 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
bool RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* tree,
- std::vector<bool>& relevels)
+ TreeType* tree,
+ std::vector<bool>& relevels)
{
// If we are splitting the root node, we need will do things differently so
// that the constructor and other methods don't confuse the end user by giving
// an address of another node.
if (tree->Parent() == NULL)
{
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
- new RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(*tree, false); // We actually want to copy this way. Pointers and everything.
-
+ // We actually want to copy this way. Pointers and everything.
+ TreeType* copy = new TreeType(*tree, false);
copy->Parent() = tree;
tree->NumChildren() = 0;
tree->NullifyData();
tree->Children()[(tree->NumChildren())++] = copy;
- RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(copy, relevels);
+ SplitNonLeafNode(copy, relevels);
return true;
}
@@ -127,16 +122,14 @@ bool RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
assert(i != j);
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeOne = new
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(tree->Parent());
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeTwo = new
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(tree->Parent());
+ TreeType* treeOne = new TreeType(tree->Parent());
+ TreeType* treeTwo = new TreeType(tree->Parent());
// This will assign the ith and jth rectangles appropriately.
AssignNodeDestNode(tree, treeOne, treeTwo, i, j);
- //Remove this node and insert treeOne and treeTwo
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* par = tree->Parent();
+ // Remove this node and insert treeOne and treeTwo.
+ TreeType* par = tree->Parent();
int index = -1;
for (int i = 0; i < par->NumChildren(); i++)
{
@@ -187,7 +180,7 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::GetPointSeeds(
- const RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>& tree,
+ const TreeType& tree,
int* iRet,
int* jRet)
{
@@ -231,7 +224,7 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::GetBoundSeeds(
- const RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>& tree,
+ const TreeType& tree,
int* iRet,
int* jRet)
{
@@ -268,9 +261,9 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::AssignPointDestNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* oldTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeOne,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeTwo,
+ TreeType* oldTree,
+ TreeType* treeOne,
+ TreeType* treeTwo,
const int intI,
const int intJ)
{
@@ -409,9 +402,9 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::AssignNodeDestNode(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* oldTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeOne,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* treeTwo,
+ TreeType* oldTree,
+ TreeType* treeOne,
+ TreeType* treeTwo,
const int intI,
const int intJ)
{
@@ -574,8 +567,7 @@ template<typename DescentType,
typename StatisticType,
typename MatType>
void RTreeSplit<DescentType, StatisticType, MatType>::InsertNodeIntoTree(
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* destTree,
- RectangleTree<RTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* srcNode)
+ TreeType* destTree, TreeType* srcNode)
{
destTree->Bound() |= srcNode->Bound();
destTree->Children()[destTree->NumChildren()++] = srcNode;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list