File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ impl Distribution<f64> for GammaSmallShape {
162
162
impl Distribution < f64 > for GammaLargeShape {
163
163
fn sample < R : Rng + ?Sized > ( & self , rng : & mut R ) -> f64 {
164
164
loop {
165
- let x = rng. sample ( StandardNormal ) ;
165
+ let x: f64 = rng. sample ( StandardNormal ) ;
166
166
let v_cbrt = 1.0 + self . c * x;
167
167
if v_cbrt <= 0.0 { // a^3 <= 0 iff a <= 0
168
168
continue
@@ -238,7 +238,7 @@ impl Distribution<f64> for ChiSquared {
238
238
match self . repr {
239
239
DoFExactlyOne => {
240
240
// k == 1 => N(0,1)^2
241
- let norm = rng. sample ( StandardNormal ) ;
241
+ let norm: f64 = rng. sample ( StandardNormal ) ;
242
242
norm * norm
243
243
}
244
244
DoFAnythingElse ( ref g) => g. sample ( rng)
@@ -332,7 +332,7 @@ impl StudentT {
332
332
}
333
333
impl Distribution < f64 > for StudentT {
334
334
fn sample < R : Rng + ?Sized > ( & self , rng : & mut R ) -> f64 {
335
- let norm = rng. sample ( StandardNormal ) ;
335
+ let norm: f64 = rng. sample ( StandardNormal ) ;
336
336
norm * ( self . dof / self . chi . sample ( rng) ) . sqrt ( )
337
337
}
338
338
}
Original file line number Diff line number Diff line change @@ -37,6 +37,15 @@ use crate::utils::ziggurat;
37
37
#[ derive( Clone , Copy , Debug ) ]
38
38
pub struct StandardNormal ;
39
39
40
+ impl Distribution < f32 > for StandardNormal {
41
+ #[ inline]
42
+ fn sample < R : Rng + ?Sized > ( & self , rng : & mut R ) -> f32 {
43
+ // TODO: use optimal 32-bit implementation
44
+ let x: f64 = self . sample ( rng) ;
45
+ x as f32
46
+ }
47
+ }
48
+
40
49
impl Distribution < f64 > for StandardNormal {
41
50
fn sample < R : Rng + ?Sized > ( & self , rng : & mut R ) -> f64 {
42
51
#[ inline]
@@ -121,7 +130,7 @@ impl Normal {
121
130
}
122
131
impl Distribution < f64 > for Normal {
123
132
fn sample < R : Rng + ?Sized > ( & self , rng : & mut R ) -> f64 {
124
- let n = rng. sample ( StandardNormal ) ;
133
+ let n: f64 = rng. sample ( StandardNormal ) ;
125
134
self . mean + self . std_dev * n
126
135
}
127
136
}
You can’t perform that action at this time.
0 commit comments