Skip to content

Commit

Permalink
chore: Fix clippy warnings and other stylistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Apr 27, 2023
1 parent 48bbf11 commit 141305a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gsl-wrapper/src/multiroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ where
impl<F> Drop for Solver<F> {
fn drop(&mut self) {
unsafe {
Box::from_raw(self.func.params as *mut F);
drop(Box::from_raw(self.func.params as *mut F));
gsl_sys::gsl_multiroot_fsolver_free(self.solver.as_ptr());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/solver/cuckoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{
};

/// Direction when performing local search for an individual.
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LocalWalkDirection {
/// Individuals are attracted to the best individual in the population.
TowardsBest,
Expand Down
23 changes: 11 additions & 12 deletions src/solver/nelder_mead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ where
fn next_inner<Sx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
x: &mut Vector<<F>::Scalar, <F>::Dim, Sx>,
dom: &Domain<F::Scalar>,
x: &mut Vector<F::Scalar, F::Dim, Sx>,
) -> Result<F::Scalar, NelderMeadError>
where
Sx: StorageMut<<F>::Scalar, <F>::Dim> + IsContiguous,
Sx: StorageMut<F::Scalar, F::Dim> + IsContiguous,
{
let NelderMeadOptions {
reflection_coeff,
Expand Down Expand Up @@ -506,17 +506,16 @@ where
fn next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
x: &mut Vector<<F>::Scalar, <F>::Dim, Sx>,
fx: &mut Vector<<F>::Scalar, <F>::Dim, Sfx>,
dom: &Domain<F::Scalar>,
x: &mut Vector<F::Scalar, F::Dim, Sx>,
fx: &mut Vector<F::Scalar, F::Dim, Sfx>,
) -> Result<(), Self::Error>
where
Sx: StorageMut<<F>::Scalar, <F>::Dim> + IsContiguous,
Sfx: StorageMut<<F>::Scalar, <F>::Dim>,
Sx: StorageMut<F::Scalar, F::Dim> + IsContiguous,
Sfx: StorageMut<F::Scalar, F::Dim>,
{
self.next_inner(f, dom, x).map(|_| {
fx.copy_from(&self.fx_best);
})
self.next_inner(f, dom, x)
.map(|_| fx.copy_from(&self.fx_best))
}
}

Expand Down Expand Up @@ -554,7 +553,7 @@ where
{
to.sub_to(from, self);
*self *= t;
*self += &*from;
*self += from;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/solver/steffensen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ impl<F: System> Solver<F> for Steffensen<F> {
fn next<Sx, Sfx>(
&mut self,
f: &F,
dom: &Domain<<F>::Scalar>,
x: &mut Vector<<F>::Scalar, <F>::Dim, Sx>,
fx: &mut Vector<<F>::Scalar, <F>::Dim, Sfx>,
dom: &Domain<F::Scalar>,
x: &mut Vector<F::Scalar, F::Dim, Sx>,
fx: &mut Vector<F::Scalar, F::Dim, Sfx>,
) -> Result<(), Self::Error>
where
Sx: StorageMut<<F>::Scalar, <F>::Dim> + IsContiguous,
Sfx: StorageMut<<F>::Scalar, <F>::Dim>,
Sx: StorageMut<F::Scalar, F::Dim> + IsContiguous,
Sfx: StorageMut<F::Scalar, F::Dim>,
{
if f.dim().value() != 1 {
return Err(SteffensenError::Problem(
Expand Down
6 changes: 2 additions & 4 deletions src/solver/trust_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ where
predicted <= F::Scalar::zero()
};

let gain_ratio = if deny {
if deny {
if allow_ascent {
debug!("predicted gain = 0");
} else {
Expand All @@ -578,9 +578,7 @@ where
debug!("gain ratio = {} / {} = {}", actual, predicted, gain_ratio);

gain_ratio
};

gain_ratio
}
} else {
debug!("trial step is invalid, gain ratio = 0");
F::Scalar::zero()
Expand Down

0 comments on commit 141305a

Please sign in to comment.