Skip to content

Commit

Permalink
feat: Pass system reference to population initializers
Browse files Browse the repository at this point in the history
This is useful sometimes. A population initializer may use specific
details (e.g., additional variable metadata) for doing the
initialization.
  • Loading branch information
pnevyk committed Jan 6, 2022
1 parent 7f3193d commit 9f2cc5b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/population.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
let size = size.get(f);

let mut individuals = vec![OVector::zeros_generic(f.dim(), U1::name()); size];
initializer.init_all(dom, rng, individuals.iter_mut());
initializer.init_all(f, dom, rng, individuals.iter_mut());

let errors = vec![F::Scalar::zero(); size];
let sorted = (0..size).collect();
Expand Down Expand Up @@ -496,6 +496,7 @@ pub trait PopulationInit<F: System> {
/// Initialize one individual in the population.
fn init<R: Rng + ?Sized, S>(
&self,
f: &F,
dom: &Domain<F::Scalar>,
rng: &mut R,
x: &mut Vector<F::Scalar, F::Dim, S>,
Expand All @@ -505,6 +506,7 @@ pub trait PopulationInit<F: System> {
/// Initialize the whole population.
fn init_all<'pop, R: Rng + ?Sized, I, S>(
&self,
f: &F,
dom: &Domain<F::Scalar>,
rng: &mut R,
population: I,
Expand All @@ -513,7 +515,7 @@ pub trait PopulationInit<F: System> {
S: StorageMut<F::Scalar, F::Dim> + 'pop,
{
for x in population {
self.init(dom, rng, x);
self.init(f, dom, rng, x);
}
}
}
Expand Down Expand Up @@ -559,6 +561,7 @@ where
{
fn init<R: Rng + ?Sized, S>(
&self,
_f: &F,
dom: &Domain<F::Scalar>,
rng: &mut R,
x: &mut Vector<F::Scalar, F::Dim, S>,
Expand Down

0 comments on commit 9f2cc5b

Please sign in to comment.