Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions .github/workflows/benches.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 27 additions & 8 deletions .github/workflows/distr_test.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 23 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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:
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/workspace.yml

This file was deleted.

24 changes: 15 additions & 9 deletions benches/benches/distr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -80,7 +75,8 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
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)
});
Expand Down Expand Up @@ -121,12 +117,22 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
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");
Expand Down
4 changes: 1 addition & 3 deletions benches/benches/seq_choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions benches/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 120
fn_call_width = 108