[mlpack-svn] r16316 - mlpack/trunk/src/mlpack/core/tree

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Feb 19 19:29:01 EST 2014


Author: rcurtin
Date: Wed Feb 19 19:29:00 2014
New Revision: 16316

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


Modified:
   mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
   mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
   mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
   mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp

Modified: mlpack/trunk/src/mlpack/core/tree/ballbound.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound.hpp	Wed Feb 19 19:29:00 2014
@@ -17,7 +17,7 @@
 /**
  * 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 @@
   /**
    * 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 @@
   /**
    * 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 @@
   /**
    * 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.

Modified: mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/ballbound_impl.hpp	Wed Feb 19 19:29:00 2014
@@ -56,7 +56,10 @@
  * 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 @@
  * 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 @@
  * 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);

Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound.hpp	Wed Feb 19 19:29:00 2014
@@ -78,7 +78,8 @@
    * @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 @@
    * @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 @@
    *     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.

Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	Wed Feb 19 19:29:00 2014
@@ -114,7 +114,9 @@
  */
 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 @@
  */
 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 @@
  */
 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-svn mailing list