rft/spectrum/average/
linear.rs

1use strided::{Stride, MutStride};
2
3use {Precision};
4use super::Average;
5
6/// Linear average.
7pub struct Linear;
8
9impl Average for Linear {
10	type Arguments = usize;
11
12	#[inline]
13	fn size(&amount: &Self::Arguments) -> usize {
14		amount
15	}
16
17	fn compute(&amount: &Self::Arguments, input: Stride<Precision>, mut output: MutStride<Precision>) {
18		debug_assert!(amount <= input.len() / 2);
19
20		let width = input.len() / amount;
21
22		for i in 0 .. amount {
23			let mut average = 0.0;
24			let mut j       = 0;
25
26			while j < width {
27				let offset = j + i * width;
28
29				if offset >= output.len() {
30					break;
31				}
32
33				average += input[offset];
34				j       += 1;
35			}
36
37			output[i] = average / j as Precision;
38		}
39	}
40}