@@ -20,17 +20,17 @@ fn fft_compl(x: Vec<Complex64>) -> Vec<Complex64> {
20
20
21
21
let mut x_even: Vec < Complex64 > = Vec :: new ( ) ;
22
22
let mut x_odd: Vec < Complex64 > = Vec :: new ( ) ;
23
- for i in 0 ..x . len ( ) {
23
+ for ( i , & el ) in x . iter ( ) . enumerate ( ) {
24
24
if i % 2 == 0 {
25
- x_even. push ( x [ i ] ) ;
25
+ x_even. push ( el ) ;
26
26
} else {
27
- x_odd. push ( x [ i ] ) ;
27
+ x_odd. push ( el ) ;
28
28
}
29
29
}
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) ;
32
32
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 ) ;
34
34
let mut f_k: Vec < Complex64 > = Vec :: new ( ) ;
35
35
for k in 0 ..x. len ( ) {
36
36
let k_compl = Complex :: new ( k as f64 , 0_f64 ) ;
@@ -87,7 +87,7 @@ pub fn dft(x: &[f64]) -> Vec<Complex64> {
87
87
}
88
88
89
89
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 ) ;
91
91
92
92
// https://en.wikipedia.org/wiki/Discrete_Fourier_transform
93
93
let mut dft_matrix: Vec < Vec < Complex64 > > = Vec :: new ( ) ;
@@ -101,7 +101,7 @@ fn dft_compl(x: Vec<Complex64>) -> Vec<Complex64> {
101
101
}
102
102
dft_matrix. push ( f_k. clone ( ) ) ;
103
103
}
104
-
104
+
105
105
mul_mv ( dft_matrix, x)
106
106
}
107
107
@@ -125,7 +125,7 @@ pub fn idft(x: &[Complex64]) -> Vec<f64> {
125
125
let n = x. len ( ) as f64 ;
126
126
let mut rr: Vec < f64 > = Vec :: new ( ) ;
127
127
for mut i in r {
128
- i /= Complex :: new ( n, 0_f64 ) ;
128
+ i /= Complex :: new ( n, 0_f64 ) ;
129
129
rr. push ( i. re ) ;
130
130
}
131
131
rr
@@ -145,8 +145,8 @@ fn mul_mv(a: Vec<Vec<Complex64>>, b: Vec<Complex64>) -> Vec<Complex64> {
145
145
146
146
let mut c: Vec < Complex64 > = vec ! [ Complex :: new( 0_f64 , 0_f64 ) ; cols] ;
147
147
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 ;
150
150
}
151
151
}
152
152
c
@@ -239,7 +239,7 @@ mod tests {
239
239
. collect ( ) ;
240
240
let r = dft ( & values) ;
241
241
println ! ( "{:?}" , r. len( ) ) ;
242
- let o = idft ( & r) ;
242
+ let _o = idft ( & r) ;
243
243
}
244
244
245
245
#[ test]
@@ -250,6 +250,6 @@ mod tests {
250
250
. collect ( ) ;
251
251
let r = fft ( & values) ;
252
252
println ! ( "{:?}" , r. len( ) ) ;
253
- let o = ifft ( & r) ;
253
+ let _o = ifft ( & r) ;
254
254
}
255
- }
255
+ }
0 commit comments