Skip to content

Commit

Permalink
Test 1D transforms with AbstractNFFTs interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jipolanco committed Sep 14, 2024
1 parent 319e2b6 commit c7e8699
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions test/abstractNFFTs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ using Random: Random
using NonuniformFFTs
using NFFT: NFFT, size_in, size_out

Ns = (64, 81) # number of Fourier modes in each direction (test odd sizes as well)
Np = 1000 # number of non-uniform points
function compare_with_nfft(Ns; Np = 1000)
rng = Random.Xoshiro(43)
T = Float64 # must be a real data type (Float32, Float64)
d = length(Ns) # number of dimensions
xp = rand(rng, T, (d, Np)) .- T(0.5) # non-uniform points in [-1/2, 1/2)ᵈ; must be given as a (d, Np) matrix
vp = randn(rng, Complex{T}, Np) # random values at points (must be complex)

rng = Random.Xoshiro(43)
T = Float64 # must be a real data type (Float32, Float64)
d = length(Ns) # number of dimensions (d = 2 here)
xp = rand(rng, T, (d, Np)) .- T(0.5) # non-uniform points in [-1/2, 1/2)ᵈ; must be given as a (d, Np) matrix
vp = randn(rng, Complex{T}, Np) # random values at points (must be complex)
reltol = 1e-9
window = :kaiser_bessel

reltol = 1e-9
window = :kaiser_bessel
p = PlanNUFFT(xp, Ns; reltol, window,)
p_nfft = NFFT.NFFTPlan(xp, Ns; reltol, window,)

p = PlanNUFFT(xp, Ns; reltol, window,)
p_nfft = NFFT.NFFTPlan(xp, Ns; reltol, window,)
@test startswith(repr(p), "$(d)-dimensional PlanNUFFT with input type $(Complex{T}):") # test pretty-printing

@test startswith(repr(p), "2-dimensional PlanNUFFT with input type ComplexF64:") # test pretty-printing

@testset "Comparison with NFFT.jl" begin
@test size_in(p) === size_in(p_nfft)
@test size_out(p) === size_out(p_nfft)

Expand All @@ -35,4 +32,16 @@ p_nfft = NFFT.NFFTPlan(xp, Ns; reltol, window,)
wp = p * us
wp_nfft = p_nfft * us
@test wp wp_nfft

nothing
end

@testset "Comparison with NFFT.jl" begin
dims_tested = [
(512,), # 1D
(64, 81), # 2D (we test odd sizes as well)
]
@testset "Dimensions: $dims" for dims dims_tested
compare_with_nfft(dims)
end
end

0 comments on commit c7e8699

Please sign in to comment.