]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/histogram/axis/regular.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / histogram / axis / regular.hpp
index 319b2fe84c222b3bf34d76c9763b66b0b203c3c5..403931f8ff78379eae3cd0cc112fe45e7abbecc1 100644 (file)
@@ -165,15 +165,22 @@ step_type<T> step(T t) {
   return step_type<T>{t};
 }
 
-/**
-  Axis for equidistant intervals on the real line.
+/** Axis for equidistant intervals on the real line.
+
+   The most common binning strategy. Very fast. Binning is a O(1) operation.
+
+   If the axis has an overflow bin (the default), a value on the upper edge of the last
+   bin is put in the overflow bin. The axis range represents a semi-open interval.
 
-  The most common binning strategy. Very fast. Binning is a O(1) operation.
+   If the overflow bin is deactivated, then a value on the upper edge of the last bin is
+   still counted towards the last bin. The axis range represents a closed interval. This
+   is the desired behavior for random numbers drawn from a bounded interval, which is
+   usually closed.
 
-  @tparam Value input value type, must be floating point.
-  @tparam Transform builtin or user-defined transform type.
-  @tparam MetaData type to store meta data.
-  @tparam Options see boost::histogram::axis::option (all values allowed).
+   @tparam Value input value type, must be floating point.
+   @tparam Transform builtin or user-defined transform type.
+   @tparam MetaData type to store meta data.
+   @tparam Options see boost::histogram::axis::option.
  */
 template <class Value, class Transform, class MetaData, class Options>
 class regular : public iterator_mixin<regular<Value, Transform, MetaData, Options>>,
@@ -207,20 +214,22 @@ public:
   constexpr regular() = default;
 
   /** Construct n bins over real transformed range [start, stop).
-   *
-   * @param trans    transform instance to use.
-   * @param n        number of bins.
-   * @param start    low edge of first bin.
-   * @param stop     high edge of last bin.
-   * @param meta     description of the axis (optional).
+
+     @param trans    transform instance to use.
+     @param n        number of bins.
+     @param start    low edge of first bin.
+     @param stop     high edge of last bin.
+     @param meta     description of the axis (optional).
+     @param options  see boost::histogram::axis::option (optional).
    */
   regular(transform_type trans, unsigned n, value_type start, value_type stop,
-          metadata_type meta = {})
+          metadata_type meta = {}, options_type options = {})
       : transform_type(std::move(trans))
       , metadata_base(std::move(meta))
       , size_(static_cast<index_type>(n))
       , min_(this->forward(detail::get_scale(start)))
       , delta_(this->forward(detail::get_scale(stop)) - min_) {
+    (void)options;
     if (size() == 0) BOOST_THROW_EXCEPTION(std::invalid_argument("bins > 0 required"));
     if (!std::isfinite(min_) || !std::isfinite(delta_))
       BOOST_THROW_EXCEPTION(
@@ -230,51 +239,56 @@ public:
   }
 
   /** Construct n bins over real range [start, stop).
-   *
-   * @param n        number of bins.
-   * @param start    low edge of first bin.
-   * @param stop     high edge of last bin.
-   * @param meta     description of the axis (optional).
+
+     @param n        number of bins.
+     @param start    low edge of first bin.
+     @param stop     high edge of last bin.
+     @param meta     description of the axis (optional).
+     @param options  see boost::histogram::axis::option (optional).
    */
-  regular(unsigned n, value_type start, value_type stop, metadata_type meta = {})
-      : regular({}, n, start, stop, std::move(meta)) {}
+  regular(unsigned n, value_type start, value_type stop, metadata_type meta = {},
+          options_type options = {})
+      : regular({}, n, start, stop, std::move(meta), options) {}
 
   /** Construct bins with the given step size over real transformed range
-   * [start, stop).
-   *
-   * @param trans   transform instance to use.
-   * @param step    width of a single bin.
-   * @param start   low edge of first bin.
-   * @param stop    upper limit of high edge of last bin (see below).
-   * @param meta    description of the axis (optional).
-   *
-   * The axis computes the number of bins as n = abs(stop - start) / step,
-   * rounded down. This means that stop is an upper limit to the actual value
-   * (start + n * step).
+     [start, stop).
+
+     @param trans    transform instance to use.
+     @param step     width of a single bin.
+     @param start    low edge of first bin.
+     @param stop     upper limit of high edge of last bin (see below).
+     @param meta     description of the axis (optional).
+     @param options  see boost::histogram::axis::option (optional).
+
+     The axis computes the number of bins as n = abs(stop - start) / step,
+     rounded down. This means that stop is an upper limit to the actual value
+     (start + n * step).
    */
   template <class T>
   regular(transform_type trans, step_type<T> step, value_type start, value_type stop,
-          metadata_type meta = {})
+          metadata_type meta = {}, options_type options = {})
       : regular(trans, static_cast<index_type>(std::abs(stop - start) / step.value),
                 start,
                 start + static_cast<index_type>(std::abs(stop - start) / step.value) *
                             step.value,
-                std::move(meta)) {}
+                std::move(meta), options) {}
 
   /** Construct bins with the given step size over real range [start, stop).
-   *
-   * @param step    width of a single bin.
-   * @param start   low edge of first bin.
-   * @param stop    upper limit of high edge of last bin (see below).
-   * @param meta    description of the axis (optional).
-   *
-   * The axis computes the number of bins as n = abs(stop - start) / step,
-   * rounded down. This means that stop is an upper limit to the actual value
-   * (start + n * step).
+
+     @param step     width of a single bin.
+     @param start    low edge of first bin.
+     @param stop     upper limit of high edge of last bin (see below).
+     @param meta     description of the axis (optional).
+     @param options  see boost::histogram::axis::option (optional).
+
+     The axis computes the number of bins as n = abs(stop - start) / step,
+     rounded down. This means that stop is an upper limit to the actual value
+     (start + n * step).
    */
   template <class T>
-  regular(step_type<T> step, value_type start, value_type stop, metadata_type meta = {})
-      : regular({}, step, start, stop, std::move(meta)) {}
+  regular(step_type<T> step, value_type start, value_type stop, metadata_type meta = {},
+          options_type options = {})
+      : regular({}, step, start, stop, std::move(meta), options) {}
 
   /// Constructor used by algorithm::reduce to shrink and rebin (not for users).
   regular(const regular& src, index_type begin, index_type end, unsigned merge)
@@ -304,6 +318,8 @@ public:
         else
           return -1;
       }
+      // upper edge of last bin is inclusive if overflow bin is not present
+      if (!options_type::test(option::overflow) && z == 1) return size() - 1;
     }
     return size(); // also returned if x is NaN
   }
@@ -397,20 +413,28 @@ private:
 
 template <class T>
 regular(unsigned, T, T)
-    ->regular<detail::convert_integer<T, double>, transform::id, null_type>;
+    -> regular<detail::convert_integer<T, double>, transform::id, null_type>;
 
 template <class T, class M>
-regular(unsigned, T, T, M)
-    ->regular<detail::convert_integer<T, double>, transform::id,
-              detail::replace_cstring<std::decay_t<M>>>;
+regular(unsigned, T, T, M) -> regular<detail::convert_integer<T, double>, transform::id,
+                                      detail::replace_cstring<std::decay_t<M>>>;
+
+template <class T, class M, unsigned B>
+regular(unsigned, T, T, M, const option::bitset<B>&)
+    -> regular<detail::convert_integer<T, double>, transform::id,
+               detail::replace_cstring<std::decay_t<M>>, option::bitset<B>>;
 
 template <class Tr, class T, class = detail::requires_transform<Tr, T>>
-regular(Tr, unsigned, T, T)->regular<detail::convert_integer<T, double>, Tr, null_type>;
+regular(Tr, unsigned, T, T) -> regular<detail::convert_integer<T, double>, Tr, null_type>;
 
 template <class Tr, class T, class M>
-regular(Tr, unsigned, T, T, M)
-    ->regular<detail::convert_integer<T, double>, Tr,
-              detail::replace_cstring<std::decay_t<M>>>;
+regular(Tr, unsigned, T, T, M) -> regular<detail::convert_integer<T, double>, Tr,
+                                          detail::replace_cstring<std::decay_t<M>>>;
+
+template <class Tr, class T, class M, unsigned B>
+regular(Tr, unsigned, T, T, M, const option::bitset<B>&)
+    -> regular<detail::convert_integer<T, double>, Tr,
+               detail::replace_cstring<std::decay_t<M>>, option::bitset<B>>;
 
 #endif