@@ -147,15 +147,15 @@ end
147
147
148
148
fft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{<:Direction} , :: AbstractFFTType , :: CallGraph{T} , :: Int ) where {T} = nothing
149
149
150
- function (g:: CallGraph{T} )(out:: AbstractVector{T} , in:: AbstractVector{T } , v:: Val{FFT_FORWARD} , t:: AbstractFFTType , idx:: Int ) where {T}
150
+ function (g:: CallGraph{T} )(out:: AbstractVector{T} , in:: AbstractVector{U } , v:: Val{FFT_FORWARD} , t:: AbstractFFTType , idx:: Int ) where {T,U }
151
151
fft! (out, in, v, t, g, idx)
152
152
end
153
153
154
- function (g:: CallGraph{T} )(out:: AbstractVector{T} , in:: AbstractVector{T } , v:: Val{FFT_BACKWARD} , t:: AbstractFFTType , idx:: Int ) where {T}
154
+ function (g:: CallGraph{T} )(out:: AbstractVector{T} , in:: AbstractVector{U } , v:: Val{FFT_BACKWARD} , t:: AbstractFFTType , idx:: Int ) where {T,U }
155
155
fft! (out, in, v, t, g, idx)
156
156
end
157
157
158
- function fft! (out:: AbstractVector{T} , in:: AbstractVector{T } , :: Val{FFT_FORWARD} , :: CompositeFFT , g:: CallGraph{T} , idx:: Int ) where {T}
158
+ function fft! (out:: AbstractVector{T} , in:: AbstractVector{U } , :: Val{FFT_FORWARD} , :: CompositeFFT , g:: CallGraph{T} , idx:: Int ) where {T,U }
159
159
N = length (out)
160
160
left = leftNode (g,idx)
161
161
right = rightNode (g,idx)
@@ -180,7 +180,7 @@ function fft!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWARD},
180
180
end
181
181
end
182
182
183
- function fft! (out:: AbstractVector{T} , in:: AbstractVector{T } , :: Val{FFT_BACKWARD} , :: CompositeFFT , g:: CallGraph{T} , idx:: Int ) where {T}
183
+ function fft! (out:: AbstractVector{T} , in:: AbstractVector{U } , :: Val{FFT_BACKWARD} , :: CompositeFFT , g:: CallGraph{T} , idx:: Int ) where {T,U }
184
184
N = length (out)
185
185
left = left (g,i)
186
186
right = right (g,i)
@@ -205,11 +205,11 @@ function fft!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_BACKWARD}
205
205
end
206
206
end
207
207
208
- function fft! (out:: AbstractVector{T} , in:: AbstractVector{T } , :: Val{FFT_FORWARD} , :: Pow2FFT , :: CallGraph{T} , :: Int ) where {T}
208
+ function fft! (out:: AbstractVector{T} , in:: AbstractVector{U } , :: Val{FFT_FORWARD} , :: Pow2FFT , :: CallGraph{T} , :: Int ) where {T,U }
209
209
fft_pow2! (out, in, Val (FFT_FORWARD))
210
210
end
211
211
212
- function fft! (out:: AbstractVector{T} , in:: AbstractVector{T } , :: Val{FFT_BACKWARD} , :: Pow2FFT , :: CallGraph{T} , :: Int ) where {T}
212
+ function fft! (out:: AbstractVector{T} , in:: AbstractVector{U } , :: Val{FFT_BACKWARD} , :: Pow2FFT , :: CallGraph{T} , :: Int ) where {T,U }
213
213
fft_pow2! (out, in, Val (FFT_BACKWARD))
214
214
end
215
215
@@ -261,16 +261,61 @@ function fft_pow2!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_BACK
261
261
end
262
262
end
263
263
264
- function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_BACKWARD} ) where {T}
264
+ """
265
+ Power of 2 FFT in place, forward
266
+
267
+ """
268
+ function fft_pow2! (out:: AbstractVector{Complex{T}} , in:: AbstractVector{T} , :: Val{FFT_FORWARD} ) where {T<: Real }
265
269
N = length (out)
266
- inc = 2 * π/ N
267
- wn² = wn = w = convert (T, cispi (2 / N))
270
+ if N == 1
271
+ out[1 ] = in[1 ]
272
+ return
273
+ end
274
+ fft_pow2! (@view (out[1 : (end ÷ 2 )]), @view (in[1 : 2 : end ]), Val (FFT_FORWARD))
275
+ fft_pow2! (@view (out[(end ÷ 2 + 1 ): end ]), @view (in[2 : 2 : end ]), Val (FFT_FORWARD))
276
+
277
+ w1 = convert (Complex{T}, cispi (- 2 / N))
278
+ wj = one (Complex{T})
279
+ m = N ÷ 2
280
+ for j in 2 : m
281
+ out[j] = out[j] + wj* out[j+ m]
282
+ wj *= w1
283
+ end
284
+ out[m+ 2 : end ] = conj .(out[m: - 1 : 2 ])
285
+ end
286
+
287
+ """
288
+ Power of 2 FFT in place, backward
289
+
290
+ """
291
+ function fft_pow2! (out:: AbstractVector{Complex{T}} , in:: AbstractVector{T} , :: Val{FFT_BACKWARD} ) where {T<: Real }
292
+ N = length (out)
293
+ if N == 1
294
+ out[1 ] = in[1 ]
295
+ return
296
+ end
297
+ fft_pow2! (@view (out[1 : (end ÷ 2 )]), @view (in[1 : 2 : end ]), Val (FFT_BACKWARD))
298
+ fft_pow2! (@view (out[(end ÷ 2 + 1 ): end ]), @view (in[2 : 2 : end ]), Val (FFT_BACKWARD))
299
+
300
+ w1 = convert (Complex{T}, cispi (2 / N))
301
+ wj = one (Complex{T})
302
+ m = N ÷ 2
303
+ for j in 2 : m
304
+ out[j] = out[j] + wj* out[j+ m]
305
+ wj *= w1
306
+ end
307
+ out[m+ 2 : end ] = conj .(out[m: - 1 : 2 ])
308
+ end
309
+
310
+ function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_FORWARD} ) where {T}
311
+ N = length (out)
312
+ wn² = wn = w = convert (T, cispi (- 2 / N))
268
313
wn_1 = one (T)
269
314
270
- tmp = in[1 ]
271
- out .= tmp
315
+ tmp = in[1 ];
316
+ out .= tmp;
272
317
tmp = sum (in)
273
- out[1 ] = tmp
318
+ out[1 ] = tmp;
274
319
275
320
wk = wn²;
276
321
for d in 2 : N
@@ -287,20 +332,20 @@ function fft_dft!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_BACKW
287
332
end
288
333
end
289
334
290
- function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_BACKWARD} ) where {T<: Real }
335
+ function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_BACKWARD} ) where {T}
291
336
N = length (out)
292
- halfN = N÷ 2
293
337
wn² = wn = w = convert (T, cispi (2 / N))
294
338
wn_1 = one (T)
295
339
296
- out .= in[1 ]
297
- out[1 ] = sum (in)
298
- iseven (N) && out[halfN+ 1 ] = foldr (- ,in)
340
+ tmp = in[1 ]
341
+ out .= tmp
342
+ tmp = sum (in)
343
+ out[1 ] = tmp
299
344
300
345
wk = wn²;
301
- for d in 2 : halfN
346
+ for d in 2 : N
302
347
out[d] = in[d]* wk + out[d]
303
- for k in (d+ 1 ): halfN
348
+ for k in (d+ 1 ): N
304
349
wk *= wn
305
350
out[d] = in[k]* wk + out[d]
306
351
out[k] = in[d]* wk + out[k]
@@ -310,23 +355,22 @@ function fft_dft!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_BACKW
310
355
wn² *= (wn* wn_1)
311
356
wk = wn²
312
357
end
313
- out[(N- halfN+ 2 ): end ] .= conj .(out[halfN: - 1 : 2 ])
314
358
end
315
359
316
- function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_FORWARD} ) where {T}
360
+ function fft_dft! (out:: AbstractVector{Complex{T}} , in:: AbstractVector{T} , :: Val{FFT_FORWARD} ) where {T<: Real }
317
361
N = length (out)
362
+ halfN = N÷ 2
318
363
wn² = wn = w = convert (T, cispi (- 2 / N))
319
364
wn_1 = one (T)
320
365
321
- tmp = in[1 ];
322
- out .= tmp;
323
- tmp = sum (in)
324
- out[1 ] = tmp;
366
+ out .= in[1 ]
367
+ out[1 ] = sum (in)
368
+ iseven (N) && (out[halfN+ 1 ] = foldr (- ,in))
325
369
326
370
wk = wn²;
327
- for d in 2 : N
371
+ for d in 2 : halfN
328
372
out[d] = in[d]* wk + out[d]
329
- for k in (d+ 1 ): N
373
+ for k in (d+ 1 ): halfN
330
374
wk *= wn
331
375
out[d] = in[k]* wk + out[d]
332
376
out[k] = in[d]* wk + out[k]
@@ -336,17 +380,18 @@ function fft_dft!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWA
336
380
wn² *= (wn* wn_1)
337
381
wk = wn²
338
382
end
383
+ out[(N- halfN+ 2 ): end ] .= conj .(out[halfN: - 1 : 2 ])
339
384
end
340
385
341
- function fft_dft! (out:: AbstractVector{T} , in:: AbstractVector{T} , :: Val{FFT_FORWARD } ) where {T<: Real }
386
+ function fft_dft! (out:: AbstractVector{Complex{T}} , in:: AbstractVector{T} , :: Val{FFT_BACKWARD } ) where {T<: Real }
342
387
N = length (out)
343
388
halfN = N÷ 2
344
- wn² = wn = w = convert (T, cispi (- 2 / N))
389
+ wn² = wn = w = convert (T, cispi (2 / N))
345
390
wn_1 = one (T)
346
391
347
392
out .= in[1 ]
348
393
out[1 ] = sum (in)
349
- iseven (N) && out[halfN+ 1 ] = foldr (- ,in)
394
+ iseven (N) && ( out[halfN+ 1 ] = foldr (- ,in) )
350
395
351
396
wk = wn²;
352
397
for d in 2 : halfN
0 commit comments