Opened 11 years ago
Closed 9 years ago
#6022 closed Bugs (fixed)
WeightType is misleading in boost::random::discrete_distribution
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | To Be Determined | Component: | random |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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
Change History (2)
comment:1 by , 11 years ago
comment:2 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I intended to support integer weight types, but it requires a separate implementation and I haven't gotten around to it yet.