range.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_MATH_RANGE_HPP
13 #define MLPACK_CORE_MATH_RANGE_HPP
14 
15 namespace mlpack {
16 namespace math {
17 
18 template<typename T>
19 class RangeType;
20 
22 typedef RangeType<double> Range;
23 
33 template<typename T = double>
34 class RangeType
35 {
36  private:
37  T lo;
38  T hi;
39 
40  public:
42  inline RangeType();
43 
44  /***
45  * Initialize a range to enclose only the given point (lo = point, hi =
46  * point).
47  *
48  * @param point Point that this range will enclose.
49  */
50  inline RangeType(const T point);
51 
58  inline RangeType(const T lo, const T hi);
59 
61  inline T Lo() const { return lo; }
63  inline T& Lo() { return lo; }
64 
66  inline T Hi() const { return hi; }
68  inline T& Hi() { return hi; }
69 
73  inline T Width() const;
74 
78  inline T Mid() const;
79 
85  inline RangeType& operator|=(const RangeType& rhs);
86 
92  inline RangeType operator|(const RangeType& rhs) const;
93 
100  inline RangeType& operator&=(const RangeType& rhs);
101 
108  inline RangeType operator&(const RangeType& rhs) const;
109 
115  inline RangeType& operator*=(const T d);
116 
122  inline RangeType operator*(const T d) const;
123 
129  template<typename TT>
130  friend inline RangeType<TT> operator*(const TT d, const RangeType<TT>& r);
131 
137  inline bool operator==(const RangeType& rhs) const;
138 
144  inline bool operator!=(const RangeType& rhs) const;
145 
152  inline bool operator<(const RangeType& rhs) const;
153 
160  inline bool operator>(const RangeType& rhs) const;
161 
167  inline bool Contains(const T d) const;
168 
176  inline bool Contains(const RangeType& r) const;
177 
181  template<typename Archive>
182  void serialize(Archive& ar, const unsigned int version);
183 };
184 
185 } // namespace math
186 } // namespace mlpack
187 
188 // Include inlined implementation.
189 #include "range_impl.hpp"
190 
191 #endif // MLPACK_CORE_MATH_RANGE_HPP
T Hi() const
Get the upper bound.
Definition: range.hpp:66
T & Lo()
Modify the lower bound.
Definition: range.hpp:63
.hpp
Definition: add_to_po.hpp:21
T Mid() const
Gets the midpoint of this range.
bool operator>(const RangeType &rhs) const
Compare with another range.
bool operator<(const RangeType &rhs) const
Compare with another range.
bool operator!=(const RangeType &rhs) const
Compare with another range for strict equality.
T Width() const
Gets the span of the range (hi - lo).
RangeType< double > Range
3.0.0 TODO: break reverse-compatibility by changing RangeType to Range.
Definition: range.hpp:19
T Lo() const
Get the lower bound.
Definition: range.hpp:61
Simple real-valued range.
Definition: range.hpp:19
bool operator==(const RangeType &rhs) const
Compare with another range for strict equality.
RangeType operator|(const RangeType &rhs) const
Expands this range to include another range.
void serialize(Archive &ar, const unsigned int version)
Serialize the range object.
RangeType & operator &=(const RangeType &rhs)
Shrinks this range to be the overlap with another range; this makes an empty set if there is no overl...
RangeType operator &(const RangeType &rhs) const
Shrinks this range to be the overlap with another range; this makes an empty set if there is no overl...
bool Contains(const T d) const
Determines if a point is contained within the range.
RangeType & operator|=(const RangeType &rhs)
Expands this range to include another range.
RangeType()
The upper bound.
RangeType operator*(const T d) const
Scale the bounds by the given double.
RangeType & operator*=(const T d)
Scale the bounds by the given double.
T & Hi()
Modify the upper bound.
Definition: range.hpp:68