bernoulli_rng - add signature `ints bernoulli_rng(real theta)`
Open
Nobody has claimed this yet.
distributions
good first issue
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Description
Add implementation of bernoulli_rng which generates an array of bernoulli outcomes for a single value of theta.
Example
Currently, it is necessary to use a loop, e.g.
real theta = beta_rng(1, 1);
array[N] int y;
for (n in 1:N) {
y[n] = bernoulli_rng(theta);
}
The vectorized alternative is:
real theta = beta_rng(1, 1);
array[N] int y;
y = bernoulli_rng(rep_array(theta, N_obs));
This is problematic for 2 reasons:
- requires extra memory allocation for the array of
thetas - not as easy to grok
Expected Output
It would be nice to be able to do the following:
real theta = beta_rng(1, 1);
array[N] int y;
y = bernoulli_rng(rtheta);
Current Version:
v4.8.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing bernoulli_rng implementation and its vectorized RNG tests. Add coverage for a scalar theta producing an array of outcomes, then run the relevant bernoulli_rng tests; done means the new signature works without constructing an array of repeated theta values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100