Go to the documentation of this file.
15 #ifndef ABSL_RANDOM_DISCRETE_DISTRIBUTION_H_
16 #define ABSL_RANDOM_DISCRETE_DISTRIBUTION_H_
23 #include <type_traits>
27 #include "absl/random/bernoulli_distribution.h"
28 #include "absl/random/internal/iostream_state_saver.h"
29 #include "absl/random/uniform_int_distribution.h"
51 template <
typename IntType =
int>
62 template <
typename InputIterator>
72 template <
class UnaryOperation>
77 double delta = (xmax - xmin) /
static_cast<double>(nw);
79 double t = delta * 0.5;
80 for (
size_t i = 0;
i < nw; ++
i) {
81 p_.push_back(fw(xmin +
i * delta + t));
88 size_t n()
const {
return p_.size() - 1; }
91 return a.probabilities() ==
b.probabilities();
103 std::vector<double>
p_;
104 std::vector<std::pair<double, size_t>>
q_;
107 "Class-template absl::discrete_distribution<> must be "
108 "parameterized using an integral type.");
115 template <
typename InputIterator>
122 template <
class UnaryOperation>
130 template <
typename URBG>
135 template <
typename URBG>
137 const param_type&
p);
155 return a.param_ ==
b.param_;
159 return a.param_ !=
b.param_;
170 namespace random_internal {
178 std::vector<double>* probabilities);
182 template <
typename IntType>
186 q_.emplace_back(1.0, 0);
193 template <
typename IntType>
194 template <
typename URBG>
200 const auto& q = p.q_[
idx];
205 template <
typename CharT,
typename Traits,
typename IntType>
207 std::basic_ostream<CharT, Traits>& os,
215 os << os.fill() << p;
220 template <
typename CharT,
typename Traits,
typename IntType>
222 std::basic_istream<CharT, Traits>& is,
228 std::vector<double> p;
231 if (is.fail())
return is;
234 for (IntType
i = 0;
i <
n && !is.fail(); ++
i) {
235 auto tmp = random_internal::read_floating_point<double>(is);
236 if (is.fail())
return is;
240 x.param(param_type(p.begin(), p.end()));
247 #endif // ABSL_RANDOM_DISCRETE_DISTRIBUTION_H_
istream_state_saver< std::basic_istream< CharT, Traits > > make_istream_state_saver(std::basic_istream< CharT, Traits > &is, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::scientific|std::ios_base::skipws)
friend bool operator!=(const discrete_distribution &a, const discrete_distribution &b)
ABSL_NAMESPACE_BEGIN std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
discrete_distribution(InputIterator begin, InputIterator end)
const std::vector< double > & probabilities() const
discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw)
param_type(InputIterator begin, InputIterator end)
#define ABSL_NAMESPACE_END
std::vector< std::pair< double, size_t > > q_
result_type() min() const
#define ABSL_NAMESPACE_BEGIN
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
std::vector< std::pair< double, size_t > > InitDiscreteDistribution(std::vector< double > *probabilities)
param_type(std::initializer_list< double > weights)
param_type(size_t nw, double xmin, double xmax, UnaryOperation fw)
const param_type & param() const
friend bool operator==(const param_type &a, const param_type &b)
result_type operator()(URBG &g)
constexpr uint128 operator>>(uint128 lhs, int amount)
void param(const param_type &p)
discrete_distribution(std::initializer_list< double > weights)
result_type() max() const
discrete_distribution(const param_type &p)
friend bool operator!=(const param_type &a, const param_type &b)
friend bool operator==(const discrete_distribution &a, const discrete_distribution &b)
ostream_state_saver< std::basic_ostream< CharT, Traits > > make_ostream_state_saver(std::basic_ostream< CharT, Traits > &os, std::ios_base::fmtflags flags=std::ios_base::dec|std::ios_base::left|std::ios_base::scientific)
friend class discrete_distribution
const std::vector< double > & probabilities() const
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:16