[Boost-bugs] [Boost C++ Libraries] #6022: WeightType is misleading in boost::random::discrete_distribution

Subject: [Boost-bugs] [Boost C++ Libraries] #6022: WeightType is misleading in boost::random::discrete_distribution
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-10-13 18:11:24


#6022: WeightType is misleading in boost::random::discrete_distribution
----------------------------------------------------------+-----------------
 Reporter: Tim White <boost.10.wtwhite@…> | Owner: no-maintainer
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
  Version: Boost 1.47.0 | Severity: Problem
 Keywords: |
----------------------------------------------------------+-----------------
 The class template `boost::random::discrete_distribution` is parameterized
 by types `IntType` (defaulting to `int`) and `WeightType` (defaulting to
 `double`). Could you please update the documentation to clarify that
 `WeightType` must be a floating-point type? Alternatively, if the
 implementation could be changed to allow integer `WeightType`s that would
 be even better! (But I imagine that could be a lot of work.)

 A bit more background:

 The documentation doesn't give any constraints on `WeightType`, and in
 fact the documentation for one of the constructors gives as an example

 {{{
 discrete_distribution<> dist{1, 4, 5};
 }}}

 which indicates that weights don't have to sum to 1, and hints at the
 possibility of using an integer `WeightType` -- which would often be
 convenient and efficient. However, the following snippet fails
 compilation:

 {{{
 #include <boost/random.hpp>
 void f() {
     int w[] = {1, 4, 5};
     boost::random::discrete_distribution<int, int> dist(w, w + 3);
 }
 }}}

 Changing the `<int, int>` to `<int, double>` or just `<int>` enables
 compilation. (Also, looking at the Boost implementation, I see a call to
 an internal `normalize()` method that divides all weights by their sum, so
 it looks like support for integer `WeightType`s was never intended.)

 Thanks,
 Tim

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6022>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC