46 if(dim == 0)
return x;
51 double n_req = asDouble(N) + 0.5;
52 if(!(n_req > 0.0))
return x;
53 if(n_req > 2147483000.0) n_req = 2147483000.0;
54 Type n_left = Type(CppAD::Integer(n_req));
55 Type p_left = p.sum();
57 for(
int a = 0; a < dim - 1; a++){
58 if(!(n_left > Type(0)))
break;
60 Type pa = (p_left > Type(0)) ? p(a) / p_left : Type(0);
61 if(pa < Type(0)) pa = Type(0);
62 if(pa > Type(1)) pa = Type(1);
63 x(a) = rbinom(n_left, pa);
69 if(n_left > Type(0)) x(dim - 1) = n_left;
90 int dim = alpha.size();
93 if(dim == 0)
return x;
95 for(
int a = 0; a < dim; a++){
96 x(a) = (alpha(a) > Type(0)) ? rgamma(alpha(a), Type(1)) : Type(0);
101 Type a_tot = alpha.sum();
104 Type u = runif(Type(0), Type(1)) * a_tot;
106 for(
int a = 0; a < dim; a++){
108 if(u <= acc){ x(a) = Type(1);
return x; }
111 x(dim - 1) = Type(1);