From b06abbade903c6ed9e097bf8dd908665de93009e Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 30 Jun 2026 20:36:20 -0700 Subject: [PATCH 1/2] Add test for Dirichlet sample normalization Signed-off-by: Anders Kaseorg --- src/distribution/dirichlet.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/distribution/dirichlet.rs b/src/distribution/dirichlet.rs index 1cc19bee..2d186073 100644 --- a/src/distribution/dirichlet.rs +++ b/src/distribution/dirichlet.rs @@ -428,6 +428,16 @@ mod tests { bad_create_case(vector![0.001, f64::INFINITY, 3756.0]); // moved to bad case as this is degenerate } + #[cfg(feature = "rand")] + #[test] + fn test_sample() { + use rand::distr::Distribution; + + test_almost(vector![1., 2.], 1., 1e-15, |dd| { + dd.sample(&mut ::rand::rng()).sum() + }); + } + #[test] fn test_mean() { let mean = |dd: Dirichlet<_>| dd.mean().unwrap(); From fd14193489bed28d1d45d0323f08e4e227a019e3 Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:23:08 -0500 Subject: [PATCH 2/2] fix: post updates to rand --- src/distribution/dirichlet.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/distribution/dirichlet.rs b/src/distribution/dirichlet.rs index 2d186073..87b6a332 100644 --- a/src/distribution/dirichlet.rs +++ b/src/distribution/dirichlet.rs @@ -432,9 +432,10 @@ mod tests { #[test] fn test_sample() { use rand::distr::Distribution; + use rand::SeedableRng; test_almost(vector![1., 2.], 1., 1e-15, |dd| { - dd.sample(&mut ::rand::rng()).sum() + dd.sample(&mut rand::rngs::StdRng::seed_from_u64(0)).sum() }); }