diff --git a/lab4/src/algo/compute.rs b/lab4/src/algo/compute.rs index e4c23d5..9c9fc77 100644 --- a/lab4/src/algo/compute.rs +++ b/lab4/src/algo/compute.rs @@ -1,13 +1,42 @@ -fn compute_potential/**/( - weights: &[&[f64/*; Is*/]/*; Os*/], - input_data: &[f64/*; Is*/], - potential_data: &mut [f64/*; Is*/], - output_data: &mut [f64/*; Is*/], +use std::ops::Index; + +fn compute_potential>( + weights: &[WA], + input_data: &[f64], + potential_data: &mut [f64], + output_data: &mut [f64], f: impl Fn(f64) -> f64, -) { +) where + for<'a> &'a WA: IntoIterator, +{ for (i, n) in weights.iter().enumerate() { - let P = input_data.iter().zip(n.iter()).map(|(x, w)| x * w).sum(); + let P = input_data + .iter() + .zip(n.into_iter()) + .map(|(x, w)| x * w) + .sum(); potential_data[i] = P; output_data[i] = f(P); } } + + +#[test] +fn test_compiles_static() { + let weights = [[0.0, 0.0], [1.0, 0.0]]; + let input_data = [0.0, 0.0]; + let mut potential_data = [0.0, 0.0]; + let mut output_data = [0.0, 0.0]; + + compute_potential(&weights, &input_data, &mut potential_data, &mut output_data, |x| x); +} + +#[test] +fn test_compiles_dynamic() { + let weights = [Vec::new(), Vec::new()]; + let input_data = [0.0, 0.0]; + let mut potential_data = [0.0, 0.0]; + let mut output_data = [0.0, 0.0]; + + compute_potential(&weights, &input_data, &mut potential_data, &mut output_data, |x| x); +} \ No newline at end of file diff --git a/lab4/src/algo/fix.rs b/lab4/src/algo/fix.rs index a24fa7f..0c28921 100644 --- a/lab4/src/algo/fix.rs +++ b/lab4/src/algo/fix.rs @@ -1,7 +1,9 @@ -fn calc_error/**/( - next_errors: &[f64/*; Ns*/], - weights: &[&[f64/*; Cs*/]/*; Ns*/], - current_errors: &mut [f64/*; Cs*/] +use std::ops::{Index, IndexMut}; + +fn calc_error>( + next_errors: &[f64], + weights: &[NWA], + current_errors: &mut [f64], ) { for i in 0..current_errors.len() { current_errors[i] = weights @@ -12,14 +14,14 @@ fn calc_error/**/( } } -fn apply_error/**/( +fn apply_error>( n: f64, - errors: &[f64/*; Ns*/], - weights: &mut [&mut [f64/*; Cs*/]/*; Ns*/], - current_potentials: &[f64/*; Cs*/], - next_potentials: &[f64/*; Cs*/], + errors: &[f64], + weights: &mut [NWA], + current_potentials: &[f64], + next_potentials: &[f64], f: impl Fn(f64) -> f64, - f1: impl Fn(f64) -> f64 + f1: impl Fn(f64) -> f64, ) { for i in 0..current_potentials.len() { for j in 0..next_potentials.len() {