Skip to content

Commit 092a2c2

Browse files
committed
Run formatter, clippy, expand workflow
1 parent a97e7f6 commit 092a2c2

22 files changed

Lines changed: 102 additions & 67 deletions

.github/workflows/rust.yml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,45 @@ env:
1111

1212
jobs:
1313
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Build
18+
run: cargo build --verbose
1419

20+
check-fmt:
1521
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Check Formatting
25+
run: cargo fmt -- --check
1626

27+
clippy:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v4
31+
- name: Install clippy
32+
run: rustup component add clippy
33+
- name: Run clippy
34+
run: cargo clippy
35+
36+
test:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Run tests
41+
run: cargo test
42+
43+
examples:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Run tests
48+
run: ./run_examples
49+
50+
docs:
51+
runs-on: ubuntu-latest
1752
steps:
18-
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
23-
- name: Run examples
24-
run: ./run_examples.sh
53+
- uses: actions/checkout@v4
54+
- name: Generate documentation
55+
run: cargo doc

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ name = "eqsolver"
1717
path = "src/lib.rs"
1818

1919
[dependencies]
20-
nalgebra = "0.33.0"
20+
nalgebra = "0.34.1"
2121
num-traits = "0.2.19"
22-
rand = "0.9.1"
22+
rand = "0.9.2"
2323
rand_distr = "0.5.1"
2424
thiserror = "2.0.17"
2525

2626
[dev-dependencies]
27-
criterion = { version = "0.6.0", features = ["html_reports"] }
27+
criterion = { version = "0.8.1", features = ["html_reports"] }
2828
rand_chacha = "0.9.0"
2929

3030
[[bench]]

benchmarks/integrators.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ macro_rules! bench_with_all_methods {
5555
});
5656

5757
$c.bench_function("Monte Carlo", |bh| {
58-
bh.iter(|| {
59-
MonteCarlo::new($f)
60-
.integrate(black_box($from), black_box($to))
61-
});
58+
bh.iter(|| MonteCarlo::new($f).integrate(black_box($from), black_box($to)));
6259
});
6360

6461
$c.bench_function("MISER", |bh| {
65-
bh.iter(|| {
66-
MonteCarlo::new($f)
67-
.integrate(black_box($from), black_box($to))
68-
});
62+
bh.iter(|| MonteCarlo::new($f).integrate(black_box($from), black_box($to)));
6963
});
7064
};
7165
}

benchmarks/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
use criterion::criterion_main;
22

3+
mod integrators;
34
mod multi;
45
mod ode;
56
mod single;
6-
mod integrators;
77

8-
criterion_main!(single::benches, multi::benches, ode::benches, integrators::benches);
8+
criterion_main!(
9+
single::benches,
10+
multi::benches,
11+
ode::benches,
12+
integrators::benches
13+
);

benchmarks/multi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use criterion::{criterion_group, Criterion};
2-
use std::hint::black_box;
32
use eqsolver::{global_optimisers::*, multivariable::*};
43
use nalgebra::{vector, DMatrix, DVector, Matrix, SVector};
54
use std::f64::consts::PI;
5+
use std::hint::black_box;
66

77
criterion_group!(
88
benches,

benchmarks/ode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{criterion_group, Criterion};
2-
use std::hint::black_box;
32
use eqsolver::{ODESolver, ODESolverMethod};
43
use nalgebra::{vector, SVector, Vector2};
4+
use std::hint::black_box;
55

66
criterion_group!(
77
benches,

benchmarks/single.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{criterion_group, Criterion};
2-
use std::hint::black_box;
32
use eqsolver::single_variable::*;
43
use std::f64::consts::PI;
4+
use std::hint::black_box;
55

66
criterion_group!(
77
benches,

run_examples.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ cd examples
44
for file in *; do
55
if [ -f "$file" ]; then
66
cargo run --example "${file%.*}"
7+
cargo run --release --example "${file%.*}"
78
fi
89
done

src/integrators/adaptive_newton_cotes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::integrators::DEFAULT_MAXIMUM_CUT_COUNT;
55
use crate::DEFAULT_TOL;
66
use crate::{SolverError, SolverResult};
77

8-
98
/// # Adaptive Newton-Cotes
109
///
1110
/// A numerical integrator of functions `f: R -> R` based on the adaptive Newton-Cotes
@@ -160,8 +159,8 @@ where
160159
let delta_i = (to_i - from_i) * half;
161160
let mid_i = from_i + delta_i;
162161

163-
let integral_full = formula(&self, from_i, to_i);
164-
let integral_split = formula(&self, from_i, mid_i) + formula(&self, mid_i, to_i);
162+
let integral_full = formula(self, from_i, to_i);
163+
let integral_split = formula(self, from_i, mid_i) + formula(self, mid_i, to_i);
165164

166165
let error = (integral_full - integral_split).abs();
167166

src/integrators/miser.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ const DEFAULT_DITHER: f64 = 0.05;
2424

2525
/// # The MISER Algorithm
2626
///
27-
/// The Monte Carlo integration algorithm MISER by Press and Farrar (See [1]) uses stratified
27+
/// The Monte Carlo integration algorithm MISER by Press and Farrar (See \[1\]) uses stratified
2828
/// sampling based on variance of the integrand's value on the sampled points. More specifically,
2929
/// the original subregion (which must be a Cartesian product of intervals `[a, b]` for real `a,
3030
/// b`) is bisected along some dimension such that the integrand's value in those two subregions
3131
/// gives the smallest total variance amongst all other bisections. The total samples points are
3232
/// then distributed to those subregions according to the variance. This procedure is continued
3333
/// recursively until either the recursion depth is reached or the number of sample points
3434
/// allocated to that subregion fall under an (adjustable) threshold. The procedure is implemented
35-
/// in [`miser_recurse`].
35+
/// in (private function) `miser_recurse`.
3636
///
3737
/// There are several adjustable parameters in this implementation of [`MISER`]. The parameters are
38-
/// inspired by those used in [1]. The parameters in [`MISER`] are:
38+
/// inspired by those used in \[1\]. The parameters in [`MISER`] are:
3939
///
4040
/// - **Sample Count**: (Default `1000`) A lower bound on the number of points to sample in total.
4141
/// The reason this is a lower bound is because if the minimum threshold is fallen under then
@@ -84,7 +84,7 @@ const DEFAULT_DITHER: f64 = 0.05;
8484
/// ## References:
8585
/// (1) Press, W.H. and Farrar, G.R., 1990. Recursive stratified sampling for multidimensional
8686
/// Monte Carlo integration. Computers in Physics, 4(2), pp.190-195.
87-
/// (2) https://www.gnu.org/software/gsl/doc/html/montecarlo.html
87+
/// (2) <https://www.gnu.org/software/gsl/doc/html/montecarlo.html>
8888
pub struct MISER<F, V, T> {
8989
f: F,
9090
sample_count: usize,
@@ -205,9 +205,10 @@ where
205205
///
206206
/// The alpha value changes the proportions of the allocated samples points to each subregion
207207
/// of the bisection that happens in every recursion call of [`MISER`]. More precisely, the
208-
/// allocated points for each subregions follow the following formulas.
208+
/// allocated points for each subregions follow the following formulas:
209209
/// - `N_1 = N * (Var_1^beta / (Var_1^beta + Var_2^beta))`
210210
/// - `N_2 = N * (Var_2^beta / (Var_1^beta + Var_2^beta))`
211+
///
211212
/// where `N` is the total sample points, `Var_1` and `Var_2` are the variances of the
212213
/// integrand on the first and second subregions, respectively, and `beta = 1 / (1 + alpha)`.
213214
///
@@ -280,7 +281,7 @@ where
280281
rng: &mut impl rand::Rng,
281282
) -> SolverResult<MeanVariance<T>> {
282283
miser_recurse(
283-
&self,
284+
self,
284285
&mut from,
285286
&mut to,
286287
rng,

0 commit comments

Comments
 (0)