From 2996af95215ef3cb046358f1b61bd5cc94bc6a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Sat, 18 Jun 2022 21:14:51 +0200 Subject: [PATCH] 1.61 const update --- src/number.rs | 4 +- src/simulation/monte_carlo/heat_bath.rs | 5 +- src/simulation/monte_carlo/hybrid.rs | 9 ++-- .../monte_carlo/hybrid_monte_carlo.rs | 46 ++++++++++--------- .../monte_carlo/metropolis_hastings.rs | 9 ++-- .../monte_carlo/metropolis_hastings_sweep.rs | 7 +-- src/simulation/monte_carlo/mod.rs | 7 +-- src/simulation/state.rs | 7 +-- src/statistics/distribution.rs | 6 +-- 9 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/number.rs b/src/number.rs index 9ab3d851..b7c71956 100644 --- a/src/number.rs +++ b/src/number.rs @@ -19,12 +19,12 @@ where D: num_traits::sign::Unsigned + std::cmp::Ord + Copy, { /// Get tje integer part of the number - pub fn integer(&self) -> I { + pub const fn integer(&self) -> I { self.integer } /// Get the decimal part of the number as it is stored (as raw data) - pub fn decimal(&self) -> D { + pub const fn decimal(&self) -> D { self.decimal } } diff --git a/src/simulation/monte_carlo/heat_bath.rs b/src/simulation/monte_carlo/heat_bath.rs index cf9ba2c0..bde56480 100644 --- a/src/simulation/monte_carlo/heat_bath.rs +++ b/src/simulation/monte_carlo/heat_bath.rs @@ -48,11 +48,12 @@ pub struct HeatBathSweep { impl HeatBathSweep { /// Create a new Self form a rng. - pub fn new(rng: Rng) -> Self { + pub const fn new(rng: Rng) -> Self { Self { rng } } /// Absorbed self and return the RNG as owned. It essentially deconstruct the structure. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn rng_owned(self) -> Rng { self.rng } @@ -63,7 +64,7 @@ impl HeatBathSweep { } /// Get a reference to the rng. - pub fn rng(&self) -> &Rng { + pub const fn rng(&self) -> &Rng { &self.rng } diff --git a/src/simulation/monte_carlo/hybrid.rs b/src/simulation/monte_carlo/hybrid.rs index 7f35a7ff..cf8c3f5e 100644 --- a/src/simulation/monte_carlo/hybrid.rs +++ b/src/simulation/monte_carlo/hybrid.rs @@ -103,7 +103,7 @@ where } /// Getter for the reference hold by self. - pub fn data(&self) -> &MC { + pub const fn data(&self) -> &MC { self.data } } @@ -344,20 +344,20 @@ where { getter!( /// get the first method - pub, + pub const, method_1, MC1 ); getter!( /// get the second method - pub, + pub const, method_2, MC2 ); /// Create a new Self from two methods - pub fn new(method_1: MC1, method_2: MC2) -> Self { + pub const fn new(method_1: MC1, method_2: MC2) -> Self { Self { method_1, method_2, @@ -366,6 +366,7 @@ where } /// Deconstruct the structure ang gives back both methods + #[allow(clippy::missing_const_for_fn)] // false positive pub fn deconstruct(self) -> (MC1, MC2) { (self.method_1, self.method_2) } diff --git a/src/simulation/monte_carlo/hybrid_monte_carlo.rs b/src/simulation/monte_carlo/hybrid_monte_carlo.rs index 51328460..fe4942c2 100644 --- a/src/simulation/monte_carlo/hybrid_monte_carlo.rs +++ b/src/simulation/monte_carlo/hybrid_monte_carlo.rs @@ -89,12 +89,12 @@ where { getter!( /// Get a ref to the rng. - pub rng() -> Rng + pub const rng() -> Rng ); project!( /// Get the integrator. - pub internal.integrator() -> &I + pub const internal.integrator() -> &I ); project_mut!( @@ -104,12 +104,12 @@ where project!( /// Get `delta_t`. - pub internal.delta_t() -> Real + pub const internal.delta_t() -> Real ); project!( /// Get the number of steps. - pub internal.number_of_steps() -> usize + pub const internal.number_of_steps() -> usize ); /// gives the following parameter for the HCM : @@ -117,7 +117,7 @@ where /// - number_of_steps is the number of time /// - integrator is the methods to solve the equation of motion /// - rng, a random number generator - pub fn new(delta_t: Real, number_of_steps: usize, integrator: I, rng: Rng) -> Self { + pub const fn new(delta_t: Real, number_of_steps: usize, integrator: I, rng: Rng) -> Self { Self { internal: HybridMonteCarloInternal::, I, D>::new( delta_t, @@ -134,6 +134,7 @@ where } /// Get the last probably of acceptance of the random change. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn rng_owned(self) -> Rng { self.rng } @@ -219,27 +220,27 @@ where { getter!( /// Get the integrator. - pub, + pub const, integrator, I ); getter_copy!( /// Get `delta_t`. - pub, + pub const, delta_t, Real ); getter_copy!( /// Get the number of steps. - pub, + pub const, number_of_steps, usize ); /// see [HybridMonteCarlo::new] - pub fn new(delta_t: Real, number_of_steps: usize, integrator: I) -> Self { + pub const fn new(delta_t: Real, number_of_steps: usize, integrator: I) -> Self { Self { delta_t, number_of_steps, @@ -340,14 +341,14 @@ where { getter!( /// Get a ref to the rng. - pub, + pub const, rng, Rng ); project!( /// Get the integrator. - pub, + pub const, integrator, internal, &I @@ -363,7 +364,7 @@ where project!( /// Get `delta_t`. - pub, + pub const, delta_t, internal, Real @@ -371,7 +372,7 @@ where project!( /// Get the number of steps. - pub, + pub const, number_of_steps, internal, usize @@ -382,7 +383,7 @@ where /// - number_of_steps is the number of time /// - integrator is the method to solve the equation of motion /// - rng, a random number generator - pub fn new(delta_t: Real, number_of_steps: usize, integrator: I, rng: Rng) -> Self { + pub const fn new(delta_t: Real, number_of_steps: usize, integrator: I, rng: Rng) -> Self { Self { internal: HybridMonteCarloInternalDiagnostics::< LatticeStateEFSyncDefault, @@ -399,16 +400,17 @@ where } /// Get the last probably of acceptance of the random change. - pub fn prob_replace_last(&self) -> Real { + pub const fn prob_replace_last(&self) -> Real { self.internal.prob_replace_last() } /// Get if last step has accepted the replacement. - pub fn has_replace_last(&self) -> bool { + pub const fn has_replace_last(&self) -> bool { self.internal.has_replace_last() } /// Get the last probably of acceptance of the random change. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn rng_owned(self) -> Rng { self.rng } @@ -493,27 +495,27 @@ where { getter!( /// Get the integrator. - pub, + pub const, integrator, I ); getter_copy!( /// Get `delta_t`. - pub, + pub const, delta_t, Real ); getter_copy!( /// Get the number of steps. - pub, + pub const, number_of_steps, usize ); /// see [HybridMonteCarlo::new] - pub fn new(delta_t: Real, number_of_steps: usize, integrator: I) -> Self { + pub const fn new(delta_t: Real, number_of_steps: usize, integrator: I) -> Self { Self { delta_t, number_of_steps, @@ -525,12 +527,12 @@ where } /// Get the last probably of acceptance of the random change. - pub fn prob_replace_last(&self) -> Real { + pub const fn prob_replace_last(&self) -> Real { self.prob_replace_last } /// Get if last step has accepted the replacement. - pub fn has_replace_last(&self) -> bool { + pub const fn has_replace_last(&self) -> bool { self.has_replace_last } diff --git a/src/simulation/monte_carlo/metropolis_hastings.rs b/src/simulation/monte_carlo/metropolis_hastings.rs index d2efae19..e304e844 100644 --- a/src/simulation/monte_carlo/metropolis_hastings.rs +++ b/src/simulation/monte_carlo/metropolis_hastings.rs @@ -303,28 +303,28 @@ pub struct MetropolisHastingsDeltaDiagnostic { impl MetropolisHastingsDeltaDiagnostic { getter_copy!( /// Get the last probably of acceptance of the random change. - pub, + pub const, prob_replace_last, Real ); getter_copy!( /// Get if last step has accepted the replacement. - pub, + pub const, has_replace_last, bool ); getter!( /// Get a ref to the rng. - pub, + pub const, rng, Rng ); getter_copy!( /// Get the spread parameter. - pub spread() -> Real + pub const spread() -> Real ); /// Get a mutable reference to the rng. @@ -351,6 +351,7 @@ impl MetropolisHastingsDeltaDiagnostic { } /// Absorbs self and return the RNG as owned. It essentially deconstruct the structure. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn rng_owned(self) -> Rng { self.rng } diff --git a/src/simulation/monte_carlo/metropolis_hastings_sweep.rs b/src/simulation/monte_carlo/metropolis_hastings_sweep.rs index 0c8af6f6..c73e99b1 100644 --- a/src/simulation/monte_carlo/metropolis_hastings_sweep.rs +++ b/src/simulation/monte_carlo/metropolis_hastings_sweep.rs @@ -63,7 +63,7 @@ pub struct MetropolisHastingsSweep { impl MetropolisHastingsSweep { getter!( /// Get a ref to the rng. - pub, + pub const, rng, Rng ); @@ -88,16 +88,17 @@ impl MetropolisHastingsSweep { } /// Get the mean of last probably of acceptance of the random change. - pub fn prob_replace_mean(&self) -> Real { + pub const fn prob_replace_mean(&self) -> Real { self.prob_replace_mean } /// Number of accepted change during last sweep - pub fn number_replace_last(&self) -> usize { + pub const fn number_replace_last(&self) -> usize { self.number_replace_last } /// Get the last probably of acceptance of the random change. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn rng_owned(self) -> Rng { self.rng } diff --git a/src/simulation/monte_carlo/mod.rs b/src/simulation/monte_carlo/mod.rs index 3cadb423..250fc641 100644 --- a/src/simulation/monte_carlo/mod.rs +++ b/src/simulation/monte_carlo/mod.rs @@ -226,13 +226,13 @@ where { getter!( /// Get a ref to the rng. - pub, + pub const, rng, Rng ); /// Create the wrapper. - pub fn new(mcd: MCD, rng: Rng) -> Self { + pub const fn new(mcd: MCD, rng: Rng) -> Self { Self { mcd, rng, @@ -241,12 +241,13 @@ where } /// deconstruct the structure to get back the rng if necessary + #[allow(clippy::missing_const_for_fn)] // false positive pub fn deconstruct(self) -> (MCD, Rng) { (self.mcd, self.rng) } /// Get a reference to the [`MonteCarloDefault`] inside the wrapper. - pub fn mcd(&self) -> &MCD { + pub const fn mcd(&self) -> &MCD { &self.mcd } diff --git a/src/simulation/state.rs b/src/simulation/state.rs index 384a4597..f32e2fdb 100644 --- a/src/simulation/state.rs +++ b/src/simulation/state.rs @@ -866,7 +866,7 @@ where { getter!( /// get a reference to the state - pub, + pub const, state, State ); @@ -874,7 +874,7 @@ where /// Create a new SimulationStateLeap directly from a state without applying any modification. /// /// In most cases wou will prefer to build it using [`LatticeStateNew`] or [`Self::from_synchronous`]. - pub fn new_from_state(state: State) -> Self { + pub const fn new_from_state(state: State) -> Self { Self { state } } @@ -1067,6 +1067,7 @@ where { /// Absorbs self and return the state as owned. /// It essentially deconstruct the structure. + #[allow(clippy::missing_const_for_fn)] // false positive pub fn state_owned(self) -> State where State: Sized, @@ -1075,7 +1076,7 @@ where } /// Get a reference to the state. - pub fn lattice_state(&self) -> &State { + pub const fn lattice_state(&self) -> &State { &self.lattice_state } diff --git a/src/statistics/distribution.rs b/src/statistics/distribution.rs index 9763413b..30d1deed 100644 --- a/src/statistics/distribution.rs +++ b/src/statistics/distribution.rs @@ -58,7 +58,7 @@ where { getter_copy!( /// Returns the parameter `a`. - pub, + pub const, param_exp, T ); @@ -181,7 +181,7 @@ where { getter_copy!( /// Returns the parameter `param_exp`. - pub, + pub const, param_exp, T ); @@ -302,7 +302,7 @@ where { getter_copy!( /// return the parameter `param_exp`. - pub, + pub const, param_exp, T );