Automatic Differentiation
 
Loading...
Searching...
No Matches
discrete_range_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_DISCRETE_RANGE_RNG_HPP
2#define STAN_MATH_PRIM_PROB_DISCRETE_RANGE_RNG_HPP
3
8#include <boost/random/uniform_int_distribution.hpp>
9#include <boost/random/variate_generator.hpp>
10
11namespace stan {
12namespace math {
13
34template <typename T_lower, typename T_upper, class RNG>
36discrete_range_rng(const T_lower& lower, const T_upper& upper, RNG& rng) {
37 static constexpr const char* function = "discrete_range_rng";
38 using boost::variate_generator;
39 using boost::random::uniform_int_distribution;
40 check_consistent_sizes(function, "Lower bound parameter", lower,
41 "Upper bound parameter", upper);
42 check_greater_or_equal(function, "Upper bound parameter", upper, lower);
43
44 scalar_seq_view<T_lower> lower_vec(lower);
45 scalar_seq_view<T_upper> upper_vec(upper);
46 size_t N = max_size(lower, upper);
48
49 for (size_t n = 0; n < N; ++n) {
50 variate_generator<RNG&, uniform_int_distribution<>> discrete_range_rng(
51 rng, uniform_int_distribution<>(lower_vec[n], upper_vec[n]));
52
53 output[n] = discrete_range_rng();
54 }
55
56 return output.data();
57}
58
59} // namespace math
60} // namespace stan
61#endif
typename helper::type type
VectorBuilder allocates type T1 values to be used as intermediate values.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
VectorBuilder< true, int, T_lower, T_upper >::type discrete_range_rng(const T_lower &lower, const T_upper &upper, RNG &rng)
Return an integer random variate between the given lower and upper bounds (inclusive) using the speci...
size_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
Definition max_size.hpp:19
void check_greater_or_equal(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not greater or equal than low.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9