Skip to content

Commit

Permalink
Simplify Kernels.init_fourier_coefficients!
Browse files Browse the repository at this point in the history
  • Loading branch information
jipolanco committed Oct 15, 2024
1 parent d40402b commit ab21f69
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Kernels/Kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function init_fourier_coefficients!(g::AbstractKernelData, ks::AbstractVector)
Nk == length(gk) && return gk # assume coefficients were already computed
resize!(gk, Nk)
@assert eachindex(gk) == eachindex(ks)
evaluate_fourier!(g, gk, ks)
f = evaluate_fourier_func(g)
map!(f, gk, ks)
gk
end

Expand Down
6 changes: 2 additions & 4 deletions src/Kernels/bspline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ function evaluate_kernel_func(g::BSplineKernelData{M}) where {M}
end
end

# This should work on CPU and GPU.
function evaluate_fourier!(g::BSplineKernelData{M}, gk::AbstractVector, ks::AbstractVector) where {M}
function evaluate_fourier_func(g::BSplineKernelData{M}) where {M}
(; Δt,) = g
@assert eachindex(gk) == eachindex(ks)
map!(gk, ks) do k
function (k)
kh = k * Δt / 2
s = sin(kh) / kh
n = 2M
Expand Down
6 changes: 2 additions & 4 deletions src/Kernels/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ function optimal_kernel(kernel::GaussianKernel, h::HalfSupport{M}, Δx, σ; back
GaussianKernelData(h, backend, Δx, ℓ)
end

# This should work on CPU and GPU.
function evaluate_fourier!(g::GaussianKernelData, gk::AbstractVector, ks::AbstractVector)
function evaluate_fourier_func(g::GaussianKernelData)
(; τ,) = g
@assert eachindex(gk) == eachindex(ks)
map!(gk, ks) do k
function (k)
exp(-τ * k^2 / 4) * sqrt* τ) # = exp(-σ² k² / 2) * sqrt(2πσ²)
end
end
Expand Down
6 changes: 2 additions & 4 deletions src/Kernels/kaiser_bessel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ function optimal_kernel(kernel::KaiserBesselKernel, h::HalfSupport{M}, Δx, σ;
KaiserBesselKernelData(h, backend, Δx, β)
end

# This should work on CPU and GPU.
function evaluate_fourier!(g::KaiserBesselKernelData, gk::AbstractVector, ks::AbstractVector)
@assert eachindex(gk) == eachindex(ks)
function evaluate_fourier_func(g::KaiserBesselKernelData)
(; β², w,) = g
map!(gk, ks) do k
function (k)
q = w * k
s = sqrt(β² - q^2) # this is always real (assuming β ≥ Mπ)
2 * w * sinh(s) / s
Expand Down
6 changes: 2 additions & 4 deletions src/Kernels/kaiser_bessel_backwards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ function optimal_kernel(kernel::BackwardsKaiserBesselKernel, h::HalfSupport{M},
BackwardsKaiserBesselKernelData(h, backend, Δx, β)
end

# This should work on CPU and GPU.
function evaluate_fourier!(g::BackwardsKaiserBesselKernelData, gk::AbstractVector, ks::AbstractVector)
@assert eachindex(gk) == eachindex(ks)
function evaluate_fourier_func(g::BackwardsKaiserBesselKernelData)
(; β, w,) = g
map!(gk, ks) do k
function (k)
q = w * k
s = sqrt^2 - q^2) # this is always real (assuming β ≥ Mπ)
w * besseli0(s)
Expand Down

0 comments on commit ab21f69

Please sign in to comment.