[mlpack-svn] r10797 - in mlpack/trunk/src/mlpack: . core/math core/tree tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Dec 14 13:17:27 EST 2011


Author: rcurtin
Date: 2011-12-14 13:17:27 -0500 (Wed, 14 Dec 2011)
New Revision: 10797

Added:
   mlpack/trunk/src/mlpack/core/math/clamp.hpp
   mlpack/trunk/src/mlpack/core/math/random.hpp
Removed:
   mlpack/trunk/src/mlpack/core/math/math_misc.hpp
Modified:
   mlpack/trunk/src/mlpack/core.hpp
   mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
   mlpack/trunk/src/mlpack/core/tree/bounds.hpp
   mlpack/trunk/src/mlpack/core/tree/dballbound.hpp
   mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
   mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
   mlpack/trunk/src/mlpack/tests/math_test.cpp
Log:
Split math_misc.hpp as per #143.


Modified: mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2011-12-14 18:17:27 UTC (rev 10797)
@@ -3,8 +3,9 @@
 # Define the files we need to compile
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
+  clamp.hpp
   lin_alg.hpp
-  math_misc.hpp
+  random.hpp
   range.hpp
   range.cpp
 )

Copied: mlpack/trunk/src/mlpack/core/math/clamp.hpp (from rev 10774, mlpack/trunk/src/mlpack/core/math/math_misc.hpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/math/clamp.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/math/clamp.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -0,0 +1,60 @@
+/**
+ * @file clamp.hpp
+ *
+ * Miscellaneous math clamping routines.
+ */
+#ifndef __MLPACK_CORE_MATH_CLAMP_HPP
+#define __MLPACK_CORE_MATH_CLAMP_HPP
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+namespace mlpack {
+namespace math /** Miscellaneous math routines. */ {
+
+/**
+ * Forces a number to be non-negative, turning negative numbers into zero.
+ * Avoids branching costs (this is a measurable improvement).
+ *
+ * @param d Double to clamp.
+ * @return 0 if d < 0, d otherwise.
+ */
+inline double ClampNonNegative(double d)
+{
+  return (d + fabs(d)) / 2;
+}
+
+/**
+ * Forces a number to be non-positive, turning positive numbers into zero.
+ * Avoids branching costs (this is a measurable improvement).
+ *
+ * @param d Double to clamp.
+ * @param 0 if d > 0, d otherwise.
+ */
+inline double ClampNonPositive(double d)
+{
+  return (d - fabs(d)) / 2;
+}
+
+/**
+ * Clamp a number between a particular range.
+ *
+ * @param value The number to clamp.
+ * @param range_min The first of the range.
+ * @param range_max The last of the range.
+ * @return max(range_min, min(range_max, d)).
+ */
+inline double ClampRange(double value, double range_min, double range_max)
+{
+  value -= range_max;
+  value = ClampNonPositive (value) + range_max;
+  value -= range_min;
+  value = ClampNonNegative (value) + range_min;
+  return value;
+}
+
+}; // namespace math
+}; // namespace mlpack
+
+#endif // __MLPACK_CORE_MATH_CLAMP_HPP

Deleted: mlpack/trunk/src/mlpack/core/math/math_misc.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/math/math_misc.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/math/math_misc.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -1,92 +0,0 @@
-/**
- * @file math_misc.hpp
- *
- * Miscellaneous math routines.
- */
-#ifndef __MLPACK_CORE_MATH_MATH_MISC_HPP
-#define __MLPACK_CORE_MATH_MATH_MISC_HPP
-
-#include <stdlib.h>
-#include <math.h>
-#include <float.h>
-
-namespace mlpack {
-namespace math /** Miscellaneous math routines. */ {
-
-/**
- * Forces a number to be non-negative, turning negative numbers into zero.
- * Avoids branching costs (this is a measurable improvement).
- *
- * @param d Double to clamp.
- * @return 0 if d < 0, d otherwise.
- */
-inline double ClampNonNegative(double d)
-{
-  return (d + fabs(d)) / 2;
-}
-
-/**
- * Forces a number to be non-positive, turning positive numbers into zero.
- * Avoids branching costs (this is a measurable improvement).
- *
- * @param d Double to clamp.
- * @param 0 if d > 0, d otherwise.
- */
-inline double ClampNonPositive(double d)
-{
-  return (d - fabs(d)) / 2;
-}
-
-/**
- * Clamp a number between a particular range.
- *
- * @param value The number to clamp.
- * @param range_min The first of the range.
- * @param range_max The last of the range.
- * @return max(range_min, min(range_max, d)).
- */
-inline double ClampRange(double value, double range_min, double range_max)
-{
-  value -= range_max;
-  value = ClampNonPositive (value) + range_max;
-  value -= range_min;
-  value = ClampNonNegative (value) + range_min;
-  return value;
-}
-
-/**
- * Generates a uniform random number between 0 and 1.
- */
-inline double Random()
-{
-  return rand() * (1.0 / RAND_MAX);
-}
-
-/**
- * Generates a uniform random number in the specified range.
- */
-inline double Random(double lo, double hi)
-{
-  return Random() * (hi - lo) + lo;
-}
-
-/**
- * Generates a uniform random integer.
- */
-inline int RandInt(int hi_exclusive)
-{
-  return rand() % hi_exclusive;
-}
-
-/**
- * Generates a uniform random integer.
- */
-inline int RandInt(int lo, int hi_exclusive)
-{
-  return (rand() % (hi_exclusive - lo)) + lo;
-}
-
-}; // namespace math
-}; // namespace mlpack
-
-#endif // __MLPACK_CORE_MATH_MATH_LIB_HPP

Copied: mlpack/trunk/src/mlpack/core/math/random.hpp (from rev 10774, mlpack/trunk/src/mlpack/core/math/math_misc.hpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/math/random.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/math/random.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -0,0 +1,51 @@
+/**
+ * @file random.hpp
+ *
+ * Miscellaneous math random-related routines.
+ */
+#ifndef __MLPACK_CORE_MATH_RANDOM_HPP
+#define __MLPACK_CORE_MATH_RANDOM_HPP
+
+#include <stdlib.h>
+#include <math.h>
+#include <float.h>
+
+namespace mlpack {
+namespace math /** Miscellaneous math routines. */ {
+
+/**
+ * Generates a uniform random number between 0 and 1.
+ */
+inline double Random()
+{
+  return rand() * (1.0 / RAND_MAX);
+}
+
+/**
+ * Generates a uniform random number in the specified range.
+ */
+inline double Random(double lo, double hi)
+{
+  return Random() * (hi - lo) + lo;
+}
+
+/**
+ * Generates a uniform random integer.
+ */
+inline int RandInt(int hi_exclusive)
+{
+  return rand() % hi_exclusive;
+}
+
+/**
+ * Generates a uniform random integer.
+ */
+inline int RandInt(int lo, int hi_exclusive)
+{
+  return (rand() % (hi_exclusive - lo)) + lo;
+}
+
+}; // namespace math
+}; // namespace mlpack
+
+#endif // __MLPACK_CORE_MATH_MATH_LIB_HPP

Modified: mlpack/trunk/src/mlpack/core/tree/bounds.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/bounds.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/tree/bounds.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -1,18 +1,12 @@
 /**
- * @file tree/bounds.h
+ * @file bounds.hpp
  *
  * Bounds that are useful for binary space partitioning trees.
- *
- * TODO: Come up with a better design so you can do plug-and-play distance
- * metrics.
- *
- * @experimental
  */
 
 #ifndef __MLPACK_CORE_TREE_BOUNDS_HPP
 #define __MLPACK_CORE_TREE_BOUNDS_HPP
 
-#include <mlpack/core/math/math_misc.hpp>
 #include <mlpack/core/math/range.hpp>
 #include <mlpack/core/metrics/lmetric.hpp>
 

Modified: mlpack/trunk/src/mlpack/core/tree/dballbound.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/dballbound.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/tree/dballbound.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -11,7 +11,6 @@
 #define __MLPACK_CORE_TREE_DBALLBOUND_HPP
 
 #include <mlpack/core.hpp>
-#include <mlpack/core/math/math_misc.hpp>
 #include <mlpack/core/metrics/lmetric.hpp>
 
 namespace mlpack {

Modified: mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/tree/hrectbound_impl.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -11,8 +11,6 @@
 
 #include <math.h>
 
-#include "../math/math_misc.hpp"
-
 // In case it has not been included yet.
 #include "hrectbound.hpp"
 

Modified: mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -12,8 +12,6 @@
 
 #include <math.h>
 
-#include "../math/math_misc.hpp"
-
 namespace mlpack {
 namespace bound {
 

Modified: mlpack/trunk/src/mlpack/core.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core.hpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/core.hpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -92,7 +92,8 @@
 #include <mlpack/core/util/cli.hpp>
 #include <mlpack/core/data/load.hpp>
 #include <mlpack/core/data/save.hpp>
-#include <mlpack/core/math/math_misc.hpp>
+#include <mlpack/core/math/clamp.hpp>
+#include <mlpack/core/math/random.hpp>
 #include <mlpack/core/math/range.hpp>
 #include <mlpack/core/util/save_restore_utility.hpp>
 

Modified: mlpack/trunk/src/mlpack/tests/math_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/math_test.cpp	2011-12-14 18:04:46 UTC (rev 10796)
+++ mlpack/trunk/src/mlpack/tests/math_test.cpp	2011-12-14 18:17:27 UTC (rev 10797)
@@ -4,8 +4,9 @@
  *
  * Tests for everything in the math:: namespace.
  */
+#include <mlpack/core/math/clamp.hpp>
+#include <mlpack/core/math/random.hpp>
 #include <mlpack/core/math/range.hpp>
-#include <mlpack/core/math/math_misc.hpp>
 #include <boost/test/unit_test.hpp>
 
 using namespace mlpack;




More information about the mlpack-svn mailing list