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 
130  template<typename TT>
131  friend inline RangeType<TT> operator*(const TT d, const RangeType<TT>& r);
132 
138  inline bool operator==(const RangeType& rhs) const;
139 
145  inline bool operator!=(const RangeType& rhs) const;
146 
153  inline bool operator<(const RangeType& rhs) const;
154 
161  inline bool operator>(const RangeType& rhs) const;
162 
168  inline bool Contains(const T d) const;
169 
177  inline bool Contains(const RangeType& r) const;
178 
182  template<typename Archive>
183  void serialize(Archive& ar, const uint32_t version);
184 };
185 
186 } // namespace math
187 } // namespace mlpack
188 
189 // Include inlined implementation.
190 #include "range_impl.hpp"
191 
192 #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
Linear algebra utility functions, generally performed on matrices or vectors.
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).
void serialize(Archive &ar, const uint32_t version)
Serialize the range object.
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.
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