Skip to content

Commit

Permalink
Merge #185
Browse files Browse the repository at this point in the history
185: Bump rand to 0.8 r=cuviper a=Gelbpunkt

This updates rand to 0.8, which is required when working with a 0.8 version in the package since the version needs to match for the trait.

Co-authored-by: Jens Reidel <adrian@travitia.xyz>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people committed Mar 5, 2021
2 parents a6e2c07 + 4247abe commit 60637c5
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 56 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -14,9 +14,8 @@ jobs:
matrix:
rust: [
1.31.0, # 2018!
1.32.0, # rand
1.34.0, # quickcheck, has_try_from
1.36.0, # alloc
1.36.0, # alloc, rand
stable,
beta,
nightly
Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Expand Up @@ -8,12 +8,17 @@ categories = [ "algorithms", "data-structures", "science" ]
license = "MIT OR Apache-2.0"
name = "num-bigint"
repository = "https://github.com/rust-num/num-bigint"
version = "0.3.2"
version = "0.4.0-pre"
publish = false
readme = "README.md"
build = "build.rs"
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
edition = "2018"

[features]
default = ["std"]
std = ["num-integer/std", "num-traits/std"]

[package.metadata.docs.rs]
features = ["std", "serde", "rand", "quickcheck", "arbitrary"]

Expand Down Expand Up @@ -47,7 +52,7 @@ features = ["i128"]

[dependencies.rand]
optional = true
version = "0.7"
version = "0.8"
default-features = false

[dependencies.serde]
Expand All @@ -65,9 +70,5 @@ optional = true
version = "0.4"
default-features = false

[features]
default = ["std"]
std = ["num-integer/std", "num-traits/std"]

[build-dependencies]
autocfg = "1"
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -29,12 +29,12 @@ if your compiler is not new enough.
feature is enabled. To enable it include rand as

```toml
rand = "0.7"
rand = "0.8"
num-bigint = { version = "0.3", features = ["rand"] }
```

Note that you must use the version of `rand` that `num-bigint` is compatible
with: `0.7`.
with: `0.8`.

## Releases

Expand Down
11 changes: 2 additions & 9 deletions benches/bigint.rs
Expand Up @@ -5,18 +5,11 @@ extern crate test;

use num_bigint::{BigInt, BigUint, RandBigInt};
use num_traits::{FromPrimitive, Num, One, Zero};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::mem::replace;
use test::Bencher;

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
}
mod rng;
use rng::get_rng;

fn multiply_bench(b: &mut Bencher, xbits: u64, ybits: u64) {
let mut rng = get_rng();
Expand Down
11 changes: 2 additions & 9 deletions benches/gcd.rs
Expand Up @@ -6,17 +6,10 @@ extern crate test;
use num_bigint::{BigUint, RandBigInt};
use num_integer::Integer;
use num_traits::Zero;
use rand::rngs::StdRng;
use rand::SeedableRng;
use test::Bencher;

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
}
mod rng;
use rng::get_rng;

fn bench(b: &mut Bencher, bits: u64, gcd: fn(&BigUint, &BigUint) -> BigUint) {
let mut rng = get_rng();
Expand Down
38 changes: 38 additions & 0 deletions benches/rng/mod.rs
@@ -0,0 +1,38 @@
use rand::RngCore;

pub(crate) fn get_rng() -> impl RngCore {
XorShiftStar {
a: 0x0123_4567_89AB_CDEF,
}
}

/// Simple `Rng` for benchmarking without additional dependencies
struct XorShiftStar {
a: u64,
}

impl RngCore for XorShiftStar {
fn next_u32(&mut self) -> u32 {
self.next_u64() as u32
}

fn next_u64(&mut self) -> u64 {
// https://en.wikipedia.org/wiki/Xorshift#xorshift*
self.a ^= self.a >> 12;
self.a ^= self.a << 25;
self.a ^= self.a >> 27;
self.a.wrapping_mul(0x2545_F491_4F6C_DD1D)
}

fn fill_bytes(&mut self, dest: &mut [u8]) {
for chunk in dest.chunks_mut(8) {
let bytes = self.next_u64().to_le_bytes();
let slice = &bytes[..chunk.len()];
chunk.copy_from_slice(slice)
}
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
Ok(self.fill_bytes(dest))
}
}
13 changes: 3 additions & 10 deletions benches/roots.rs
Expand Up @@ -4,10 +4,11 @@
extern crate test;

use num_bigint::{BigUint, RandBigInt};
use rand::rngs::StdRng;
use rand::SeedableRng;
use test::Bencher;

mod rng;
use rng::get_rng;

// The `big64` cases demonstrate the speed of cases where the value
// can be converted to a `u64` primitive for faster calculation.
//
Expand All @@ -16,14 +17,6 @@ use test::Bencher;
//
// The `big2k` and `big4k` cases are too big for `f64`, and use a simpler guess.

fn get_rng() -> StdRng {
let mut seed = [0; 32];
for i in 1..32 {
seed[usize::from(i)] = i;
}
SeedableRng::from_seed(seed)
}

fn check(x: &BigUint, n: u32) {
let root = x.nth_root(n);
if n == 2 {
Expand Down
1 change: 0 additions & 1 deletion bors.toml
@@ -1,6 +1,5 @@
status = [
"Test (1.31.0)",
"Test (1.32.0)",
"Test (1.34.0)",
"Test (1.36.0)",
"Test (stable)",
Expand Down
11 changes: 4 additions & 7 deletions ci/big_rand/Cargo.toml
Expand Up @@ -6,14 +6,11 @@ edition = "2018"

[dependencies]
num-traits = "0.2.11"
rand_chacha = "0.2"
rand_isaac = "0.2"
rand_xorshift = "0.2"
rand = "0.8"
rand_chacha = "0.3"
rand_isaac = "0.3"
rand_xorshift = "0.3"

[dependencies.num-bigint]
features = ["rand"]
path = "../.."

[dependencies.rand]
features = ["small_rng"]
version = "0.7"
4 changes: 2 additions & 2 deletions ci/big_rand/src/lib.rs
Expand Up @@ -11,7 +11,7 @@ mod torture;
mod biguint {
use num_bigint::{BigUint, RandBigInt, RandomBits};
use num_traits::Zero;
use rand::distributions::Uniform;
use rand::distributions::{Distribution, Uniform};
use rand::thread_rng;
use rand::{Rng, SeedableRng};

Expand Down Expand Up @@ -192,7 +192,7 @@ mod biguint {

let mut rng = thread_rng();
let bit_range = Uniform::new(0, 2048);
let sample_bits: Vec<_> = rng.sample_iter(&bit_range).take(100).collect();
let sample_bits: Vec<_> = bit_range.sample_iter(&mut rng).take(100).collect();
for bits in sample_bits {
let x = rng.gen_biguint(bits);
for n in 2..11 {
Expand Down
11 changes: 5 additions & 6 deletions ci/big_rand/src/torture.rs
@@ -1,11 +1,10 @@
use num_bigint::RandBigInt;
use num_traits::Zero;
use rand::prelude::*;
use rand::rngs::SmallRng;
use rand_xorshift::XorShiftRng;

fn get_rng() -> SmallRng {
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
SmallRng::from_seed(seed)
fn get_rng() -> XorShiftRng {
XorShiftRng::seed_from_u64(0x1234_5678_9abc_def0)
}

fn test_mul_divide_torture_count(count: usize) {
Expand All @@ -14,8 +13,8 @@ fn test_mul_divide_torture_count(count: usize) {

for _ in 0..count {
// Test with numbers of random sizes:
let xbits = rng.gen_range(0, bits_max);
let ybits = rng.gen_range(0, bits_max);
let xbits = rng.gen_range(0..bits_max);
let ybits = rng.gen_range(0..bits_max);

let x = rng.gen_biguint(xbits);
let y = rng.gen_biguint(ybits);
Expand Down
2 changes: 1 addition & 1 deletion ci/rustup.sh
Expand Up @@ -5,6 +5,6 @@
set -ex

ci=$(dirname $0)
for version in 1.31.0 1.32.0 1.34.0 1.36.0 stable beta nightly; do
for version in 1.31.0 1.34.0 1.36.0 stable beta nightly; do
rustup run "$version" "$ci/test_full.sh"
done
2 changes: 1 addition & 1 deletion ci/test_full.sh
Expand Up @@ -28,8 +28,8 @@ if ! check_version $MSRV ; then
fi

STD_FEATURES=(serde)
check_version 1.32 && STD_FEATURES+=(rand)
check_version 1.34 && STD_FEATURES+=(quickcheck)
check_version 1.36 && STD_FEATURES+=(rand)
check_version 1.36 && NO_STD_FEATURES=(serde rand)
check_version 1.40 && STD_FEATURES+=(arbitrary)
echo "Testing supported features: ${STD_FEATURES[*]}"
Expand Down

0 comments on commit 60637c5

Please sign in to comment.