Skip to content

Commit

Permalink
feat!: rename next methods on Solver and Optimizer so they do not clash
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Nov 12, 2023
1 parent 8b6c271 commit d15c996
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/rosenbrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() -> Result<(), String> {

for i in 1..=100 {
solver
.next(&f, &dom, &mut x, &mut fx)
.solve_next(&f, &dom, &mut x, &mut fx)
.map_err(|err| format!("{}", err))?;

println!(
Expand Down
4 changes: 2 additions & 2 deletions gomez-bench/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
let mut fx = x.clone_owned();
let mut iter = 0;
loop {
if solver.next(&f, &dom, &mut x, &mut fx).is_err() {
if solver.solve_next(&f, &dom, &mut x, &mut fx).is_err() {
panic!("solver error");
}

Expand Down Expand Up @@ -290,7 +290,7 @@ impl<F: TestSystem<Scalar = f64>> Solver<F> for GslSolverWrapper<GslFunctionWrap

type Error = String;

fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
_f: &F,
_dom: &Domain<F::Scalar>,
Expand Down
6 changes: 3 additions & 3 deletions src/core/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{domain::Domain, function::Function};
/// Common interface for all optimizers.
///
/// All optimizers implement a common interface defined by the [`Optimizer`]
/// trait. The essential method is [`next`](Optimizer::next) which takes
/// trait. The essential method is [`opt_next`](Optimizer::opt_next) which takes
/// variables *x* and computes the next step. Thus it represents one iteration
/// in the process. Repeated call to this method should move *x* towards the
/// minimum in successful cases.
Expand Down Expand Up @@ -44,7 +44,7 @@ use super::{domain::Domain, function::Function};
/// const NAME: &'static str = "Random";
/// type Error = std::convert::Infallible;
///
/// fn next<Sx>(
/// fn opt_next<Sx>(
/// &mut self,
/// f: &F,
/// dom: &Domain<F::Scalar>,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub trait Optimizer<F: Function> {
/// The implementations *can* assume that subsequent calls to `next` pass
/// the value of `x` as was outputted in the previous iteration by the same
/// method.
fn next<Sx>(
fn opt_next<Sx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand Down
12 changes: 6 additions & 6 deletions src/core/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use super::{domain::Domain, system::System};
/// Common interface for all solvers.
///
/// All solvers implement a common interface defined by the [`Solver`] trait.
/// The essential method is [`next`](Solver::next) which takes variables *x* and
/// computes the next step. Thus it represents one iteration in the process.
/// Repeated call to this method should converge *x* to the solution in
/// successful cases.
/// The essential method is [`solve_next`](Solver::solve_next) which takes
/// variables *x* and computes the next step. Thus it represents one iteration
/// in the process. Repeated call to this method should converge *x* to the
/// solution in successful cases.
///
/// If you implement a solver, please consider make it a contribution to this
/// library.
Expand Down Expand Up @@ -44,7 +44,7 @@ use super::{domain::Domain, system::System};
/// const NAME: &'static str = "Random";
/// type Error = std::convert::Infallible;
///
/// fn next<Sx, Sfx>(
/// fn solve_next<Sx, Sfx>(
/// &mut self,
/// f: &F,
/// dom: &Domain<F::Scalar>,
Expand Down Expand Up @@ -86,7 +86,7 @@ pub trait Solver<F: System> {
/// The implementations *can* assume that subsequent calls to `next` pass
/// the value of `x` as was outputted in the previous iteration by the same
/// method.
fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
//! for i in 1.. {
//! // Do one iteration in the solving process.
//! solver
//! .next(&f, &dom, &mut x, &mut fx)
//! .solve_next(&f, &dom, &mut x, &mut fx)
//! .expect("solver encountered an error");
//!
//! println!(
Expand Down
6 changes: 3 additions & 3 deletions src/solver/lipo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ where

// Do not fail the optimization on an error from the local
// optimization.
match local_optimizer.next(f, dom, x) {
match local_optimizer.opt_next(f, dom, x) {
Ok(error) => error,
Err(_) => f.apply(x),
}
Expand Down Expand Up @@ -387,7 +387,7 @@ where

type Error = LipoError;

fn next<Sx>(
fn opt_next<Sx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
Expand All @@ -409,7 +409,7 @@ where

type Error = LipoError;

fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
Expand Down
4 changes: 2 additions & 2 deletions src/solver/nelder_mead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<F: Function> Optimizer<F> for NelderMead<F> {

type Error = NelderMeadError;

fn next<Sx>(
fn opt_next<Sx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand All @@ -475,7 +475,7 @@ impl<F: System + Function> Solver<F> for NelderMead<F> {

type Error = NelderMeadError;

fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand Down
2 changes: 1 addition & 1 deletion src/solver/steffensen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<F: System> Solver<F> for Steffensen<F> {

type Error = SteffensenError;

fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand Down
4 changes: 2 additions & 2 deletions src/solver/trust_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<F: System> Solver<F> for TrustRegion<F> {

type Error = TrustRegionError;

fn next<Sx, Sfx>(
fn solve_next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<F::Scalar>,
Expand Down Expand Up @@ -685,7 +685,7 @@ impl<F: Function> Optimizer<F> for TrustRegion<F> {

type Error = TrustRegionError;

fn next<Sx>(
fn opt_next<Sx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
Expand Down
6 changes: 3 additions & 3 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ where
let mut iter = 0;

loop {
solver.next(f, dom, &mut x, &mut fx)?;
solver.solve_next(f, dom, &mut x, &mut fx)?;

if fx.norm() <= tolerance {
return Ok(x);
Expand Down Expand Up @@ -767,7 +767,7 @@ where
let mut iter = 0;

loop {
let fx = optimizer.next(f, dom, &mut x)?;
let fx = optimizer.opt_next(f, dom, &mut x)?;

if fx <= min + tolerance {
// Converged.
Expand Down Expand Up @@ -799,7 +799,7 @@ where
let mut fx = x.clone_owned();

for iter in 0..iters {
solver.next(f, dom, &mut x, &mut fx)?;
solver.solve_next(f, dom, &mut x, &mut fx)?;
inspect(&solver, &x, fx.norm(), iter);
}

Expand Down

0 comments on commit d15c996

Please sign in to comment.