Skip to content

Commit

Permalink
1.61 const update
Browse files Browse the repository at this point in the history
  • Loading branch information
ABouttefeux committed Jun 19, 2022
1 parent 5db8e10 commit 2996af9
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/simulation/monte_carlo/heat_bath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ pub struct HeatBathSweep<Rng: rand::Rng> {

impl<Rng: rand::Rng> HeatBathSweep<Rng> {
/// 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
}
Expand All @@ -63,7 +64,7 @@ impl<Rng: rand::Rng> HeatBathSweep<Rng> {
}

/// Get a reference to the rng.
pub fn rng(&self) -> &Rng {
pub const fn rng(&self) -> &Rng {
&self.rng
}

Expand Down
9 changes: 5 additions & 4 deletions src/simulation/monte_carlo/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
46 changes: 24 additions & 22 deletions src/simulation/monte_carlo/hybrid_monte_carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -104,20 +104,20 @@ 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 :
/// - delta_t is the step size per integration of the equation of motion
/// - 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::<LatticeStateEFSyncDefault<State, D>, I, D>::new(
delta_t,
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -363,15 +364,15 @@ where

project!(
/// Get `delta_t`.
pub,
pub const,
delta_t,
internal,
Real
);

project!(
/// Get the number of steps.
pub,
pub const,
number_of_steps,
internal,
usize
Expand All @@ -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<State, D>,
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions src/simulation/monte_carlo/metropolis_hastings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,28 @@ pub struct MetropolisHastingsDeltaDiagnostic<Rng: rand::Rng> {
impl<Rng: rand::Rng> MetropolisHastingsDeltaDiagnostic<Rng> {
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.
Expand All @@ -351,6 +351,7 @@ impl<Rng: rand::Rng> MetropolisHastingsDeltaDiagnostic<Rng> {
}

/// 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
}
Expand Down
7 changes: 4 additions & 3 deletions src/simulation/monte_carlo/metropolis_hastings_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct MetropolisHastingsSweep<Rng: rand::Rng> {
impl<Rng: rand::Rng> MetropolisHastingsSweep<Rng> {
getter!(
/// Get a ref to the rng.
pub,
pub const,
rng,
Rng
);
Expand All @@ -88,16 +88,17 @@ impl<Rng: rand::Rng> MetropolisHastingsSweep<Rng> {
}

/// 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
}
Expand Down
7 changes: 4 additions & 3 deletions src/simulation/monte_carlo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

Expand Down
Loading

0 comments on commit 2996af9

Please sign in to comment.