Skip to content

Commit d374797

Browse files
committed
Ver 0.39.0
Decouple initial conditions from ODEProblem
2 parents 768c4e8 + db310b8 commit d374797

File tree

17 files changed

+52
-77
lines changed

17 files changed

+52
-77
lines changed

Cargo.toml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "peroxide"
3-
version = "0.38.1"
3+
version = "0.39.0"
44
authors = ["axect <[email protected]>"]
55
edition = "2018"
66
description = "Rust comprehensive scientific computation library contains linear algebra, numerical analysis, statistics and machine learning tools with farmiliar syntax"
@@ -11,12 +11,12 @@ readme = "README.md"
1111
documentation = "https://axect.github.io/Peroxide_Doc"
1212
keywords = ["Numeric", "Science", "Dataframe", "Plot", "LinearAlgebra"]
1313
exclude = [
14-
"example_data/",
15-
"src/bin/",
16-
"benches/",
17-
"example/",
18-
"test_data/",
19-
"peroxide-ad2",
14+
"example_data/",
15+
"src/bin/",
16+
"benches/",
17+
"example/",
18+
"test_data/",
19+
"peroxide-ad2",
2020
]
2121

2222
[badges]
@@ -40,12 +40,18 @@ anyhow = "1.0"
4040
paste = "1.0"
4141
#num-complex = "0.3"
4242
netcdf = { version = "0.7", optional = true, default-features = false }
43-
pyo3 = { version = "0.22", optional = true, features = ["auto-initialize", "gil-refs"] }
43+
pyo3 = { version = "0.23", optional = true, features = [
44+
"auto-initialize",
45+
"gil-refs",
46+
] }
4447
blas = { version = "0.22", optional = true }
4548
lapack = { version = "0.19", optional = true }
4649
serde = { version = "1.0", features = ["derive"], optional = true }
4750
json = { version = "0.12", optional = true }
48-
arrow2 = { version = "0.18", features = ["io_parquet", "io_parquet_compression"], optional = true }
51+
arrow2 = { version = "0.18", features = [
52+
"io_parquet",
53+
"io_parquet_compression",
54+
], optional = true }
4955
num-complex = { version = "0.4", optional = true }
5056
rayon = { version = "1.10", optional = true }
5157

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,14 @@ The example code demonstrates how Peroxide can be used to simulate the Lorenz at
260260
use peroxide::fuga::*;
261261

262262
fn main() -> Result<(), Box<dyn Error>> {
263+
let initial_conditions = vec![10f64, 1f64, 1f64];
263264
let rkf45 = RKF45::new(1e-4, 0.9, 1e-6, 1e-2, 100);
264265
let basic_ode_solver = BasicODESolver::new(rkf45);
265266
let (_, y_vec) = basic_ode_solver.solve(
266267
&Lorenz,
267268
(0f64, 100f64),
268269
1e-2,
270+
&initial_conditions,
269271
)?; // Error handling with `?` - can check constraint violation and etc.
270272
let y_mat = py_matrix(y_vec);
271273
let y0 = y_mat.col(0);
@@ -290,10 +292,6 @@ fn main() -> Result<(), Box<dyn Error>> {
290292
struct Lorenz;
291293

292294
impl ODEProblem for Lorenz {
293-
fn initial_conditions(&self) -> Vec<f64> {
294-
vec![10f64, 1f64, 1f64]
295-
}
296-
297295
fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
298296
dy[0] = 10f64 * (y[1] - y[0]);
299297
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

RELEASES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Release 0.39.0 (2024-11-22)
2+
3+
- Decouple `initial_conditions` from `ODEProblem`
4+
- Now, we can define `initial_conditions` in solving phase
5+
16
# Release 0.38.1 (2024-11-06)
27

38
- Fix error in `O3` feature

examples/lorenz_dp45.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![10f64, 1f64, 1f64];
56
let dp45 = DP45::new(1e-4, 0.9, 1e-6, 1e-1, 100);
67
let basic_ode_solver = BasicODESolver::new(dp45);
7-
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2)?;
8+
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2, &initial_conditions)?;
89
let y_mat = py_matrix(y_vec);
910
let y0 = y_mat.col(0);
1011
let y2 = y_mat.col(2);
@@ -29,10 +30,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2930
struct Lorenz;
3031

3132
impl ODEProblem for Lorenz {
32-
fn initial_conditions(&self) -> Vec<f64> {
33-
vec![10f64, 1f64, 1f64]
34-
}
35-
3633
fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3734
dy[0] = 10f64 * (y[1] - y[0]);
3835
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

examples/lorenz_gl4.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![10f64, 1f64, 1f64];
56
let gl4 = GL4::new(ImplicitSolver::FixedPoint, 1e-6, 100);
67
let basic_ode_solver = BasicODESolver::new(gl4);
7-
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2)?;
8+
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2, &initial_conditions)?;
89
let y_mat = py_matrix(y_vec);
910
let y0 = y_mat.col(0);
1011
let y2 = y_mat.col(2);
@@ -29,10 +30,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2930
struct Lorenz;
3031

3132
impl ODEProblem for Lorenz {
32-
fn initial_conditions(&self) -> Vec<f64> {
33-
vec![10f64, 1f64, 1f64]
34-
}
35-
3633
fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3734
dy[0] = 10f64 * (y[1] - y[0]);
3835
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

examples/lorenz_rk4.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![10f64, 1f64, 1f64];
56
let basic_ode_solver = BasicODESolver::new(RK4);
6-
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2)?;
7+
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2, &initial_conditions)?;
78
let y_mat = py_matrix(y_vec);
89
let y0 = y_mat.col(0);
910
let y2 = y_mat.col(2);
@@ -28,10 +29,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2829
struct Lorenz;
2930

3031
impl ODEProblem for Lorenz {
31-
fn initial_conditions(&self) -> Vec<f64> {
32-
vec![10f64, 1f64, 1f64]
33-
}
34-
3532
fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3633
dy[0] = 10f64 * (y[1] - y[0]);
3734
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

examples/lorenz_rkf45.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![10f64, 1f64, 1f64];
56
let rkf45 = RKF45::new(1e-4, 0.9, 1e-6, 1e-2, 100);
67
let basic_ode_solver = BasicODESolver::new(rkf45);
7-
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2)?;
8+
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2, &initial_conditions)?;
89
let y_mat = py_matrix(y_vec);
910
let y0 = y_mat.col(0);
1011
let y2 = y_mat.col(2);
@@ -29,10 +30,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2930
struct Lorenz;
3031

3132
impl ODEProblem for Lorenz {
32-
fn initial_conditions(&self) -> Vec<f64> {
33-
vec![10f64, 1f64, 1f64]
34-
}
35-
3633
fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3734
dy[0] = 10f64 * (y[1] - y[0]);
3835
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

examples/lorenz_tsit45.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![10f64, 1f64, 1f64];
56
let tsit45 = TSIT45::new(1e-2, 0.9, 1e-6, 1e-1, 100);
67
let basic_ode_solver = BasicODESolver::new(tsit45);
7-
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2)?;
8+
let (_, y_vec) = basic_ode_solver.solve(&Lorenz, (0f64, 100f64), 1e-2, &initial_conditions)?;
89
let y_mat = py_matrix(y_vec);
910
let y0 = y_mat.col(0);
1011
let y2 = y_mat.col(2);
@@ -29,10 +30,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2930
struct Lorenz;
3031

3132
impl ODEProblem for Lorenz {
32-
fn initial_conditions(&self) -> Vec<f64> {
33-
vec![10f64, 1f64, 1f64]
34-
}
35-
3633
fn rhs(&self, _t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3734
dy[0] = 10f64 * (y[1] - y[0]);
3835
dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];

examples/ode_env.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ fn main() -> Result<(), Box<dyn Error>> {
1111

1212
let c = cubic_hermite_spline(&t, &y, Quadratic)?;
1313

14+
let initial_conditions = vec![1f64];
1415
let test_problem = Test { cs: c };
1516
let basic_ode_solver = BasicODESolver::new(RK4);
16-
let (t_vec, y_vec) = basic_ode_solver.solve(&test_problem, (0f64, 10f64), 0.01)?;
17+
let (t_vec, y_vec) =
18+
basic_ode_solver.solve(&test_problem, (0f64, 10f64), 0.01, &initial_conditions)?;
1719
let y_vec: Vec<f64> = y_vec.into_iter().flatten().collect();
1820

1921
#[cfg(feature = "plot")]
@@ -38,10 +40,6 @@ struct Test {
3840
}
3941

4042
impl ODEProblem for Test {
41-
fn initial_conditions(&self) -> Vec<f64> {
42-
vec![1f64]
43-
}
44-
4543
fn rhs(&self, t: f64, _y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
4644
Ok(dy[0] = self.cs.eval(t))
4745
}

examples/ode_test_gl4.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use peroxide::fuga::*;
22

33
#[allow(unused_variables)]
44
fn main() -> Result<(), Box<dyn Error>> {
5+
let initial_conditions = vec![1f64];
56
let gl4 = GL4::new(ImplicitSolver::FixedPoint, 1e-6, 100);
67
let basic_ode_solver = BasicODESolver::new(gl4);
7-
let (t_vec, y_vec) = basic_ode_solver.solve(&Test, (0f64, 10f64), 0.01)?;
8+
let (t_vec, y_vec) = basic_ode_solver.solve(&Test, (0f64, 10f64), 0.01, &initial_conditions)?;
89
let y_vec: Vec<f64> = y_vec.into_iter().flatten().collect();
910

1011
#[cfg(feature = "plot")]
@@ -27,10 +28,6 @@ fn main() -> Result<(), Box<dyn Error>> {
2728
struct Test;
2829

2930
impl ODEProblem for Test {
30-
fn initial_conditions(&self) -> Vec<f64> {
31-
vec![1f64]
32-
}
33-
3431
fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
3532
Ok(dy[0] = (5f64 * t.powi(2) - y[0]) / (t + y[0]).exp())
3633
}

0 commit comments

Comments
 (0)