Skip to content

Commit

Permalink
rustfmt: expression spacing (on the line)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Jan 2, 2020
1 parent 0f9500b commit 92e0701
Show file tree
Hide file tree
Showing 27 changed files with 59 additions and 59 deletions.
18 changes: 9 additions & 9 deletions benches/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const RAND_BENCH_N: u64 = 1000;
#[bench]
fn seq_shuffle_100(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &mut [usize] = &mut [1; 100];
let x: &mut [usize] = &mut [1; 100];
b.iter(|| {
x.shuffle(&mut rng);
x[0]
Expand All @@ -36,7 +36,7 @@ fn seq_shuffle_100(b: &mut Bencher) {
#[bench]
fn seq_slice_choose_1_of_1000(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &mut [usize] = &mut [1; 1000];
let x: &mut [usize] = &mut [1; 1000];
for i in 0..1000 {
x[i] = i;
}
Expand All @@ -55,15 +55,15 @@ macro_rules! seq_slice_choose_multiple {
#[bench]
fn $name(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &[i32] = &[$amount; $length];
let x: &[i32] = &[$amount; $length];
let mut result = [0i32; $amount];
b.iter(|| {
// Collect full result to prevent unwanted shortcuts getting
// first element (in case sample_indices returns an iterator).
for (slot, sample) in result.iter_mut().zip(x.choose_multiple(&mut rng, $amount)) {
*slot = *sample;
}
result[$amount-1]
result[$amount - 1]
})
}
};
Expand All @@ -77,7 +77,7 @@ seq_slice_choose_multiple!(seq_slice_choose_multiple_90_of_100, 90, 100);
#[bench]
fn seq_iter_choose_from_1000(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &mut [usize] = &mut [1; 1000];
let x: &mut [usize] = &mut [1; 1000];
for i in 0..1000 {
x[i] = i;
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<I: ExactSizeIterator + Iterator + Clone> Iterator for WindowHintedIterator<
#[bench]
fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &[usize] = &[1; 1000];
let x: &[usize] = &[1; 1000];
b.iter(|| {
UnhintedIterator { iter: x.iter() }
.choose(&mut rng)
Expand All @@ -134,7 +134,7 @@ fn seq_iter_unhinted_choose_from_1000(b: &mut Bencher) {
#[bench]
fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &[usize] = &[1; 1000];
let x: &[usize] = &[1; 1000];
b.iter(|| {
WindowHintedIterator {
iter: x.iter(),
Expand All @@ -147,14 +147,14 @@ fn seq_iter_window_hinted_choose_from_1000(b: &mut Bencher) {
#[bench]
fn seq_iter_choose_multiple_10_of_100(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &[usize] = &[1; 100];
let x: &[usize] = &[1; 100];
b.iter(|| x.iter().cloned().choose_multiple(&mut rng, 10))
}

#[bench]
fn seq_iter_choose_multiple_fill_10_of_100(b: &mut Bencher) {
let mut rng = SmallRng::from_rng(thread_rng()).unwrap();
let x : &[usize] = &[1; 100];
let x: &[usize] = &[1; 100];
let mut buf = [0; 10];
b.iter(|| x.iter().cloned().choose_multiple_fill(&mut rng, &mut buf))
}
Expand Down
2 changes: 1 addition & 1 deletion examples/monte-carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
for _ in 0..total {
let a = range.sample(&mut rng);
let b = range.sample(&mut rng);
if a*a + b*b <= 1.0 {
if a * a + b * b <= 1.0 {
in_circle += 1;
}
}
Expand Down
8 changes: 4 additions & 4 deletions rand_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<R: BlockRngCore> BlockRng<R> {
}
}

impl<R: BlockRngCore<Item=u32>> RngCore for BlockRng<R>
impl<R: BlockRngCore<Item = u32>> RngCore for BlockRng<R>
where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
{
#[inline]
Expand Down Expand Up @@ -201,15 +201,15 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
let len = self.results.as_ref().len();

let index = self.index;
if index < len-1 {
if index < len - 1 {
self.index += 2;
// Read an u64 from the current index
read_u64(self.results.as_ref(), index)
} else if index >= len {
self.generate_and_set(2);
read_u64(self.results.as_ref(), 0)
} else {
let x = u64::from(self.results.as_ref()[len-1]);
let x = u64::from(self.results.as_ref()[len - 1]);
self.generate_and_set(1);
let y = u64::from(self.results.as_ref()[0]);
(y << 32) | x
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
}
}

impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>
impl<R: BlockRngCore<Item = u64>> RngCore for BlockRng64<R>
where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
{
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion rand_core/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn next_u64_via_u32<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
pub fn fill_bytes_via_next<R: RngCore + ?Sized>(rng: &mut R, dest: &mut [u8]) {
let mut left = dest;
while left.len() >= 8 {
let (l, r) = {left}.split_at_mut(8);
let (l, r) = { left }.split_at_mut(8);
left = r;
let chunk: [u8; 8] = rng.next_u64().to_le_bytes();
l.copy_from_slice(&chunk);
Expand Down
4 changes: 2 additions & 2 deletions rand_distr/src/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ impl Distribution<u64> for Binomial {
// Step 5.2: Squeezing. Check the value of ln(v) againts upper and
// lower bound of ln(f(y)).
let k = k as f64;
let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1./6.) / npq + 0.5);
let t = -0.5 * k*k / npq;
let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1. / 6.) / npq + 0.5);
let t = -0.5 * k * k / npq;
let alpha = v.ln();
if alpha < t - rho {
break;
Expand Down
4 changes: 2 additions & 2 deletions rand_distr/src/cauchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ mod test {
let mut buf = [0.0; 4];
gen_samples(10f32, 7.0, &mut buf);
let expected = [15.023088, -5.446413, 3.7092876, 3.112482];
for (a,b) in buf.iter().zip(expected.iter()) {
let (a,b) = (*a, *b);
for (a, b) in buf.iter().zip(expected.iter()) {
let (a, b) = (*a, *b);
assert!((a - b).abs() < 1e-6, "expected: {} = {}", a, b);
}
}
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Distribution<f64> for StandardNormal {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 {
#[inline]
fn pdf(x: f64) -> f64 {
(-x*x/2.0).exp()
(-x * x / 2.0).exp()
}
#[inline]
fn zero_case<R: Rng + ?Sized>(rng: &mut R, u: f64) -> f64 {
Expand Down
4 changes: 2 additions & 2 deletions rand_distr/src/pert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ mod test {
assert!(Pert::new(min, max, mode).is_err());
}
}

#[test]
fn value_stability() {
let rng = crate::test::rng(860);
let distr = Pert::new(2., 10., 3.).unwrap(); // mean = 4, var = 12/7
let distr = Pert::new(2., 10., 3.).unwrap(); // mean = 4, var = 12/7
let seq = distr.sample_iter(rng).take(5).collect::<Vec<f64>>();
println!("seq: {:?}", seq);
let expected = vec![
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/unit_ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<N: Float + SampleUniform> Distribution<[N; 3]> for UnitBall {
x1 = uniform.sample(rng);
x2 = uniform.sample(rng);
x3 = uniform.sample(rng);
if x1*x1 + x2*x2 + x3*x3 <= N::from(1.) {
if x1 * x1 + x2 * x2 + x3 * x3 <= N::from(1.) {
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions rand_distr/src/unit_circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ impl<N: Float + SampleUniform> Distribution<[N; 2]> for UnitCircle {
loop {
x1 = uniform.sample(rng);
x2 = uniform.sample(rng);
sum = x1*x1 + x2*x2;
sum = x1 * x1 + x2 * x2;
if sum < N::from(1.) {
break;
}
}
let diff = x1*x1 - x2*x2;
[diff / sum, N::from(2.)*x1*x2 / sum]
let diff = x1 * x1 - x2 * x2;
[diff / sum, N::from(2.) * x1 * x2 / sum]
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ mod tests {
let mut rng = crate::test::rng(1);
for _ in 0..1000 {
let x: [f64; 2] = UnitCircle.sample(&mut rng);
assert_almost_eq!(x[0]*x[0] + x[1]*x[1], 1., 1e-15);
assert_almost_eq!(x[0] * x[0] + x[1] * x[1], 1., 1e-15);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/unit_disc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<N: Float + SampleUniform> Distribution<[N; 2]> for UnitDisc {
loop {
x1 = uniform.sample(rng);
x2 = uniform.sample(rng);
if x1*x1 + x2*x2 <= N::from(1.) {
if x1 * x1 + x2 * x2 <= N::from(1.) {
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions rand_distr/src/unit_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ impl<N: Float + SampleUniform> Distribution<[N; 3]> for UnitSphere {
let uniform = Uniform::new(N::from(-1.), N::from(1.));
loop {
let (x1, x2) = (uniform.sample(rng), uniform.sample(rng));
let sum = x1*x1 + x2*x2;
let sum = x1 * x1 + x2 * x2;
if sum >= N::from(1.) {
continue;
}
let factor = N::from(2.) * (N::from(1.0) - sum).sqrt();
return [x1 * factor, x2 * factor, N::from(1.) - N::from(2.)*sum];
return [x1 * factor, x2 * factor, N::from(1.) - N::from(2.) * sum];
}
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ mod tests {
let mut rng = crate::test::rng(1);
for _ in 0..1000 {
let x: [f64; 3] = UnitSphere.sample(&mut rng);
assert_almost_eq!(x[0]*x[0] + x[1]*x[1] + x[2]*x[2], 1., 1e-15);
assert_almost_eq!(x[0] * x[0] + x[1] * x[1] + x[2] * x[2], 1., 1e-15);
}
}

Expand Down
2 changes: 1 addition & 1 deletion rand_distr/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ pub(crate) fn ziggurat<R: Rng + ?Sized, P, Z>(
};
let x = u * x_tab[i];

let test_x = if symmetric { x.abs() } else {x};
let test_x = if symmetric { x.abs() } else { x };

// algebraically equivalent to |u| < x_tab[i+1]/x_tab[i] (or u < x_tab[i+1]/x_tab[i])
if test_x < x_tab[i + 1] {
Expand Down
4 changes: 2 additions & 2 deletions rand_hc/src/hc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl Hc128Core {
}

impl SeedableRng for Hc128Core {
type Seed = [u8; SEED_WORDS*4];
type Seed = [u8; SEED_WORDS * 4];

/// Create an HC-128 random number generator with a seed. The seed has to be
/// 256 bits in length, matching the 128 bit `key` followed by 128 bit `iv`
Expand Down Expand Up @@ -457,7 +457,7 @@ mod test {
// Pick a somewhat large buffer so we can test filling with the
// remainder from `state.results`, directly filling the buffer, and
// filling the remainder of the buffer.
let mut buffer = [0u8; 16*4*2];
let mut buffer = [0u8; 16 * 4 * 2];
// Consume a value so that we have a remainder.
assert!(rng.next_u64() == 0x04b4930a518251a4);
rng.fill_bytes(&mut buffer);
Expand Down
6 changes: 3 additions & 3 deletions rand_pcg/src/pcg128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ impl RngCore for Mcg128Xsl64 {
fn output_xsl_rr(state: u128) -> u64 {
// Output function XSL RR ("xorshift low (bits), random rotation")
// Constants are for 128-bit state, 64-bit output
const XSHIFT: u32 = 64; // (128 - 64 + 64) / 2
const ROTATE: u32 = 122; // 128 - 6
const XSHIFT: u32 = 64; // (128 - 64 + 64) / 2
const ROTATE: u32 = 122; // 128 - 6

let rot = (state >> ROTATE) as u32;
let xsl = ((state >> XSHIFT) as u64) ^ (state as u64);
Expand All @@ -213,7 +213,7 @@ fn output_xsl_rr(state: u128) -> u64 {
fn fill_bytes_impl<R: RngCore + ?Sized>(rng: &mut R, dest: &mut [u8]) {
let mut left = dest;
while left.len() >= 8 {
let (l, r) = {left}.split_at_mut(8);
let (l, r) = { left }.split_at_mut(8);
left = r;
let chunk: [u8; 8] = rng.next_u64().to_le_bytes();
l.copy_from_slice(&chunk);
Expand Down
2 changes: 1 addition & 1 deletion rand_pcg/src/pcg64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl RngCore for Lcg64Xsh32 {
// Constants are for 64-bit state, 32-bit output
const ROTATE: u32 = 59; // 64 - 5
const XSHIFT: u32 = 18; // (5 + 32) / 2
const SPARE: u32 = 27; // 64 - 32 - 5
const SPARE: u32 = 27; // 64 - 32 - 5

let rot = (state >> ROTATE) as u32;
let xsh = (((state >> XSHIFT) ^ state) >> SPARE) as u32;
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/bernoulli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod test {
assert!((avg1 - P).abs() < 5e-3);

let avg2 = (sum2 as f64) / (N as f64);
assert!((avg2 - (NUM as f64)/(DENOM as f64)).abs() < 5e-3);
assert!((avg2 - (NUM as f64) / (DENOM as f64)).abs() < 5e-3);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/distributions/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl Distribution<u64> for Binomial {
// Step 5.2: Squeezing. Check the value of ln(v) againts upper and
// lower bound of ln(f(y)).
let k = k as f64;
let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1./6.) / npq + 0.5);
let t = -0.5 * k*k / npq;
let rho = (k / npq) * ((k * (k / 3. + 0.625) + 1. / 6.) / npq + 0.5);
let t = -0.5 * k * k / npq;
let alpha = v.ln();
if alpha < t - rho {
break;
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Distribution<f64> for StandardNormal {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> f64 {
#[inline]
fn pdf(x: f64) -> f64 {
(-x*x/2.0).exp()
(-x * x / 2.0).exp()
}
#[inline]
fn zero_case<R: Rng + ?Sized>(rng: &mut R, u: f64) -> f64 {
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ mod tests {
type Sampler = UniformMyF32;
}

let (low, high) = (MyF32{ x: 17.0f32 }, MyF32{ x: 22.0f32 });
let (low, high) = (MyF32 { x: 17.0f32 }, MyF32 { x: 22.0f32 });
let uniform = Uniform::new(low, high);
let mut rng = crate::test::rng(804);
for _ in 0..100 {
Expand Down
8 changes: 4 additions & 4 deletions src/distributions/unit_circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ impl Distribution<[f64; 2]> for UnitCircle {
loop {
x1 = uniform.sample(rng);
x2 = uniform.sample(rng);
sum = x1*x1 + x2*x2;
sum = x1 * x1 + x2 * x2;
if sum < 1. {
break;
}
}
let diff = x1*x1 - x2*x2;
[diff / sum, 2.*x1*x2 / sum]
let diff = x1 * x1 - x2 * x2;
[diff / sum, 2. * x1 * x2 / sum]
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ mod tests {
let dist = UnitCircle::new();
for _ in 0..1000 {
let x = dist.sample(&mut rng);
assert_almost_eq!(x[0]*x[0] + x[1]*x[1], 1., 1e-15);
assert_almost_eq!(x[0] * x[0] + x[1] * x[1], 1., 1e-15);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/distributions/unit_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ impl Distribution<[f64; 3]> for UnitSphereSurface {
let uniform = Uniform::new(-1., 1.);
loop {
let (x1, x2) = (uniform.sample(rng), uniform.sample(rng));
let sum = x1*x1 + x2*x2;
let sum = x1 * x1 + x2 * x2;
if sum >= 1. {
continue;
}
let factor = 2. * (1.0_f64 - sum).sqrt();
return [x1 * factor, x2 * factor, 1. - 2.*sum];
return [x1 * factor, x2 * factor, 1. - 2. * sum];
}
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ mod tests {
let dist = UnitSphereSurface::new();
for _ in 0..1000 {
let x = dist.sample(&mut rng);
assert_almost_eq!(x[0]*x[0] + x[1]*x[1] + x[2]*x[2], 1., 1e-15);
assert_almost_eq!(x[0] * x[0] + x[1] * x[1] + x[2] * x[2], 1., 1e-15);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/distributions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub fn ziggurat<R: Rng + ?Sized, P, Z>(
};
let x = u * x_tab[i];

let test_x = if symmetric { x.abs() } else {x};
let test_x = if symmetric { x.abs() } else { x };

// algebraically equivalent to |u| < x_tab[i+1]/x_tab[i] (or u < x_tab[i+1]/x_tab[i])
if test_x < x_tab[i + 1] {
Expand Down
Loading

0 comments on commit 92e0701

Please sign in to comment.