[mlpack-git] master: Replace HRectBound::Intersect() by operator&() (e75a087)

gitdub at mlpack.org gitdub at mlpack.org
Tue Jul 5 05:21:12 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/6147ed01bab6eadcd6a5e796e259a6afacae4662...e0fd69006b17a845f066ea4de1e205fc0922739d

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

commit e75a0879a12b6ddabc1046d2a0fabde080b69543
Author: Mikhail Lozhnikov <lozhnikovma at gmail.com>
Date:   Tue Jul 5 12:21:12 2016 +0300

    Replace HRectBound::Intersect() by operator&()


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

e75a0879a12b6ddabc1046d2a0fabde080b69543
 src/mlpack/core/tree/hrectbound.hpp      |  7 ++++++-
 src/mlpack/core/tree/hrectbound_impl.hpp | 26 +++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/mlpack/core/tree/hrectbound.hpp b/src/mlpack/core/tree/hrectbound.hpp
index 948174a..7a0823f 100644
--- a/src/mlpack/core/tree/hrectbound.hpp
+++ b/src/mlpack/core/tree/hrectbound.hpp
@@ -190,7 +190,12 @@ class HRectBound
   /**
    * Returns the intersection of this bound and another.
    */
-  HRectBound Intersect(const HRectBound& bound) const;
+  HRectBound operator&(const HRectBound& bound) const;
+
+  /**
+   * Intersects this bound with another.
+   */
+  HRectBound& operator&=(const HRectBound& bound);
 
   /**
    * Returns the volume of overlap of this bound and another.
diff --git a/src/mlpack/core/tree/hrectbound_impl.hpp b/src/mlpack/core/tree/hrectbound_impl.hpp
index 9b3ee1e..ccfa026 100644
--- a/src/mlpack/core/tree/hrectbound_impl.hpp
+++ b/src/mlpack/core/tree/hrectbound_impl.hpp
@@ -435,6 +435,9 @@ inline bool HRectBound<MetricType, ElemType>::Contains(const VecType& point) con
   return true;
 }
 
+/**
+ * Determines if this bound partially contains a bound.
+ */
 template<typename MetricType, typename ElemType>
 inline bool HRectBound<MetricType, ElemType>::Contains(
     const HRectBound& bound) const
@@ -451,9 +454,12 @@ inline bool HRectBound<MetricType, ElemType>::Contains(
   return true;
 }
 
+/**
+ * Returns the intersection of this bound and another.
+ */
 template<typename MetricType, typename ElemType>
 inline HRectBound<MetricType, ElemType> HRectBound<MetricType, ElemType>::
-Intersect(const HRectBound& bound) const
+operator&(const HRectBound& bound) const
 {
   HRectBound<MetricType, ElemType> result(dim);
 
@@ -465,6 +471,24 @@ Intersect(const HRectBound& bound) const
   return result;
 }
 
+/**
+ * Intersects this bound with another.
+ */
+template<typename MetricType, typename ElemType>
+inline HRectBound<MetricType, ElemType>& HRectBound<MetricType, ElemType>::
+operator&=(const HRectBound& bound)
+{
+  for (size_t k = 0; k < dim; k++)
+  {
+    bounds[k].Lo() = std::max(bounds[k].Lo(), bound.bounds[k].Lo());
+    bounds[k].Hi() = std::min(bounds[k].Hi(), bound.bounds[k].Hi());
+  }
+  return *this;
+}
+
+/**
+ * Returns the volume of overlap of this bound and another.
+ */
 template<typename MetricType, typename ElemType>
 inline ElemType HRectBound<MetricType, ElemType>::Overlap(
     const HRectBound& bound) const




More information about the mlpack-git mailing list