Skip to content

Commit 5c948fe

Browse files
committed
Rename NaturalCompare and math_helpers
1 parent 4dab1e3 commit 5c948fe

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

src/distributions/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use core::mem;
1414
use Rng;
1515
use distributions::{Distribution, Standard};
16-
use distributions::math_helpers::CastFromInt;
16+
use distributions::utils::CastFromInt;
1717
#[cfg(feature="simd_support")]
1818
use core::simd::*;
1919

src/distributions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ mod float;
214214
mod integer;
215215
#[cfg(feature="std")]
216216
mod log_gamma;
217-
mod math_helpers;
218217
mod other;
218+
mod utils;
219219
#[cfg(feature="std")]
220220
mod ziggurat_tables;
221221
#[cfg(feature="std")]

src/distributions/uniform.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use std::time::Duration;
116116
use Rng;
117117
use distributions::Distribution;
118118
use distributions::float::IntoFloat;
119-
use distributions::math_helpers::{WideningMultiply, NaturalCompare};
119+
use distributions::utils::{WideningMultiply, CompareAll};
120120

121121
#[cfg(feature="simd_support")]
122122
use core::simd::*;
@@ -517,7 +517,7 @@ macro_rules! uniform_float_impl {
517517
{
518518
let low = *low_b.borrow();
519519
let high = *high_b.borrow();
520-
assert!(low.cmp_lt(high),
520+
assert!(low.all_lt(high),
521521
"Uniform::new called with `low >= high`");
522522
let scale = high - low;
523523
let offset = low - scale;
@@ -533,7 +533,7 @@ macro_rules! uniform_float_impl {
533533
{
534534
let low = *low_b.borrow();
535535
let high = *high_b.borrow();
536-
assert!(low.cmp_le(high),
536+
assert!(low.all_le(high),
537537
"Uniform::new_inclusive called with `low > high`");
538538
let scale = high - low;
539539
let offset = low - scale;
@@ -562,7 +562,7 @@ macro_rules! uniform_float_impl {
562562
{
563563
let low = *low_b.borrow();
564564
let high = *high_b.borrow();
565-
assert!(low.cmp_lt(high),
565+
assert!(low.all_lt(high),
566566
"Uniform::sample_single called with low >= high");
567567
let scale = high - low;
568568
let offset = low - scale;

src/distributions/math_helpers.rs renamed to src/distributions/utils.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,32 @@ macro_rules! simd_float_from_int {
125125
#[cfg(feature="simd_support")] simd_float_from_int! { f64x8, u64x8 }
126126

127127

128-
/// `PartialOrd` for vectors compares lexicographically. We want natural order.
128+
/// `PartialOrd` for vectors compares lexicographically. We want to compare all
129+
/// the individual SIMD lanes instead, and get the combined result over all
130+
/// lanes. This is possible using something like `a.lt(b).all()`, but we
131+
/// implement it as a trait so we can write the same code for `f32` and `f64`.
129132
/// Only the comparison functions we need are implemented.
130-
pub trait NaturalCompare {
131-
fn cmp_lt(self, other: Self) -> bool;
132-
fn cmp_le(self, other: Self) -> bool;
133+
pub trait CompareAll {
134+
fn all_lt(self, other: Self) -> bool;
135+
fn all_le(self, other: Self) -> bool;
133136
}
134137

135-
impl NaturalCompare for f32 {
136-
fn cmp_lt(self, other: Self) -> bool { self < other }
137-
fn cmp_le(self, other: Self) -> bool { self <= other }
138+
impl CompareAll for f32 {
139+
fn all_lt(self, other: Self) -> bool { self < other }
140+
fn all_le(self, other: Self) -> bool { self <= other }
138141
}
139142

140-
impl NaturalCompare for f64 {
141-
fn cmp_lt(self, other: Self) -> bool { self < other }
142-
fn cmp_le(self, other: Self) -> bool { self <= other }
143+
impl CompareAll for f64 {
144+
fn all_lt(self, other: Self) -> bool { self < other }
145+
fn all_le(self, other: Self) -> bool { self <= other }
143146
}
144147

145148
#[cfg(feature="simd_support")]
146149
macro_rules! simd_less_then {
147150
($ty:ident) => {
148-
impl NaturalCompare for $ty {
149-
fn cmp_lt(self, other: Self) -> bool { self.lt(other).all() }
150-
fn cmp_le(self, other: Self) -> bool { self.le(other).all() }
151+
impl CompareAll for $ty {
152+
fn all_lt(self, other: Self) -> bool { self.lt(other).all() }
153+
fn all_le(self, other: Self) -> bool { self.le(other).all() }
151154
}
152155
}
153156
}

0 commit comments

Comments
 (0)