Skip to content

Commit

Permalink
Use Val(true) in G_to_r to help const-prop (JuliaMolSim#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine-levitt authored Feb 25, 2022
1 parent 012ce66 commit 8eadc55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ Perform an iFFT to obtain the quantity defined by `f_fourier` defined
on the k-dependent spherical basis set (if `kpt` is given) or the
k-independent cubic (if it is not) on the real-space grid.
"""
function G_to_r(basis::PlaneWaveBasis, f_fourier::AbstractArray; assume_real=true)
function G_to_r(basis::PlaneWaveBasis, f_fourier::AbstractArray; assume_real=Val(true))
# assume_real is true by default because this is the most common usage
# (for densities & potentials)
# (for densities & potentials). Val(true) to help const-prop;
# see https://github.com/JuliaLang/julia/issues/44330
f_real = similar(f_fourier)
@assert length(size(f_fourier)) (3, 4)
# this exploits trailing index convention
for= 1:size(f_fourier, 4)
@views G_to_r!(f_real[:, :, :, iσ], basis, f_fourier[:, :, :, iσ])
end
assume_real ? real(f_real) : f_real
(assume_real == Val(true)) ? real(f_real) : f_real
end
function G_to_r(basis::PlaneWaveBasis, kpt::Kpoint, f_fourier::AbstractVector; kwargs...)
G_to_r!(similar(f_fourier, basis.fft_size...), basis, kpt, f_fourier; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion test/fourier_transforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include("testcases.jl")
G_to_r!(f_R, pw, f_G)

f2_G = r_to_G(pw, f_R)
f2_R = G_to_r(pw, f2_G; assume_real=false)
f2_R = G_to_r(pw, f2_G; assume_real=Val(false))
f3_G = r_to_G!(similar(f_R), pw, f_R)

@test maximum(abs.(f2_G - f_G)) < 1e-12
Expand Down

0 comments on commit 8eadc55

Please sign in to comment.