[mlpack-git] master: Typedef to the rescue! Much easier to read now. (6f60dad)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:58:07 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 6f60dadce1bda932a1c5cbcdda062e9013234aeb
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Aug 17 04:52:51 2014 +0000

    Typedef to the rescue!  Much easier to read now.


>---------------------------------------------------------------

6f60dadce1bda932a1c5cbcdda062e9013234aeb
 .../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;



More information about the mlpack-git mailing list