[mlpack-svn] r13529 - mlpack/trunk/src/mlpack/core/metrics

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Sep 11 13:05:38 EDT 2012


Author: rcurtin
Date: 2012-09-11 13:05:38 -0400 (Tue, 11 Sep 2012)
New Revision: 13529

Modified:
   mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp
   mlpack/trunk/src/mlpack/core/metrics/lmetric_impl.hpp
Log:
Change template parameter names to be more in accordance with the rest of the
codebase.


Modified: mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp	2012-09-11 16:37:04 UTC (rev 13528)
+++ mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp	2012-09-11 17:05:38 UTC (rev 13529)
@@ -28,14 +28,14 @@
  * The value of p is given as a template parameter.
  *
  * In addition, the function @f$ d(x, y) @f$ can be simplified, neglecting the
- * p-root calculation.  This is done by specifying the t_take_root template
+ * p-root calculation.  This is done by specifying the TakeRoot template
  * parameter to be false.  Then,
  *
  * @f[
  * d(x, y) = \sum_{i = 1}^{n} | x_i - y_i |^p
  * @f]
  *
- * It is faster to compute that distance, so t_take_root is by default off.
+ * It is faster to compute that distance, so TakeRoot is by default off.
  *
  * A few convenience typedefs are given:
  *
@@ -43,14 +43,14 @@
  *  - EuclideanDistance
  *  - SquaredEuclideanDistance
  *
- * @tparam t_pow Power of metric; i.e. t_pow = 1 gives the L1-norm (Manhattan
- *   distance).
- * @tparam t_take_root If true, the t_pow'th root of the result is taken before
- *   it is returned.  In the case of the L2-norm (t_pow = 2), when t_take_root
- *   is true, the squared L2 distance is returned.  It is slightly faster to set
- *   t_take_root = false, because one fewer call to pow() is required.
+ * @tparam Power Power of metric; i.e. Power = 1 gives the L1-norm (Manhattan
+ *    distance).
+ * @tparam TakeRoot If true, the Power'th root of the result is taken before it
+ *    is returned.  In the case of the L2-norm (Power = 2), when TakeRoot is
+ *    true, the squared L2 distance is returned.  It is slightly faster to set
+ *    TakeRoot = false, because one fewer call to pow() is required.
  */
-template<int t_pow, bool t_take_root = false>
+template<int Power, bool TakeRoot = false>
 class LMetric
 {
  public:

Modified: mlpack/trunk/src/mlpack/core/metrics/lmetric_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/lmetric_impl.hpp	2012-09-11 16:37:04 UTC (rev 13528)
+++ mlpack/trunk/src/mlpack/core/metrics/lmetric_impl.hpp	2012-09-11 17:05:38 UTC (rev 13529)
@@ -14,19 +14,19 @@
 namespace metric {
 
 // Unspecialized implementation.  This should almost never be used...
-template<int t_pow, bool t_take_root>
+template<int Power, bool TakeRoot>
 template<typename VecType1, typename VecType2>
-double LMetric<t_pow, t_take_root>::Evaluate(const VecType1& a,
+double LMetric<Power, TakeRoot>::Evaluate(const VecType1& a,
                                              const VecType2& b)
 {
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
-    sum += pow(fabs(a[i] - b[i]), t_pow);
+    sum += pow(fabs(a[i] - b[i]), Power);
 
-  if (!t_take_root) // Suboptimal to have this here.
+  if (!TakeRoot) // The compiler should optimize this correctly at compile-time.
     return sum;
 
-  return pow(sum, (1.0 / t_pow));
+  return pow(sum, (1.0 / Power));
 }
 
 // L1-metric specializations; the root doesn't matter.




More information about the mlpack-svn mailing list