Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant argument checking for out-of-place nufftndm calls #46

Closed
jkrimmer opened this issue Sep 1, 2022 · 1 comment
Closed

Redundant argument checking for out-of-place nufftndm calls #46

jkrimmer opened this issue Sep 1, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@jkrimmer
Copy link
Contributor

jkrimmer commented Sep 1, 2022

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

@ludvigak ludvigak added the enhancement New feature or request label Sep 2, 2022
@jkrimmer
Copy link
Contributor Author

As far as I can tell, this issue can be closed with the merge of #47.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants