diff --git a/.github/workflows/benches.yml b/.github/workflows/benches.yml index a862bd7e6c..4be504fb67 100644 --- a/.github/workflows/benches.yml +++ b/.github/workflows/benches.yml @@ -1,26 +1,44 @@ name: Benches on: + push: + branches: [ master ] + paths-ignore: + - "**.md" + - "distr_test/**" + - "examples/**" pull_request: - paths: - - ".github/workflows/benches.yml" - - "benches/**" + branches: [ master ] + paths-ignore: + - "**.md" + - "distr_test/**" + - "examples/**" + +defaults: + run: + working-directory: ./benches jobs: - benches: + clippy-fmt: + name: Check Clippy and rustfmt runs-on: ubuntu-latest - defaults: - run: - working-directory: ./benches steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly + toolchain: stable components: clippy, rustfmt - name: Rustfmt run: cargo fmt -- --check - name: Clippy run: cargo clippy --all-targets -- -D warnings - - name: Build + benches: + name: Test benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + - name: Test run: RUSTFLAGS=-Dwarnings cargo test --benches diff --git a/.github/workflows/distr_test.yml b/.github/workflows/distr_test.yml index 34d632770a..ad0c0ba1e8 100644 --- a/.github/workflows/distr_test.yml +++ b/.github/workflows/distr_test.yml @@ -1,24 +1,43 @@ name: distr_test on: + push: + branches: [ master ] + paths-ignore: + - "**.md" + - "benches/**" + - "examples/**" pull_request: - paths: - - ".github/workflows/distr_test.yml" - - "distr_test/**" + branches: [ master ] + paths-ignore: + - "**.md" + - "benches/**" + - "examples/**" + +defaults: + run: + working-directory: ./distr_test jobs: - distr_test: + clippy-fmt: + name: Check Clippy and rustfmt runs-on: ubuntu-latest - defaults: - run: - working-directory: ./distr_test steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly + toolchain: stable components: clippy, rustfmt - name: Rustfmt run: cargo fmt -- --check - name: Clippy run: cargo clippy --all-targets -- -D warnings + ks-tests: + name: Run Komogorov Smirnov tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + - run: cargo test --release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4a8989c513..d5088ddcf2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,37 @@ -name: Tests +name: Main tests on: push: branches: [ master, '0.[0-9]+' ] + paths-ignore: + - "**.md" + - "benches/**" + - "distr_test/**" pull_request: branches: [ master, '0.[0-9]+' ] + paths-ignore: + - "**.md" + - "benches/**" + - "distr_test/**" permissions: contents: read # to fetch code (actions/checkout) jobs: + clippy-fmt: + name: Check Clippy and rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy, rustfmt + - name: Check Clippy + run: cargo clippy --all --all-targets -- -D warnings + - name: Check rustfmt + run: cargo fmt --all -- --check + check-doc: name: Check doc runs-on: ubuntu-latest @@ -85,7 +107,6 @@ jobs: run: | cargo test --target ${{ matrix.target }} --features=nightly cargo test --target ${{ matrix.target }} --all-features - cargo test --target ${{ matrix.target }} --manifest-path benches/Cargo.toml --benches cargo test --target ${{ matrix.target }} --lib --tests --no-default-features - name: Test rand run: | @@ -111,17 +132,6 @@ jobs: - name: Test rand_chacha run: cargo test --target ${{ matrix.target }} --manifest-path rand_chacha/Cargo.toml --features=serde - test-ks: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install toolchain - uses: dtolnay/rust-toolchain@nightly - with: - target: x86_64-unknown-linux-gnu - - name: Test Komogorov Smirnov - run: cargo test --manifest-path distr_test/Cargo.toml --release - test-cross: runs-on: ${{ matrix.os }} strategy: diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml deleted file mode 100644 index ef92b7f479..0000000000 --- a/.github/workflows/workspace.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Workspace - -on: - pull_request: - paths-ignore: - - README.md - - "benches/**" - push: - branches: master - paths-ignore: - - README.md - - "benches/**" - -jobs: - clippy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.78.0 - components: clippy - - run: cargo clippy --all --all-targets -- -D warnings - - rustfmt: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - components: rustfmt - - run: cargo fmt --all -- --check diff --git a/benches/benches/distr.rs b/benches/benches/distr.rs index 94a3940443..fccfb1e0e9 100644 --- a/benches/benches/distr.rs +++ b/benches/benches/distr.rs @@ -6,11 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(custom_inner_attributes)] - -// Rustfmt splits macro invocations to shorten lines; in this case longer-lines are more readable -#![rustfmt::skip] - use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use criterion_cycles_per_byte::CyclesPerByte; @@ -80,7 +75,8 @@ fn bench(c: &mut Criterion) { let distr = Normal::new(-E, PI).unwrap(); c.iter(|| { - distr.sample_iter(&mut rng) + distr + .sample_iter(&mut rng) .take(ITER_ELTS as usize) .fold(0.0, |a, r| a + r) }); @@ -121,12 +117,22 @@ fn bench(c: &mut Criterion) { let mut g = c.benchmark_group("weighted"); distr_int!(g, "i8", usize, WeightedIndex::new([1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap()); distr_int!(g, "u32", usize, WeightedIndex::new([1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap()); - distr_int!(g, "f64", usize, WeightedIndex::new([1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()); + distr_int!(g, "f64", usize, WeightedIndex::new([1.0f64, 0.001, 1.0 / 3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()); distr_int!(g, "large_set", usize, WeightedIndex::new((0..10000).rev().chain(1..10001)).unwrap()); distr_int!(g, "alias_method_i8", usize, WeightedAliasIndex::new(vec![1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap()); distr_int!(g, "alias_method_u32", usize, WeightedAliasIndex::new(vec![1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap()); - distr_int!(g, "alias_method_f64", usize, WeightedAliasIndex::new(vec![1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()); - distr_int!(g, "alias_method_large_set", usize, WeightedAliasIndex::new((0..10000).rev().chain(1..10001).collect()).unwrap()); + distr_int!( + g, + "alias_method_f64", + usize, + WeightedAliasIndex::new(vec![1.0f64, 0.001, 1.0 / 3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap() + ); + distr_int!( + g, + "alias_method_large_set", + usize, + WeightedAliasIndex::new((0..10000).rev().chain(1..10001).collect()).unwrap() + ); g.finish(); let mut g = c.benchmark_group("binomial"); diff --git a/benches/benches/seq_choose.rs b/benches/benches/seq_choose.rs index 8f19caf7e2..56223dd0a6 100644 --- a/benches/benches/seq_choose.rs +++ b/benches/benches/seq_choose.rs @@ -68,9 +68,7 @@ pub fn bench(c: &mut Criterion) { b.iter(|| { // Collect full result to prevent unwanted shortcuts getting // first element (in case sample_indices returns an iterator). - let samples_iter = x - .choose_multiple_weighted(&mut rng, amount, |_| 1.0) - .unwrap(); + let samples_iter = x.choose_multiple_weighted(&mut rng, amount, |_| 1.0).unwrap(); for (slot, sample) in y.iter_mut().zip(samples_iter) { *slot = *sample; } diff --git a/benches/rustfmt.toml b/benches/rustfmt.toml new file mode 100644 index 0000000000..b64fd7ad0e --- /dev/null +++ b/benches/rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 120 +fn_call_width = 108