FINUFFT.jl icon indicating copy to clipboard operation
FINUFFT.jl copied to clipboard

Redundant argument checking for out-of-place nufftndm calls

Open jkrimmer opened this issue 2 years ago • 0 comments

Taking care of the discussed changes with respect to the dtype keyword argument, I noticed that the out-of-place nufftndm calls essentially validate their arguments twice since valid_setpts, valid_ntr, and checkkwdtype are called a second time within the nufftndm! functions. Wouldn't it make sense to remove these checks from the out-of-place functions and simplify them to something like the following?

function nufft3d3(xj      :: Array{T},
                  yj      :: Array{T},
                  zj      :: Array{T},                   
                  cj      :: Array{Complex{T}}, 
                  iflag   :: Integer, 
                  eps     :: Real,
                  sk      :: Array{T},
                  tk      :: Array{T},
                  uk      :: Array{T};
                  kwargs...) where T <: finufftReal
    ntrans = valid_ntr(xj,cj)
    fk = Array{Complex{T}}(undef, nk, ntrans)
    nufft3d3!(xj, yj, zj, cj, iflag, eps, sk, tk, uk, fk; kwargs...)
    return fk
end

Currently, the function looks like

function nufft3d3(xj      :: Array{T},
                  yj      :: Array{T},
                  zj      :: Array{T},                   
                  cj      :: Array{Complex{T}}, 
                  iflag   :: Integer, 
                  eps     :: Real,
                  sk      :: Array{T},
                  tk      :: Array{T},
                  uk      :: Array{T};
                  kwargs...) where T <: finufftReal
    (nj, nk) = valid_setpts(3,3,xj,yj,zj,sk,tk,uk)
    ntrans = valid_ntr(xj,cj)
    fk = Array{Complex{T}}(undef, nk, ntrans)
    checkkwdtype(T; kwargs...)
    nufft3d3!(xj, yj, zj, cj, iflag, eps, sk, tk, uk, fk;kwargs...)
    return fk
end

with the in-place method

function nufft3d3!(xj      :: Array{T}, 
                   yj      :: Array{T},
                   zj      :: Array{T},                   
                   cj      :: Array{Complex{T}}, 
                   iflag   :: Integer, 
                   eps     :: Real,
                   sk      :: Array{T},
                   tk      :: Array{T},
                   uk      :: Array{T},
                   fk      :: Array{Complex{T}};
                   kwargs...) where T <: finufftReal
    (nj, nk) = valid_setpts(3,3,xj,yj,zj,sk,tk,uk)
    ntrans = valid_ntr(xj,cj)

    checkkwdtype(T; kwargs...)
    plan = finufft_makeplan(3,3,iflag,ntrans,eps;dtype=T,kwargs...)
    finufft_setpts!(plan,xj,yj,zj,sk,tk,uk)
    finufft_exec!(plan,cj,fk)
    ret = finufft_destroy!(plan)
    check_ret(ret)
end

jkrimmer avatar Sep 01 '22 09:09 jkrimmer