[mlpack] 31/207: Fixed coding style in Range Search model classes and added my name to copyright.txt and core.hpp

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:38 UTC 2017


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch master
in repository mlpack.

commit 378bbc61543b24a301bc1a61692db946337ffe46
Author: dinesh Raj <dinu.iota at gmail.com>
Date:   Fri Feb 10 11:06:48 2017 +0530

    Fixed coding style in Range Search model classes and added my name to copyright.txt and core.hpp
---
 COPYRIGHT.txt                                     |   1 +
 src/mlpack/core.hpp                               |   1 +
 src/mlpack/methods/range_search/rs_model.hpp      |  58 +++++-----
 src/mlpack/methods/range_search/rs_model_impl.hpp | 131 ++++++++++------------
 4 files changed, 91 insertions(+), 100 deletions(-)

diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt
index 859f300..b113bbd 100644
--- a/COPYRIGHT.txt
+++ b/COPYRIGHT.txt
@@ -67,6 +67,7 @@ Copyright:
   Copyright 2016, Mike Izbicki <mike at izbicki.me>
   Copyright 2017, Sudhanshu Ranjan <sranjan.sud at gmail.com>
   Copyright 2017, Piyush Jaiswal <piyush.jaiswal at st.niituniversity.in>
+  Copyright 2017, Dinesh Raj <dinu.iota at gmail.com>
 License: BSD-3-clause
   All rights reserved.
   .
diff --git a/src/mlpack/core.hpp b/src/mlpack/core.hpp
index 1035aa9..4a9140a 100644
--- a/src/mlpack/core.hpp
+++ b/src/mlpack/core.hpp
@@ -207,6 +207,7 @@
  *   - Mike Izbicki <mike at izbicki.me>
  *   - Sudhanshu Ranjan <sranjan.sud at gmail.com>
  *   - Piyush Jaiswal <piyush.jaiswal at st.niituniversity.in>
+ *   - Dinesh Raj <dinu.iota at gmail.com>
  */
 
 // First, include all of the prerequisites.
diff --git a/src/mlpack/methods/range_search/rs_model.hpp b/src/mlpack/methods/range_search/rs_model.hpp
index 4544097..c6245f8 100644
--- a/src/mlpack/methods/range_search/rs_model.hpp
+++ b/src/mlpack/methods/range_search/rs_model.hpp
@@ -29,8 +29,8 @@ namespace range {
  * Alias template for Range Search.
  */
 template<template<typename TreeMetricType,
-                    typename TreeStatType,
-                    typename TreeMatType> class TreeType>
+                  typename TreeStatType,
+                  typename TreeMatType> class TreeType>
 using RSType = RangeSearch<metric::EuclideanDistance, arma::mat, TreeType>;
 
 
@@ -60,7 +60,7 @@ class MonoSearchVisitor : public  boost::static_visitor<void>
         range(range),
         neighbors(neighbors),
         distances(distances)
-      {};      
+    {};      
 
 };
 
@@ -93,7 +93,7 @@ class BiSearchVisitor : public boost::static_visitor<void>
   template<template<typename TreeMetricType,
                     typename TreeStatType,
                     typename TreeMatType> class TreeType>
- using RSTypeT = RSType<TreeType>;
+  using RSTypeT = RSType<TreeType>;
 
   //! Default Bichromatic range search on the given RSType instance.
   template<template<typename TreeMetricType,
@@ -115,8 +115,7 @@ class BiSearchVisitor : public boost::static_visitor<void>
                   const math::Range& range,
                   std::vector<std::vector<size_t>>& neighbors,
                   std::vector<std::vector<double>>& distances,
-                  const size_t leafSize
-                  );
+                  const size_t leafSize);
 };
 
 /**
@@ -159,13 +158,10 @@ class TrainVisitor : public boost::static_visitor<void>
   void operator()(RSTypeT<tree::Octree>* rs) const;
 
   //! Construct the TrainVisitor object with the given reference set, leafSize
-  //! for BinarySpaceTrees, and tau and rho for spill trees.
   TrainVisitor(arma::mat&& referenceSet,
-               const size_t leafSize
-               );
+               const size_t leafSize);
 };
 
-
 /**
  * ReferenceSetVisitor exposes the referenceSet of the given RSType.
  */
@@ -174,7 +170,7 @@ class ReferenceSetVisitor : public boost::static_visitor<const arma::mat&>
  public:
   //! Return the reference set.
   template<typename RSType>
-  const arma::mat& operator()(RSType *rs) const;
+  const arma::mat& operator()(RSType* rs) const;
 };
 
 /**
@@ -185,12 +181,12 @@ class DeleteVisitor : public boost::static_visitor<void>
  public:
   //! Delete the RSType object.
   template<typename RSType>
-  void operator()(RSType *rs) const;
+  void operator()(RSType* rs) const;
 };
 
 /**
-  * Exposes the seralize method of the given RSType
-  */
+ * Exposes the seralize method of the given RSType
+ */
 template<typename Archive>
  class SerializeVisitor : public boost::static_visitor<void>
  {
@@ -200,7 +196,7 @@ template<typename Archive>
  
   public:
     template<typename RSType>
-    void operator()(RSType *rs) const;
+    void operator()(RSType* rs) const;
  
     SerializeVisitor(Archive& ar, const std::string& name);
  };
@@ -212,7 +208,7 @@ template<typename Archive>
  {
   public:
     template<typename RSType>
-    bool& operator()(RSType *ns) const;
+    bool& operator()(RSType* rs) const;
  };
 
 /**
@@ -222,7 +218,7 @@ template<typename Archive>
  {
   public:
     template<typename RSType>
-    bool& operator()(RSType *ns) const;
+    bool& operator()(RSType* rs) const;
  };
 
 class RSModel
@@ -260,20 +256,20 @@ class RSModel
    * treeType. It is initialized every time BuildModel is executed.
    * We access to the contained value through the visitor classes defined above.
    */
-  boost::variant<RSType<tree::KDTree> *,
-                 RSType<tree::StandardCoverTree> *,
-                 RSType<tree::RTree> *,
-                 RSType<tree::RStarTree> *,
-                 RSType<tree::BallTree> *,
-                 RSType<tree::XTree> *,
-                 RSType<tree::HilbertRTree> *,
-                 RSType<tree::RPlusTree> *,
-                 RSType<tree::RPlusPlusTree> *,
-                 RSType<tree::VPTree> *,
-                 RSType<tree::RPTree> *,
-                 RSType<tree::MaxRPTree> *,
-                 RSType<tree::UBTree> *,
-                 RSType<tree::Octree> *> rSearch;
+  boost::variant<RSType<tree::KDTree>*,
+                 RSType<tree::StandardCoverTree>*,
+                 RSType<tree::RTree>*,
+                 RSType<tree::RStarTree>*,
+                 RSType<tree::BallTree>*,
+                 RSType<tree::XTree>*,
+                 RSType<tree::HilbertRTree>*,
+                 RSType<tree::RPlusTree>*,
+                 RSType<tree::RPlusPlusTree>*,
+                 RSType<tree::VPTree>*,
+                 RSType<tree::RPTree>*,
+                 RSType<tree::MaxRPTree>*,
+                 RSType<tree::UBTree>*,
+                 RSType<tree::Octree>*> rSearch;
                  
  public:
   /**
diff --git a/src/mlpack/methods/range_search/rs_model_impl.hpp b/src/mlpack/methods/range_search/rs_model_impl.hpp
index 351a96b..bfe6a5e 100644
--- a/src/mlpack/methods/range_search/rs_model_impl.hpp
+++ b/src/mlpack/methods/range_search/rs_model_impl.hpp
@@ -20,7 +20,7 @@ namespace range {
 
 //! Monochromatic range search on the given RSType instance.
 template<typename RSType>
-void MonoSearchVisitor::operator()(RSType *rs) const
+void MonoSearchVisitor::operator()(RSType* rs) const
 {
   if (rs)
     return rs->Search(range, neighbors, distances);
@@ -29,11 +29,10 @@ void MonoSearchVisitor::operator()(RSType *rs) const
 
 //! Save parameters for bichromatic range search.
 BiSearchVisitor::BiSearchVisitor(const arma::mat& querySet,
-                                                        const math::Range& range,
-                                                        std::vector<std::vector<size_t>>& neighbors,
-                                                        std::vector<std::vector<double>>& distances,
-                                                        const size_t leafSize
-                                                        ) :
+                                 const math::Range& range,
+                                 std::vector<std::vector<size_t>>& neighbors,
+                                 std::vector<std::vector<double>>& distances,
+                                 const size_t leafSize):
     querySet(querySet),
     range(range),
     neighbors(neighbors),
@@ -81,42 +80,38 @@ template<typename RSType>
 void BiSearchVisitor::SearchLeaf(RSType* rs) const
 {
    if (!rs->Naive() && !rs->SingleMode())
+   {
+      // Build a second tree and search.
+      Timer::Start("tree_building");
+      Log::Info << "Building query tree..." << std::endl;
+      std::vector<size_t> oldFromNewQueries;
+      typename RSType::Tree queryTree(std::move(querySet), oldFromNewQueries,
+          leafSize);
+      Log::Info << "Tree built." << std::endl;
+      Timer::Stop("tree_building");
+
+      std::vector<std::vector<size_t>> neighborsOut;
+      std::vector<std::vector<double>> distancesOut;
+      rs->Search(&queryTree, range, neighborsOut, distancesOut);
+
+      // Remap the query points.
+      neighbors.resize(queryTree.Dataset().n_cols);
+      distances.resize(queryTree.Dataset().n_cols);
+      for (size_t i = 0; i < queryTree.Dataset().n_cols; ++i)
       {
-        // // Build a second tree and search.
-        // Timer::Start("tree_building");
-        // Log::Info << "Building query tree..." << endl;
-        std::vector<size_t> oldFromNewQueries;
-        typename RSType::Tree queryTree(std::move(querySet), oldFromNewQueries,
-            leafSize);
-        // Log::Info << "Tree built." << endl;
-        // Timer::Stop("tree_building");
-
-        std::vector<std::vector<size_t>> neighborsOut;
-        std::vector<std::vector<double>> distancesOut;
-        rs->Search(&queryTree, range, neighborsOut, distancesOut);
-
-        // Remap the query points.
-        neighbors.resize(queryTree.Dataset().n_cols);
-        distances.resize(queryTree.Dataset().n_cols);
-        for (size_t i = 0; i < queryTree.Dataset().n_cols; ++i)
-        {
-          neighbors[oldFromNewQueries[i]] = neighborsOut[i];
-          distances[oldFromNewQueries[i]] = distancesOut[i];
-        }
-      }
-      else
-      {
-        // Search without building a second tree.
-        rs->Search(querySet, range, neighbors, distances);
+        neighbors[oldFromNewQueries[i]] = neighborsOut[i];
+        distances[oldFromNewQueries[i]] = distancesOut[i];
       }
+    }
+   else
+     rs->Search(querySet, range, neighbors, distances);
 }
 
 //! Save parameters for Train.
 TrainVisitor::TrainVisitor(arma::mat&& referenceSet,
-                                       const size_t leafSize
-                                       ) :
-      referenceSet(std::move(referenceSet)),
-      leafSize(leafSize)
+                           const size_t leafSize) :
+    referenceSet(std::move(referenceSet)),
+    leafSize(leafSize)
 {}
 
 //! Default Train on the given RSType instance.
@@ -159,22 +154,20 @@ template<typename RSType>
 void TrainVisitor::TrainLeaf(RSType* rs) const
 {
    if (rs->Naive())
-      {
-        rs->Train(std::move(referenceSet));
-      }
-      else
-      {
-       std::vector<size_t> oldFromNewReferences;
-       typename RSType::Tree* tree =
-                    new typename RSType::Tree(std::move(referenceSet),
-                    oldFromNewReferences, leafSize);
-       rs->Train(tree);
- 
-     // Give the model ownership of the tree and the mappings.
-     rs->treeOwner = true;
-     rs->oldFromNewReferences = std::move(oldFromNewReferences);
+      rs->Train(std::move(referenceSet));
+   else
+   {
+      std::vector<size_t> oldFromNewReferences;
+      typename RSType::Tree* tree =
+                  new typename RSType::Tree(std::move(referenceSet),
+                  oldFromNewReferences, leafSize);
+      rs->Train(tree);
+
+      // Give the model ownership of the tree and the mappings.
+      rs->treeOwner = true;
+      rs->oldFromNewReferences = std::move(oldFromNewReferences);
   }
-      }
+}
 
 
 //! Expose the referenceSet of the given RSType.
@@ -196,37 +189,37 @@ void DeleteVisitor::operator()(RSType* rs) const
 
 //! Save parameters for serializing
 template<typename Archive>
- SerializeVisitor<Archive>::SerializeVisitor(Archive& ar,
-                                             const std::string& name) :
-                            ar(ar),
-                            name(name)
- {}
+SerializeVisitor<Archive>::SerializeVisitor(Archive& ar,
+                                            const std::string& name) :
+    ar(ar),
+    name(name)
+{}
  
  //! Serializes the given RSType instance
  template<typename Archive>
  template<typename RSType>
- void SerializeVisitor<Archive>::operator()(RSType *rs) const
+ void SerializeVisitor<Archive>::operator()(RSType* rs) const
  {
    ar & data::CreateNVP(rs, name);
  }
 
 //! Return whether single mode enabled
 template<typename RSType>
- bool& SingleModeVisitor::operator()(RSType *rs) const
- {
-   if (rs)
-     return rs->SingleMode();
-   throw std::runtime_error("no range search model initialized");
- }
+bool& SingleModeVisitor::operator()(RSType* rs) const
+{
+ if (rs)
+   return rs->SingleMode();
+ throw std::runtime_error("no range search model initialized");
+}
 
 //! Exposes Naive() function of given RSType
 template<typename RSType>
- bool& NaiveVisitor::operator()(RSType *rs) const
- {
-   if (rs)
-     return rs->Naive();
-   throw std::runtime_error("no range search model initialized");
- }
+bool& NaiveVisitor::operator()(RSType* rs) const
+{
+ if (rs)
+   return rs->Naive();
+ throw std::runtime_error("no range search model initialized");
+}
  
 // Serialize the model.
 template<typename Archive>

-- 
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