@@ -6,7 +6,8 @@ use core::{
66use necsim_core:: cogs:: {
77 distribution:: {
88 Bernoulli , Exponential , IndexU128 , IndexU32 , IndexU64 , IndexUsize , Lambda , Length , Normal ,
9- Normal2D , Poisson , StandardNormal2D , UniformClosedOpenUnit , UniformOpenClosedUnit ,
9+ Normal2D , Poisson , RawDistribution , StandardNormal2D , UniformClosedOpenUnit ,
10+ UniformOpenClosedUnit ,
1011 } ,
1112 Backup , DistributionSampler , MathsCore , Rng , RngCore ,
1213} ;
@@ -86,7 +87,7 @@ impl<M: MathsCore, R: RngCore, S> DistributionSampler<M, R, S, UniformClosedOpen
8687 self
8788 }
8889
89- fn sample_with ( & self , rng : & mut R , _samplers : & S , _params : ( ) ) -> ClosedOpenUnitF64 {
90+ fn sample_distribution ( & self , rng : & mut R , _samplers : & S , _params : ( ) ) -> ClosedOpenUnitF64 {
9091 // http://prng.di.unimi.it -> Generating uniform doubles in the unit interval
9192 #[ allow( clippy:: cast_precision_loss) ]
9293 let u01 = ( ( rng. sample_u64 ( ) >> 11 ) as f64 ) * f64:: from_bits ( 0x3CA0_0000_0000_0000_u64 ) ; // 0x1.0p-53
@@ -104,7 +105,7 @@ impl<M: MathsCore, R: RngCore, S> DistributionSampler<M, R, S, UniformOpenClosed
104105 self
105106 }
106107
107- fn sample_with ( & self , rng : & mut R , _samplers : & S , _params : ( ) ) -> OpenClosedUnitF64 {
108+ fn sample_distribution ( & self , rng : & mut R , _samplers : & S , _params : ( ) ) -> OpenClosedUnitF64 {
108109 // http://prng.di.unimi.it -> Generating uniform doubles in the unit interval
109110 #[ allow( clippy:: cast_precision_loss) ]
110111 let u01 =
@@ -123,10 +124,15 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformClosedOpen
123124 self
124125 }
125126
126- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroUsize > ) -> usize {
127+ fn sample_distribution (
128+ & self ,
129+ rng : & mut R ,
130+ samplers : & S ,
131+ params : Length < NonZeroUsize > ,
132+ ) -> usize {
127133 let length = params. 0 ;
128134
129- let u01: ClosedOpenUnitF64 = samplers . sample ( rng, samplers) ;
135+ let u01 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
130136
131137 #[ allow(
132138 clippy:: cast_precision_loss,
@@ -149,10 +155,10 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformClosedOpen
149155 self
150156 }
151157
152- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU32 > ) -> u32 {
158+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU32 > ) -> u32 {
153159 let length = params. 0 ;
154160
155- let u01: ClosedOpenUnitF64 = samplers . sample ( rng, samplers) ;
161+ let u01 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
156162
157163 #[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
158164 let index = M :: floor ( u01. get ( ) * f64:: from ( length. get ( ) ) ) as u32 ;
@@ -171,10 +177,10 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformClosedOpen
171177 self
172178 }
173179
174- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU64 > ) -> u64 {
180+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU64 > ) -> u64 {
175181 let length = params. 0 ;
176182
177- let u01: ClosedOpenUnitF64 = samplers . sample ( rng, samplers) ;
183+ let u01 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
178184
179185 #[ allow(
180186 clippy:: cast_precision_loss,
@@ -197,10 +203,10 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformClosedOpen
197203 self
198204 }
199205
200- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU128 > ) -> u128 {
206+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Length < NonZeroU128 > ) -> u128 {
201207 let length = params. 0 ;
202208
203- let u01: ClosedOpenUnitF64 = samplers . sample ( rng, samplers) ;
209+ let u01 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
204210
205211 #[ allow(
206212 clippy:: cast_precision_loss,
@@ -223,10 +229,10 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformOpenClosed
223229 self
224230 }
225231
226- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Lambda ) -> NonNegativeF64 {
232+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Lambda ) -> NonNegativeF64 {
227233 let lambda = params. 0 ;
228234
229- let u01: OpenClosedUnitF64 = samplers . sample ( rng, samplers) ;
235+ let u01 = UniformOpenClosedUnit :: sample_raw ( rng, samplers) ;
230236
231237 // Inverse transform sample: X = -ln(U(0,1]) / lambda
232238 -u01. ln :: < M > ( ) / lambda
@@ -246,15 +252,14 @@ impl<
246252 self
247253 }
248254
249- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Lambda ) -> u64 {
255+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Lambda ) -> u64 {
250256 let lambda = params. 0 ;
251257 let no_event_probability = M :: exp ( -lambda. get ( ) ) ;
252258
253259 if no_event_probability <= 0.0_f64 {
254260 // Fallback in case no_event_probability_per_step underflows
255261 #[ allow( clippy:: cast_possible_truncation, clippy:: cast_sign_loss) ]
256- let normal_as_poisson = DistributionSampler :: < M , R , S , Normal2D > :: sample_with (
257- samplers,
262+ let normal_as_poisson = Normal2D :: sample_raw_with (
258263 rng,
259264 samplers,
260265 Normal {
@@ -273,8 +278,7 @@ impl<
273278 let mut prod = no_event_probability;
274279 let mut acc = no_event_probability;
275280
276- let u =
277- DistributionSampler :: < M , R , S , UniformClosedOpenUnit > :: sample ( samplers, rng, samplers) ;
281+ let u = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
278282
279283 #[ allow( clippy:: cast_precision_loss) ]
280284 while u > acc && prod > 0.0_f64 {
@@ -296,10 +300,10 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, UniformClosedOpen
296300 self
297301 }
298302
299- fn sample_with ( & self , rng : & mut R , samplers : & S , params : ClosedUnitF64 ) -> bool {
303+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : ClosedUnitF64 ) -> bool {
300304 let probability = params;
301305
302- let u01: ClosedOpenUnitF64 = samplers . sample ( rng, samplers) ;
306+ let u01 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
303307
304308 // if probability == 1, then U[0, 1) always < 1.0
305309 // if probability == 0, then U[0, 1) never < 0.0
@@ -320,12 +324,10 @@ impl<
320324 self
321325 }
322326
323- fn sample_with ( & self , rng : & mut R , samplers : & S , _params : ( ) ) -> ( f64 , f64 ) {
327+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , _params : ( ) ) -> ( f64 , f64 ) {
324328 // Basic Box-Muller transform
325- let u0 =
326- DistributionSampler :: < M , R , S , UniformOpenClosedUnit > :: sample ( samplers, rng, samplers) ;
327- let u1 =
328- DistributionSampler :: < M , R , S , UniformClosedOpenUnit > :: sample ( samplers, rng, samplers) ;
329+ let u0 = UniformOpenClosedUnit :: sample_raw ( rng, samplers) ;
330+ let u1 = UniformClosedOpenUnit :: sample_raw ( rng, samplers) ;
329331
330332 let r = M :: sqrt ( -2.0_f64 * M :: ln ( u0. get ( ) ) ) ;
331333 let theta = -core:: f64:: consts:: TAU * u1. get ( ) ;
@@ -343,8 +345,8 @@ impl<M: MathsCore, R: RngCore, S: DistributionSampler<M, R, S, StandardNormal2D>
343345 self
344346 }
345347
346- fn sample_with ( & self , rng : & mut R , samplers : & S , params : Normal ) -> ( f64 , f64 ) {
347- let ( z0, z1) = samplers . sample ( rng, samplers) ;
348+ fn sample_distribution ( & self , rng : & mut R , samplers : & S , params : Normal ) -> ( f64 , f64 ) {
349+ let ( z0, z1) = StandardNormal2D :: sample_raw ( rng, samplers) ;
348350
349351 (
350352 z0 * params. sigma . get ( ) + params. mu ,
0 commit comments