math_audio_test_functions/functions/
vincent.rs1use ndarray::Array1;
4
5pub fn vincent(x: &Array1<f64>) -> f64 {
9 -x.iter().map(|&xi| (10.0 * xi.ln()).sin()).sum::<f64>()
10}
11#[cfg(test)]
12mod tests {
13 use super::*;
14
15 #[test]
16 fn test_vincent_known_properties() {
17 use ndarray::Array1;
19
20 let x_approx = Array1::from(vec![7.70628, 7.70628]);
22 let f_approx = vincent(&x_approx);
23
24 assert!(
26 f_approx < -1.9,
27 "Approximate optimum value not as expected: {}",
28 f_approx
29 );
30
31 let x_low = Array1::from(vec![0.25, 0.25]);
33 let f_low = vincent(&x_low);
34 assert!(
35 f_low.is_finite(),
36 "Function at lower bound should be finite"
37 );
38
39 let x_high = Array1::from(vec![10.0, 10.0]);
40 let f_high = vincent(&x_high);
41 assert!(
42 f_high.is_finite(),
43 "Function at upper bound should be finite"
44 );
45 }
46}