mlpack  2.0.1
range.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_CORE_MATH_RANGE_HPP
15 #define __MLPACK_CORE_MATH_RANGE_HPP
16 
17 namespace mlpack {
18 namespace math {
19 
20 template<typename T>
21 class RangeType;
22 
24 typedef RangeType<double> Range;
25 
35 template<typename T = double>
36 class RangeType
37 {
38  private:
39  T lo;
40  T hi;
41 
42  public:
44  inline RangeType();
45 
46  /***
47  * Initialize a range to enclose only the given point (lo = point, hi =
48  * point).
49  *
50  * @param point Point that this range will enclose.
51  */
52  inline RangeType(const T point);
53 
60  inline RangeType(const T lo, const T hi);
61 
63  inline T Lo() const { return lo; }
65  inline T& Lo() { return lo; }
66 
68  inline T Hi() const { return hi; }
70  inline T& Hi() { return hi; }
71 
75  inline T Width() const;
76 
80  inline T Mid() const;
81 
87  inline RangeType& operator|=(const RangeType& rhs);
88 
94  inline RangeType operator|(const RangeType& rhs) const;
95 
102  inline RangeType& operator&=(const RangeType& rhs);
103 
110  inline RangeType operator&(const RangeType& rhs) const;
111 
117  inline RangeType& operator*=(const T d);
118 
124  inline RangeType operator*(const T d) const;
125 
131  template<typename TT>
132  friend inline RangeType<TT> operator*(const TT d, const RangeType<TT>& r);
133 
139  inline bool operator==(const RangeType& rhs) const;
140 
146  inline bool operator!=(const RangeType& rhs) const;
147 
154  inline bool operator<(const RangeType& rhs) const;
155 
162  inline bool operator>(const RangeType& rhs) const;
163 
169  inline bool Contains(const T d) const;
170 
178  inline bool Contains(const RangeType& r) const;
179 
183  template<typename Archive>
184  void Serialize(Archive& ar, const unsigned int version);
185 };
186 
187 } // namespace math
188 } // namespace mlpack
189 
190 // Include inlined implementation.
191 #include "range_impl.hpp"
192 
193 #endif // __MLPACK_CORE_MATH_RANGE_HPP
T Lo() const
Get the lower bound.
Definition: range.hpp:63
T hi
The lower bound.
Definition: range.hpp:40
RangeType operator*(const T d) const
Scale the bounds by the given double.
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...
Linear algebra utility functions, generally performed on matrices or vectors.
void Serialize(Archive &ar, const unsigned int version)
Serialize the range object.
RangeType operator|(const RangeType &rhs) const
Expands this range to include another range.
bool operator<(const RangeType &rhs) const
Compare with another range.
RangeType< double > Range
3.0.0 TODO: break reverse-compatibility by changing RangeType to Range.
Definition: range.hpp:21
bool operator!=(const RangeType &rhs) const
Compare with another range for strict equality.
Simple real-valued range.
Definition: range.hpp:21
RangeType & operator*=(const T d)
Scale the bounds by the given double.
T & Lo()
Modify the lower bound.
Definition: range.hpp:65
T Hi() const
Get the upper bound.
Definition: range.hpp:68
bool Contains(const T d) const
Determines if a point is contained within the range.
RangeType()
The upper bound.
bool operator>(const RangeType &rhs) const
Compare with another range.
RangeType & operator|=(const RangeType &rhs)
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...
T Width() const
Gets the span of the range (hi - lo).
bool operator==(const RangeType &rhs) const
Compare with another range for strict equality.
T & Hi()
Modify the upper bound.
Definition: range.hpp:70
T Mid() const
Gets the midpoint of this range.