[mlpack-svn] r10846 - mlpack/trunk/src/mlpack/core/math

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Dec 16 01:57:49 EST 2011


Author: rcurtin
Date: 2011-12-16 01:57:49 -0500 (Fri, 16 Dec 2011)
New Revision: 10846

Added:
   mlpack/trunk/src/mlpack/core/math/range_impl.hpp
Removed:
   mlpack/trunk/src/mlpack/core/math/range.cpp
Modified:
   mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
   mlpack/trunk/src/mlpack/core/math/range.hpp
Log:
Inline math::Range.


Modified: mlpack/trunk/src/mlpack/core/math/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2011-12-16 06:39:35 UTC (rev 10845)
+++ mlpack/trunk/src/mlpack/core/math/CMakeLists.txt	2011-12-16 06:57:49 UTC (rev 10846)
@@ -7,7 +7,7 @@
   lin_alg.hpp
   random.hpp
   range.hpp
-  range.cpp
+  range_impl.hpp
 )
 
 # add directory name to sources

Deleted: mlpack/trunk/src/mlpack/core/math/range.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/math/range.cpp	2011-12-16 06:39:35 UTC (rev 10845)
+++ mlpack/trunk/src/mlpack/core/math/range.cpp	2011-12-16 06:57:49 UTC (rev 10846)
@@ -1,174 +0,0 @@
-/**
- * @file range.cpp
- *
- * Implementation of the Range class.
- */
-#include "range.hpp"
-#include <float.h>
-
-namespace mlpack {
-namespace math {
-
-/**
- * Initialize the range to 0.
- */
-Range::Range() :
-    lo(DBL_MAX), hi(-DBL_MAX) { /* nothing else to do */ }
-
-/**
- * Initialize a range to enclose only the given point.
- */
-Range::Range(const double point) :
-    lo(point), hi(point) { /* nothing else to do */ }
-
-/**
- * Initializes the range to the specified values.
- */
-Range::Range(const double lo, const double hi) :
-    lo(lo), hi(hi) { /* nothing else to do */ }
-
-/**
- * Gets the span of the range, hi - lo.  Returns 0 if the range is negative.
- */
-double Range::Width() const
-{
-  if (lo < hi)
-    return (hi - lo);
-  else
-    return 0.0;
-}
-
-/**
- * Gets the midpoint of this range.
- */
-double Range::Mid() const
-{
-  return (hi + lo) / 2;
-}
-
-/**
- * Expands range to include the other range.
- */
-Range& Range::operator|=(const Range& rhs)
-{
-  if (rhs.lo < lo)
-    lo = rhs.lo;
-  if (rhs.hi > hi)
-    hi = rhs.hi;
-
-  return *this;
-}
-
-Range Range::operator|(const Range& rhs) const
-{
-  return Range((rhs.lo < lo) ? rhs.lo : lo,
-               (rhs.hi > hi) ? rhs.hi : hi);
-}
-
-/**
- * Shrinks range to be the overlap with another range, becoming an empty
- * set if there is no overlap.
- */
-Range& Range::operator&=(const Range& rhs)
-{
-  if (rhs.lo > lo)
-    lo = rhs.lo;
-  if (rhs.hi < hi)
-    hi = rhs.hi;
-
-  return *this;
-}
-
-Range Range::operator&(const Range& rhs) const
-{
-  return Range((rhs.lo > lo) ? rhs.lo : lo,
-               (rhs.hi < hi) ? rhs.hi : hi);
-}
-
-/**
- * Scale the bounds by the given double.
- */
-Range& Range::operator*=(const double d)
-{
-  lo *= d;
-  hi *= d;
-
-  // Now if we've negated, we need to flip things around so the bound is valid.
-  if (lo > hi)
-  {
-    double tmp = hi;
-    hi = lo;
-    lo = tmp;
-  }
-
-  return *this;
-}
-
-Range Range::operator*(const double d) const
-{
-  double nlo = lo * d;
-  double nhi = hi * d;
-
-  if (nlo <= nhi)
-    return Range(nlo, nhi);
-  else
-    return Range(nhi, nlo);
-}
-
-// Symmetric case.
-Range operator*(const double d, const Range& r)
-{
-  double nlo = r.lo * d;
-  double nhi = r.hi * d;
-
-  if (nlo <= nhi)
-    return Range(nlo, nhi);
-  else
-    return Range(nhi, nlo);
-}
-
-/**
- * Compare with another range for strict equality.
- */
-bool Range::operator==(const Range& rhs) const
-{
-  return (lo == rhs.lo) && (hi == rhs.hi);
-}
-
-bool Range::operator!=(const Range& rhs) const
-{
-  return (lo != rhs.lo) || (hi != rhs.hi);
-}
-
-/**
- * Compare with another range.  For Range objects x and y, x < y means that x is
- * strictly less than y and does not overlap at all.
- */
-bool Range::operator<(const Range& rhs) const
-{
-  return hi < rhs.lo;
-}
-
-bool Range::operator>(const Range& rhs) const
-{
-  return lo > rhs.hi;
-}
-
-/**
- * Determines if a point is contained within the range.
- */
-bool Range::Contains(const double d) const
-{
-  return d >= lo && d <= hi;
-}
-
-/**
- * Determines if this range overlaps with another range.
- */
-bool Range::Contains(const Range& r) const
-{
-  return lo <= r.hi;
-}
-
-}; // namesapce math
-}; // namespace mlpack

Modified: mlpack/trunk/src/mlpack/core/math/range.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/math/range.hpp	2011-12-16 06:39:35 UTC (rev 10845)
+++ mlpack/trunk/src/mlpack/core/math/range.hpp	2011-12-16 06:57:49 UTC (rev 10846)
@@ -21,7 +21,7 @@
 
  public:
   /** Initialize to an empty set (where lo > hi). */
-  Range();
+  inline Range();
 
   /***
    * Initialize a range to enclose only the given point (lo = point, hi =
@@ -29,7 +29,7 @@
    *
    * @param point Point that this range will enclose.
    */
-  Range(const double point);
+  inline Range(const double point);
 
   /**
    * Initializes to specified range.
@@ -37,41 +37,41 @@
    * @param lo Lower bound of the range.
    * @param hi Upper bound of the range.
    */
-  Range(const double lo, const double hi);
+  inline Range(const double lo, const double hi);
 
   //! Get the lower bound.
-  const double& Lo() const { return lo; }
+  inline const double& Lo() const { return lo; }
   //! Modify the lower bound.
-  double& Lo() { return lo; }
+  inline double& Lo() { return lo; }
 
   //! Get the upper bound.
-  const double& Hi() const { return hi; }
+  inline const double& Hi() const { return hi; }
   //! Modify the upper bound.
-  double& Hi() { return hi; }
+  inline double& Hi() { return hi; }
 
   /**
    * Gets the span of the range (hi - lo).
    */
-  double Width() const;
+  inline double Width() const;
 
   /**
    * Gets the midpoint of this range.
    */
-  double Mid() const;
+  inline double Mid() const;
 
   /**
    * Expands this range to include another range.
    *
    * @param rhs Range to include.
    */
-  Range& operator|=(const Range& rhs);
+  inline Range& operator|=(const Range& rhs);
 
   /**
    * Expands this range to include another range.
    *
    * @param rhs Range to include.
    */
-  Range operator|(const Range& rhs) const;
+  inline Range operator|(const Range& rhs) const;
 
   /**
    * Shrinks this range to be the overlap with another range; this makes an
@@ -79,7 +79,7 @@
    *
    * @param rhs Other range.
    */
-  Range& operator&=(const Range& rhs);
+  inline Range& operator&=(const Range& rhs);
 
   /**
    * Shrinks this range to be the overlap with another range; this makes an
@@ -87,42 +87,42 @@
    *
    * @param rhs Other range.
    */
-  Range operator&(const Range& rhs) const;
+  inline Range operator&(const Range& rhs) const;
 
   /**
    * Scale the bounds by the given double.
    *
    * @param d Scaling factor.
    */
-  Range& operator*=(const double d);
+  inline Range& operator*=(const double d);
 
   /**
    * Scale the bounds by the given double.
    *
    * @param d Scaling factor.
    */
-  Range operator*(const double d) const;
+  inline Range operator*(const double d) const;
 
   /**
    * Scale the bounds by the given double.
    *
    * @param d Scaling factor.
    */
-  friend Range operator*(const double d, const Range& r); // Symmetric case.
+  friend inline Range operator*(const double d, const Range& r); // Symmetric.
 
   /**
    * Compare with another range for strict equality.
    *
    * @param rhs Other range.
    */
-  bool operator==(const Range& rhs) const;
+  inline bool operator==(const Range& rhs) const;
 
   /**
    * Compare with another range for strict equality.
    *
    * @param rhs Other range.
    */
-  bool operator!=(const Range& rhs) const;
+  inline bool operator!=(const Range& rhs) const;
 
   /**
    * Compare with another range.  For Range objects x and y, x < y means that x
@@ -130,7 +130,7 @@
    *
    * @param rhs Other range.
    */
-  bool operator<(const Range& rhs) const;
+  inline bool operator<(const Range& rhs) const;
 
   /**
    * Compare with another range.  For Range objects x and y, x < y means that x
@@ -138,14 +138,14 @@
    *
    * @param rhs Other range.
    */
-  bool operator>(const Range& rhs) const;
+  inline bool operator>(const Range& rhs) const;
 
   /**
    * Determines if a point is contained within the range.
    *
    * @param d Point to check.
    */
-  bool Contains(const double d) const;
+  inline bool Contains(const double d) const;
 
   /**
    * Determines if another range overlaps with this one.
@@ -154,11 +154,14 @@
    *
    * @return true if ranges overlap at all.
    */
-  bool Contains(const Range& r) const;
+  inline bool Contains(const Range& r) const;
 
 };
 
 }; // namespace math
 }; // namespace mlpack
 
+// Include inlined implementation.
+#include "range_impl.hpp"
+
 #endif // __MLPACK_CORE_MATH_RANGE_HPP

Copied: mlpack/trunk/src/mlpack/core/math/range_impl.hpp (from rev 10837, mlpack/trunk/src/mlpack/core/math/range.cpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/math/range_impl.hpp	                        (rev 0)
+++ mlpack/trunk/src/mlpack/core/math/range_impl.hpp	2011-12-16 06:57:49 UTC (rev 10846)
@@ -0,0 +1,179 @@
+/**
+ * @file range_impl.hpp
+ *
+ * Implementation of the (inlined) Range class.
+ */
+#ifndef __MLPACK_CORE_MATH_RANGE_IMPL_HPP
+#define __MLPACK_CORE_MATH_RANGE_IMPL_HPP
+
+#include "range.hpp"
+#include <float.h>
+
+namespace mlpack {
+namespace math {
+
+/**
+ * Initialize the range to 0.
+ */
+inline Range::Range() :
+    lo(DBL_MAX), hi(-DBL_MAX) { /* nothing else to do */ }
+
+/**
+ * Initialize a range to enclose only the given point.
+ */
+inline Range::Range(const double point) :
+    lo(point), hi(point) { /* nothing else to do */ }
+
+/**
+ * Initializes the range to the specified values.
+ */
+inline Range::Range(const double lo, const double hi) :
+    lo(lo), hi(hi) { /* nothing else to do */ }
+
+/**
+ * Gets the span of the range, hi - lo.  Returns 0 if the range is negative.
+ */
+inline double Range::Width() const
+{
+  if (lo < hi)
+    return (hi - lo);
+  else
+    return 0.0;
+}
+
+/**
+ * Gets the midpoint of this range.
+ */
+inline double Range::Mid() const
+{
+  return (hi + lo) / 2;
+}
+
+/**
+ * Expands range to include the other range.
+ */
+inline Range& Range::operator|=(const Range& rhs)
+{
+  if (rhs.lo < lo)
+    lo = rhs.lo;
+  if (rhs.hi > hi)
+    hi = rhs.hi;
+
+  return *this;
+}
+
+inline Range Range::operator|(const Range& rhs) const
+{
+  return Range((rhs.lo < lo) ? rhs.lo : lo,
+               (rhs.hi > hi) ? rhs.hi : hi);
+}
+
+/**
+ * Shrinks range to be the overlap with another range, becoming an empty
+ * set if there is no overlap.
+ */
+inline Range& Range::operator&=(const Range& rhs)
+{
+  if (rhs.lo > lo)
+    lo = rhs.lo;
+  if (rhs.hi < hi)
+    hi = rhs.hi;
+
+  return *this;
+}
+
+inline Range Range::operator&(const Range& rhs) const
+{
+  return Range((rhs.lo > lo) ? rhs.lo : lo,
+               (rhs.hi < hi) ? rhs.hi : hi);
+}
+
+/**
+ * Scale the bounds by the given double.
+ */
+inline Range& Range::operator*=(const double d)
+{
+  lo *= d;
+  hi *= d;
+
+  // Now if we've negated, we need to flip things around so the bound is valid.
+  if (lo > hi)
+  {
+    double tmp = hi;
+    hi = lo;
+    lo = tmp;
+  }
+
+  return *this;
+}
+
+inline Range Range::operator*(const double d) const
+{
+  double nlo = lo * d;
+  double nhi = hi * d;
+
+  if (nlo <= nhi)
+    return Range(nlo, nhi);
+  else
+    return Range(nhi, nlo);
+}
+
+// Symmetric case.
+inline Range operator*(const double d, const Range& r)
+{
+  double nlo = r.lo * d;
+  double nhi = r.hi * d;
+
+  if (nlo <= nhi)
+    return Range(nlo, nhi);
+  else
+    return Range(nhi, nlo);
+}
+
+/**
+ * Compare with another range for strict equality.
+ */
+inline bool Range::operator==(const Range& rhs) const
+{
+  return (lo == rhs.lo) && (hi == rhs.hi);
+}
+
+inline bool Range::operator!=(const Range& rhs) const
+{
+  return (lo != rhs.lo) || (hi != rhs.hi);
+}
+
+/**
+ * Compare with another range.  For Range objects x and y, x < y means that x is
+ * strictly less than y and does not overlap at all.
+ */
+inline bool Range::operator<(const Range& rhs) const
+{
+  return hi < rhs.lo;
+}
+
+inline bool Range::operator>(const Range& rhs) const
+{
+  return lo > rhs.hi;
+}
+
+/**
+ * Determines if a point is contained within the range.
+ */
+inline bool Range::Contains(const double d) const
+{
+  return d >= lo && d <= hi;
+}
+
+/**
+ * Determines if this range overlaps with another range.
+ */
+inline bool Range::Contains(const Range& r) const
+{
+  return lo <= r.hi;
+}
+
+}; // namesapce math
+}; // namespace mlpack
+
+#endif




More information about the mlpack-svn mailing list