Skip to main content

math_audio_optimisation/
mutant_rand1.rs

1use ndarray::{Array1, Array2, Zip};
2use rand::Rng;
3
4use crate::distinct_indices::distinct_indices;
5
6pub(crate) fn mutant_rand1<R: Rng + ?Sized>(
7    i: usize,
8    pop: &Array2<f64>,
9    f: f64,
10    rng: &mut R,
11) -> Array1<f64> {
12    let idxs = distinct_indices(i, 3, pop.nrows(), rng);
13    let r0 = idxs[0];
14    let r1 = idxs[1];
15    let r2 = idxs[2];
16
17    Zip::from(pop.row(r0))
18        .and(pop.row(r1))
19        .and(pop.row(r2))
20        .map_collect(|&x0, &x1, &x2| x0 + f * (x1 - x2))
21}