@@ -46,7 +46,7 @@ pub struct Gamma {
46
46
enum GammaRepr {
47
47
Large ( GammaLargeShape ) ,
48
48
One ( Exp ) ,
49
- Small ( GammaSmallShape )
49
+ Small ( GammaSmallShape ) ,
50
50
}
51
51
52
52
// These two helpers could be made public, but saving the
@@ -65,7 +65,7 @@ enum GammaRepr {
65
65
/// shape parameters.
66
66
struct GammaSmallShape {
67
67
inv_shape : f64 ,
68
- large_shape : GammaLargeShape
68
+ large_shape : GammaLargeShape ,
69
69
}
70
70
71
71
/// Gamma distribution where the shape parameter is larger than 1.
@@ -75,7 +75,7 @@ struct GammaSmallShape {
75
75
struct GammaLargeShape {
76
76
scale : f64 ,
77
77
c : f64 ,
78
- d : f64
78
+ d : f64 ,
79
79
}
80
80
81
81
impl Gamma {
@@ -88,9 +88,9 @@ impl Gamma {
88
88
assert ! ( scale > 0.0 , "Gamma::new called with scale <= 0" ) ;
89
89
90
90
let repr = match shape {
91
- 1.0 => One ( Exp :: new ( 1.0 / scale) ) ,
91
+ 1.0 => One ( Exp :: new ( 1.0 / scale) ) ,
92
92
0.0 ... 1.0 => Small ( GammaSmallShape :: new_raw ( shape, scale) ) ,
93
- _ => Large ( GammaLargeShape :: new_raw ( shape, scale) )
93
+ _ => Large ( GammaLargeShape :: new_raw ( shape, scale) ) ,
94
94
} ;
95
95
Gamma { repr : repr }
96
96
}
@@ -100,7 +100,7 @@ impl GammaSmallShape {
100
100
fn new_raw ( shape : f64 , scale : f64 ) -> GammaSmallShape {
101
101
GammaSmallShape {
102
102
inv_shape : 1. / shape,
103
- large_shape : GammaLargeShape :: new_raw ( shape + 1.0 , scale)
103
+ large_shape : GammaLargeShape :: new_raw ( shape + 1.0 , scale) ,
104
104
}
105
105
}
106
106
}
@@ -111,19 +111,25 @@ impl GammaLargeShape {
111
111
GammaLargeShape {
112
112
scale : scale,
113
113
c : 1. / ( 9. * d) . sqrt ( ) ,
114
- d : d
114
+ d : d,
115
115
}
116
116
}
117
117
}
118
118
119
119
impl Sample < f64 > for Gamma {
120
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
120
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
121
+ self . ind_sample ( rng)
122
+ }
121
123
}
122
124
impl Sample < f64 > for GammaSmallShape {
123
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
125
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
126
+ self . ind_sample ( rng)
127
+ }
124
128
}
125
129
impl Sample < f64 > for GammaLargeShape {
126
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
130
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
131
+ self . ind_sample ( rng)
132
+ }
127
133
}
128
134
129
135
impl IndependentSample < f64 > for Gamma {
@@ -156,7 +162,7 @@ impl IndependentSample<f64> for GammaLargeShape {
156
162
157
163
let x_sqr = x * x;
158
164
if u < 1.0 - 0.0331 * x_sqr * x_sqr ||
159
- u. ln ( ) < 0.5 * x_sqr + self . d * ( 1.0 - v + v. ln ( ) ) {
165
+ u. ln ( ) < 0.5 * x_sqr + self . d * ( 1.0 - v + v. ln ( ) ) {
160
166
return self . d * v * self . scale
161
167
}
162
168
}
@@ -196,7 +202,9 @@ impl ChiSquared {
196
202
}
197
203
}
198
204
impl Sample < f64 > for ChiSquared {
199
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
205
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
206
+ self . ind_sample ( rng)
207
+ }
200
208
}
201
209
impl IndependentSample < f64 > for ChiSquared {
202
210
fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
@@ -206,7 +214,7 @@ impl IndependentSample<f64> for ChiSquared {
206
214
let StandardNormal ( norm) = rng. gen :: < StandardNormal > ( ) ;
207
215
norm * norm
208
216
}
209
- DoFAnythingElse ( ref g) => g. ind_sample ( rng)
217
+ DoFAnythingElse ( ref g) => g. ind_sample ( rng) ,
210
218
}
211
219
}
212
220
}
@@ -234,12 +242,14 @@ impl FisherF {
234
242
FisherF {
235
243
numer : ChiSquared :: new ( m) ,
236
244
denom : ChiSquared :: new ( n) ,
237
- dof_ratio : n / m
245
+ dof_ratio : n / m,
238
246
}
239
247
}
240
248
}
241
249
impl Sample < f64 > for FisherF {
242
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
250
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
251
+ self . ind_sample ( rng)
252
+ }
243
253
}
244
254
impl IndependentSample < f64 > for FisherF {
245
255
fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
@@ -251,7 +261,7 @@ impl IndependentSample<f64> for FisherF {
251
261
/// freedom.
252
262
pub struct StudentT {
253
263
chi : ChiSquared ,
254
- dof : f64
264
+ dof : f64 ,
255
265
}
256
266
257
267
impl StudentT {
@@ -261,12 +271,14 @@ impl StudentT {
261
271
assert ! ( n > 0.0 , "StudentT::new called with `n <= 0`" ) ;
262
272
StudentT {
263
273
chi : ChiSquared :: new ( n) ,
264
- dof : n
274
+ dof : n,
265
275
}
266
276
}
267
277
}
268
278
impl Sample < f64 > for StudentT {
269
- fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 { self . ind_sample ( rng) }
279
+ fn sample < R : Rng > ( & mut self , rng : & mut R ) -> f64 {
280
+ self . ind_sample ( rng)
281
+ }
270
282
}
271
283
impl IndependentSample < f64 > for StudentT {
272
284
fn ind_sample < R : Rng > ( & self , rng : & mut R ) -> f64 {
0 commit comments