[mlpack-git] master, mlpack-1.0.x: Refactor MinDistance(), MaxDistance(), and RangeDistance() to accept arbitrary types of Armadillo vectors using IsVector<>. (965d9e2)

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


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

On branches: master,mlpack-1.0.x
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 965d9e2638650dd6c48e91898f9c775ad78755ce
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Feb 20 00:29:00 2014 +0000

    Refactor MinDistance(), MaxDistance(), and RangeDistance() to accept arbitrary
    types of Armadillo vectors using IsVector<>.


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

965d9e2638650dd6c48e91898f9c775ad78755ce
 src/mlpack/core/tree/ballbound.hpp       | 17 +++++++++++++----
 src/mlpack/core/tree/ballbound_impl.hpp  | 16 ++++++++++++----
 src/mlpack/core/tree/hrectbound.hpp      | 10 +++++++---
 src/mlpack/core/tree/hrectbound_impl.hpp | 13 +++++++++----
 4 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/src/mlpack/core/tree/ballbound.hpp b/src/mlpack/core/tree/ballbound.hpp
index 581b37a..ac579d0 100644
--- a/src/mlpack/core/tree/ballbound.hpp
+++ b/src/mlpack/core/tree/ballbound.hpp
@@ -17,7 +17,7 @@ namespace bound {
 /**
  * Ball bound that works in the regular Euclidean metric space.
  *
- * @tparam VecType Type of vector (arma::vec or arma::spvec).
+ * @tparam VecType Type of vector (arma::vec or arma::sp_vec).
  */
 template<typename VecType = arma::vec>
 class BallBound
@@ -78,7 +78,10 @@ class BallBound
   /**
    * Calculates minimum bound-to-point squared distance.
    */
-  double MinDistance(const VecType& point) const;
+  template<typename OtherVecType>
+  double MinDistance(const OtherVecType& point,
+                     typename boost::enable_if<IsVector<OtherVecType> >* = 0)
+      const;
 
   /**
    * Calculates minimum bound-to-bound squared distance.
@@ -88,7 +91,10 @@ class BallBound
   /**
    * Computes maximum distance.
    */
-  double MaxDistance(const VecType& point) const;
+  template<typename OtherVecType>
+  double MaxDistance(const OtherVecType& point,
+                     typename boost::enable_if<IsVector<OtherVecType> >* = 0)
+      const;
 
   /**
    * Computes maximum distance.
@@ -98,7 +104,10 @@ class BallBound
   /**
    * Calculates minimum and maximum bound-to-point distance.
    */
-  math::Range RangeDistance(const VecType& other) const;
+  template<typename OtherVecType>
+  math::Range RangeDistance(
+      const OtherVecType& other,
+      typename boost::enable_if<IsVector<OtherVecType> >* = 0) const;
 
   /**
    * Calculates minimum and maximum bound-to-bound distance.
diff --git a/src/mlpack/core/tree/ballbound_impl.hpp b/src/mlpack/core/tree/ballbound_impl.hpp
index 649e094..57e3587 100644
--- a/src/mlpack/core/tree/ballbound_impl.hpp
+++ b/src/mlpack/core/tree/ballbound_impl.hpp
@@ -56,7 +56,10 @@ void BallBound<VecType>::CalculateMidpoint(VecType& centroid) const
  * Calculates minimum bound-to-point squared distance.
  */
 template<typename VecType>
-double BallBound<VecType>::MinDistance(const VecType& point) const
+template<typename OtherVecType>
+double BallBound<VecType>::MinDistance(
+    const OtherVecType& point,
+    typename boost::enable_if<IsVector<OtherVecType> >* /* junk */) const
 {
   if (radius < 0)
     return DBL_MAX;
@@ -85,7 +88,10 @@ double BallBound<VecType>::MinDistance(const BallBound& other) const
  * Computes maximum distance.
  */
 template<typename VecType>
-double BallBound<VecType>::MaxDistance(const VecType& point) const
+template<typename OtherVecType>
+double BallBound<VecType>::MaxDistance(
+    const OtherVecType& point,
+    typename boost::enable_if<IsVector<OtherVecType> >* /* junk */) const
 {
   if (radius < 0)
     return DBL_MAX;
@@ -112,8 +118,10 @@ double BallBound<VecType>::MaxDistance(const BallBound& other) const
  * Example: bound1.MinDistanceSq(other) for minimum squared distance.
  */
 template<typename VecType>
-math::Range BallBound<VecType>::RangeDistance(const VecType& point)
-    const
+template<typename OtherVecType>
+math::Range BallBound<VecType>::RangeDistance(
+    const OtherVecType& point,
+    typename boost::enable_if<IsVector<OtherVecType> >* /* junk */) const
 {
   if (radius < 0)
     return math::Range(DBL_MAX, DBL_MAX);
diff --git a/src/mlpack/core/tree/hrectbound.hpp b/src/mlpack/core/tree/hrectbound.hpp
index a51a6e4..cb69196 100644
--- a/src/mlpack/core/tree/hrectbound.hpp
+++ b/src/mlpack/core/tree/hrectbound.hpp
@@ -78,7 +78,8 @@ class HRectBound
    * @param point Point to which the minimum distance is requested.
    */
   template<typename VecType>
-  double MinDistance(const VecType& point) const;
+  double MinDistance(const VecType& point,
+                     typename boost::enable_if<IsVector<VecType> >* = 0) const;
 
   /**
    * Calculates minimum bound-to-bound distance.
@@ -93,7 +94,8 @@ class HRectBound
    * @param point Point to which the maximum distance is requested.
    */
   template<typename VecType>
-  double MaxDistance(const VecType& point) const;
+  double MaxDistance(const VecType& point,
+                     typename boost::enable_if<IsVector<VecType> >* = 0) const;
 
   /**
    * Computes maximum distance.
@@ -117,7 +119,9 @@ class HRectBound
    *     requested.
    */
   template<typename VecType>
-  math::Range RangeDistance(const VecType& point) const;
+  math::Range RangeDistance(const VecType& point,
+                            typename boost::enable_if<IsVector<VecType> >* = 0)
+      const;
 
   /**
    * Expands this region to include new points.
diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp
index bc9983a..9d3b3ad 100644
--- a/src/mlpack/core/tree/hrectbound_impl.hpp
+++ b/src/mlpack/core/tree/hrectbound_impl.hpp
@@ -114,7 +114,9 @@ void HRectBound<Power, TakeRoot>::Centroid(arma::vec& centroid) const
  */
 template<int Power, bool TakeRoot>
 template<typename VecType>
-double HRectBound<Power, TakeRoot>::MinDistance(const VecType& point) const
+double HRectBound<Power, TakeRoot>::MinDistance(
+    const VecType& point,
+    typename boost::enable_if<IsVector<VecType> >* /* junk */) const
 {
   Log::Assert(point.n_elem == dim);
 
@@ -181,7 +183,9 @@ double HRectBound<Power, TakeRoot>::MinDistance(const HRectBound& other) const
  */
 template<int Power, bool TakeRoot>
 template<typename VecType>
-double HRectBound<Power, TakeRoot>::MaxDistance(const VecType& point) const
+double HRectBound<Power, TakeRoot>::MaxDistance(
+    const VecType& point,
+    typename boost::enable_if<IsVector<VecType> >* /* junk */) const
 {
   double sum = 0;
 
@@ -271,8 +275,9 @@ math::Range HRectBound<Power, TakeRoot>::RangeDistance(const HRectBound& other)
  */
 template<int Power, bool TakeRoot>
 template<typename VecType>
-math::Range HRectBound<Power, TakeRoot>::RangeDistance(const VecType& point)
-    const
+math::Range HRectBound<Power, TakeRoot>::RangeDistance(
+    const VecType& point,
+    typename boost::enable_if<IsVector<VecType> >* /* junk */) const
 {
   double loSum = 0;
   double hiSum = 0;



More information about the mlpack-git mailing list