Skip to content

Commit

Permalink
Fix and test deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Dec 12, 2024
1 parent 92438c3 commit 6acf4ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inst/include/monty/random/multinomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace random {
template <typename real_type, typename rng_state_type,
typename T, typename U>
__host__ __device__
void multinomial(rng_state_type& rng_state, int size, const T& prob,
void multinomial(rng_state_type& rng_state, real_type size, const T& prob,
int prob_len, U ret) {
real_type p_tot = 0;
for (int i = 0; i < prob_len; ++i) {
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-rng.R
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ test_that("can validate multinomial inputs", {
})


test_that("deterministic multinomial returns expectation", {
r <- monty_rng_create(seed = 1, deterministic = TRUE)
p <- runif(10)
p <- p / sum(p)
res <- monty_random_multinomial(100, p, r)
expect_equal(res, 100 * p)
})


test_that("deterministic rbinom returns mean", {
m <- 10
n <- as.numeric(sample(10, m, replace = TRUE))
Expand Down

0 comments on commit 6acf4ab

Please sign in to comment.