Skip to content

Commit f703d55

Browse files
author
=
committed
refactored
1 parent bd7a58b commit f703d55

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/lib.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ fn fft_compl(x: Vec<Complex64>) -> Vec<Complex64> {
2020

2121
let mut x_even: Vec<Complex64> = Vec::new();
2222
let mut x_odd: Vec<Complex64> = Vec::new();
23-
for i in 0..x.len() {
23+
for (i,&el) in x.iter().enumerate() {
2424
if i % 2 == 0 {
25-
x_even.push(x[i]);
25+
x_even.push(el);
2626
} else {
27-
x_odd.push(x[i]);
27+
x_odd.push(el);
2828
}
2929
}
30-
let mut x_even_cmplx = fft_compl(x_even);
31-
let mut x_odd_cmplx = fft_compl(x_odd);
30+
let x_even_cmplx = fft_compl(x_even);
31+
let x_odd_cmplx = fft_compl(x_odd);
3232

33-
let mut w = Complex::new(0_f64, 2_f64 * PI / n as f64);
33+
let w = Complex::new(0_f64, 2_f64 * PI / n as f64);
3434
let mut f_k: Vec<Complex64> = Vec::new();
3535
for k in 0..x.len() {
3636
let k_compl = Complex::new(k as f64, 0_f64);
@@ -87,7 +87,7 @@ pub fn dft(x: &[f64]) -> Vec<Complex64> {
8787
}
8888

8989
fn dft_compl(x: Vec<Complex64>) -> Vec<Complex64> {
90-
let w = Complex::new(0_f64, -2_f64 * PI / x.len() as f64);
90+
let w = Complex::new(0_f64, -2_f64 * PI / x.len() as f64);
9191

9292
// https://en.wikipedia.org/wiki/Discrete_Fourier_transform
9393
let mut dft_matrix: Vec<Vec<Complex64>> = Vec::new();
@@ -101,7 +101,7 @@ fn dft_compl(x: Vec<Complex64>) -> Vec<Complex64> {
101101
}
102102
dft_matrix.push(f_k.clone());
103103
}
104-
104+
105105
mul_mv(dft_matrix, x)
106106
}
107107

@@ -125,7 +125,7 @@ pub fn idft(x: &[Complex64]) -> Vec<f64> {
125125
let n = x.len() as f64;
126126
let mut rr: Vec<f64> = Vec::new();
127127
for mut i in r {
128-
i /= Complex::new(n, 0_f64);
128+
i /= Complex::new(n, 0_f64);
129129
rr.push(i.re);
130130
}
131131
rr
@@ -145,8 +145,8 @@ fn mul_mv(a: Vec<Vec<Complex64>>, b: Vec<Complex64>) -> Vec<Complex64> {
145145

146146
let mut c: Vec<Complex64> = vec![Complex::new(0_f64, 0_f64); cols];
147147
for i in 0..rows {
148-
for j in 0..cols {
149-
c[i] += a[i][j] * b[j];
148+
for (j,&el) in b.iter().enumerate().take(cols) {
149+
c[i] += a[i][j] * el;
150150
}
151151
}
152152
c
@@ -239,7 +239,7 @@ mod tests {
239239
.collect();
240240
let r = dft(&values);
241241
println!("{:?}", r.len());
242-
let o = idft(&r);
242+
let _o = idft(&r);
243243
}
244244

245245
#[test]
@@ -250,6 +250,6 @@ mod tests {
250250
.collect();
251251
let r = fft(&values);
252252
println!("{:?}", r.len());
253-
let o = ifft(&r);
253+
let _o = ifft(&r);
254254
}
255-
}
255+
}

0 commit comments

Comments
 (0)