Skip to main content

math_audio_optimisation/
mutant_best1.rs

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