From 332ca62569b633a796a13ddadf997a89508b51ba Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Sun, 8 Feb 2026 19:42:50 +0300 Subject: [PATCH] [lab4] Now arrays are dynamically sized --- lab4/src/algo/compute.rs | 12 ++++++------ lab4/src/algo/fix.rs | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lab4/src/algo/compute.rs b/lab4/src/algo/compute.rs index 17b1c7e..e4c23d5 100644 --- a/lab4/src/algo/compute.rs +++ b/lab4/src/algo/compute.rs @@ -1,12 +1,12 @@ -fn compute_potential( - weights: &[[f64; Is]; Os], - input_data: &[f64; Is], - potential_data: &mut [f64; Is], - output_data: &mut [f64; Is], +fn compute_potential/**/( + weights: &[&[f64/*; Is*/]/*; Os*/], + input_data: &[f64/*; Is*/], + potential_data: &mut [f64/*; Is*/], + output_data: &mut [f64/*; Is*/], f: impl Fn(f64) -> f64, ) { for (i, n) in weights.iter().enumerate() { - let P = input_data.iter().zip(n).map(|(x, w)| x * w).sum(); + let P = input_data.iter().zip(n.iter()).map(|(x, w)| x * w).sum(); potential_data[i] = P; output_data[i] = f(P); } diff --git a/lab4/src/algo/fix.rs b/lab4/src/algo/fix.rs index 40465f3..a24fa7f 100644 --- a/lab4/src/algo/fix.rs +++ b/lab4/src/algo/fix.rs @@ -1,9 +1,9 @@ -fn calc_error( - next_errors: &[f64; Ns], - weights: &[[f64; Cs]; Ns], - current_errors: &mut [f64; Cs] +fn calc_error/**/( + next_errors: &[f64/*; Ns*/], + weights: &[&[f64/*; Cs*/]/*; Ns*/], + current_errors: &mut [f64/*; Cs*/] ) { - for i in 0..Cs { + for i in 0..current_errors.len() { current_errors[i] = weights .iter() .enumerate() @@ -12,17 +12,17 @@ fn calc_error( } } -fn apply_error( +fn apply_error/**/( n: f64, - errors: &[f64; Ns], - weights: &mut [[f64; Cs]; Ns], - current_potentials: &[f64; Cs], - next_potentials: &[f64; Cs], + errors: &[f64/*; Ns*/], + weights: &mut [&mut [f64/*; Cs*/]/*; Ns*/], + current_potentials: &[f64/*; Cs*/], + next_potentials: &[f64/*; Cs*/], f: impl Fn(f64) -> f64, f1: impl Fn(f64) -> f64 ) { - for i in 0..Cs { - for j in 0..Ns { + for i in 0..current_potentials.len() { + for j in 0..next_potentials.len() { let dw = n * errors[j] * f1(next_potentials[j]) * f(current_potentials[i]); weights[j][i] += dw; }