Skip to content

Commit 9797779

Browse files
committed
rustfmt librand/distributions
1 parent a668dd2 commit 9797779

File tree

5 files changed

+1224
-341
lines changed

5 files changed

+1224
-341
lines changed

src/librand/distributions/exponential.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ pub struct Exp1(pub f64);
3535
// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
3636
impl Rand for Exp1 {
3737
#[inline]
38-
fn rand<R:Rng>(rng: &mut R) -> Exp1 {
38+
fn rand<R: Rng>(rng: &mut R) -> Exp1 {
3939
#[inline]
4040
fn pdf(x: f64) -> f64 {
4141
(-x).exp()
4242
}
4343
#[inline]
44-
fn zero_case<R:Rng>(rng: &mut R, _u: f64) -> f64 {
44+
fn zero_case<R: Rng>(rng: &mut R, _u: f64) -> f64 {
4545
ziggurat_tables::ZIG_EXP_R - rng.gen::<f64>().ln()
4646
}
4747

48-
Exp1(ziggurat(rng, false,
48+
Exp1(ziggurat(rng,
49+
false,
4950
&ziggurat_tables::ZIG_EXP_X,
5051
&ziggurat_tables::ZIG_EXP_F,
51-
pdf, zero_case))
52+
pdf,
53+
zero_case))
5254
}
5355
}
5456

@@ -59,7 +61,7 @@ impl Rand for Exp1 {
5961
#[derive(Copy, Clone)]
6062
pub struct Exp {
6163
/// `lambda` stored as `1/lambda`, since this is what we scale by.
62-
lambda_inverse: f64
64+
lambda_inverse: f64,
6365
}
6466

6567
impl Exp {
@@ -72,7 +74,9 @@ impl Exp {
7274
}
7375

7476
impl Sample<f64> for Exp {
75-
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) }
77+
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 {
78+
self.ind_sample(rng)
79+
}
7680
}
7781
impl IndependentSample<f64> for Exp {
7882
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {

src/librand/distributions/gamma.rs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Gamma {
4646
enum GammaRepr {
4747
Large(GammaLargeShape),
4848
One(Exp),
49-
Small(GammaSmallShape)
49+
Small(GammaSmallShape),
5050
}
5151

5252
// These two helpers could be made public, but saving the
@@ -65,7 +65,7 @@ enum GammaRepr {
6565
/// shape parameters.
6666
struct GammaSmallShape {
6767
inv_shape: f64,
68-
large_shape: GammaLargeShape
68+
large_shape: GammaLargeShape,
6969
}
7070

7171
/// Gamma distribution where the shape parameter is larger than 1.
@@ -75,7 +75,7 @@ struct GammaSmallShape {
7575
struct GammaLargeShape {
7676
scale: f64,
7777
c: f64,
78-
d: f64
78+
d: f64,
7979
}
8080

8181
impl Gamma {
@@ -88,9 +88,9 @@ impl Gamma {
8888
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
8989

9090
let repr = match shape {
91-
1.0 => One(Exp::new(1.0 / scale)),
91+
1.0 => One(Exp::new(1.0 / scale)),
9292
0.0 ... 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
93-
_ => Large(GammaLargeShape::new_raw(shape, scale))
93+
_ => Large(GammaLargeShape::new_raw(shape, scale)),
9494
};
9595
Gamma { repr: repr }
9696
}
@@ -100,7 +100,7 @@ impl GammaSmallShape {
100100
fn new_raw(shape: f64, scale: f64) -> GammaSmallShape {
101101
GammaSmallShape {
102102
inv_shape: 1. / shape,
103-
large_shape: GammaLargeShape::new_raw(shape + 1.0, scale)
103+
large_shape: GammaLargeShape::new_raw(shape + 1.0, scale),
104104
}
105105
}
106106
}
@@ -111,19 +111,25 @@ impl GammaLargeShape {
111111
GammaLargeShape {
112112
scale: scale,
113113
c: 1. / (9. * d).sqrt(),
114-
d: d
114+
d: d,
115115
}
116116
}
117117
}
118118

119119
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+
}
121123
}
122124
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+
}
124128
}
125129
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+
}
127133
}
128134

129135
impl IndependentSample<f64> for Gamma {
@@ -156,7 +162,7 @@ impl IndependentSample<f64> for GammaLargeShape {
156162

157163
let x_sqr = x * x;
158164
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()) {
160166
return self.d * v * self.scale
161167
}
162168
}
@@ -196,7 +202,9 @@ impl ChiSquared {
196202
}
197203
}
198204
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+
}
200208
}
201209
impl IndependentSample<f64> for ChiSquared {
202210
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
@@ -206,7 +214,7 @@ impl IndependentSample<f64> for ChiSquared {
206214
let StandardNormal(norm) = rng.gen::<StandardNormal>();
207215
norm * norm
208216
}
209-
DoFAnythingElse(ref g) => g.ind_sample(rng)
217+
DoFAnythingElse(ref g) => g.ind_sample(rng),
210218
}
211219
}
212220
}
@@ -234,12 +242,14 @@ impl FisherF {
234242
FisherF {
235243
numer: ChiSquared::new(m),
236244
denom: ChiSquared::new(n),
237-
dof_ratio: n / m
245+
dof_ratio: n / m,
238246
}
239247
}
240248
}
241249
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+
}
243253
}
244254
impl IndependentSample<f64> for FisherF {
245255
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
@@ -251,7 +261,7 @@ impl IndependentSample<f64> for FisherF {
251261
/// freedom.
252262
pub struct StudentT {
253263
chi: ChiSquared,
254-
dof: f64
264+
dof: f64,
255265
}
256266

257267
impl StudentT {
@@ -261,12 +271,14 @@ impl StudentT {
261271
assert!(n > 0.0, "StudentT::new called with `n <= 0`");
262272
StudentT {
263273
chi: ChiSquared::new(n),
264-
dof: n
274+
dof: n,
265275
}
266276
}
267277
}
268278
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+
}
270282
}
271283
impl IndependentSample<f64> for StudentT {
272284
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {

0 commit comments

Comments
 (0)