Skip to content

Commit bd4d645

Browse files
committed
Working pow2
1 parent 2be1bb6 commit bd4d645

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.1.0"
55

66
[deps]
77
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
8+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
89

910
[compat]
1011
julia = "1"

src/NSFFT.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module NSFFT
22

3-
using Primes
3+
using Primes, StaticArrays
44
export pow2FFT!, myfft_sv
55

66
include("algos.jl")

src/algos.jl

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@enum Direction FFT_FORWARD FFT_BACKWARD
22

3-
function pow2FFT!(out::AbstractArray{T,0}, in::AbstractArray{T,0}, ::Val) where T
4-
out[] = in[]
3+
function pow2FFT!(out::AbstractArray{T,0}, in::AbstractArray{T,1}, ::Val) where T
4+
out[] = in[1]
55
end
66

77
function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWARD}) where {T<:Complex}
@@ -10,33 +10,17 @@ function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWA
1010
out[1] = in[1]
1111
return
1212
end
13-
pow2FFT!(@view(out[1:2:end]), @view(in[1:2:end]), Val(FFT_FORWARD))
14-
pow2FFT!(@view(out[2:2:end]), @view(in[2:2:end]), Val(FFT_FORWARD))
13+
pow2FFT!(@view(out[1:(end÷2)]), @view(in[1:2:end]), Val(FFT_FORWARD))
14+
pow2FFT!(@view(out[(end÷2+1):end]), @view(in[2:2:end]), Val(FFT_FORWARD))
1515

1616
inc = 2*π/N
1717
w1 = T(cos(inc), -sin(inc));
1818
wj = T(1,0)
1919
m = N ÷ 2
2020
for j in 1:m
2121
out_j = out[j]
22-
println(out_j)
2322
out[j] = out_j + wj*out[j+m]
24-
println(out_j)
25-
println()
2623
out[j+m] = out_j - wj*out[j+m]
2724
wj *= w1
2825
end
29-
println()
30-
end
31-
32-
even_zeroindexed_sv(x::SVector{N,T}) where {N,T} = SVector{N÷2}(x[1:2:end])
33-
34-
function myfft_sv(arr::SVector{N, T}) where {N, T<:Complex}
35-
Nhalf = N/2
36-
ft_even = myfft_sv(even_zeroindexed_sv(arr))
37-
ft_odd = myfft_sv(odd_zeroindexed_sv(arr))
38-
f(e, o, n) = e + exp(-2im * T*n/N)) * o
39-
ft_first = map(f, ft_even, ft_odd, 0:Nhalf-1)
40-
ft_second = map(f, ft_even, ft_odd, Nhalf:N-1)
41-
vcat(ft_first, ft_second)
4226
end

0 commit comments

Comments
 (0)