Skip to content

Commit

Permalink
Merge pull request #16 from JuliaMolSim/allow_preallocation
Browse files Browse the repository at this point in the history
Allow preallocation of output arguments
  • Loading branch information
mfherbst authored Jun 4, 2020
2 parents 52bfbf1 + 063acc2 commit abee8ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/evaluate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,23 @@ function evaluate(func::Functional; derivatives=1, rho::AbstractArray, kwargs...
end
end

outargs = Dict{Symbol, AbstractArray}(:zk => similar(rho, shape))
for symbol in vcat(ARGUMENTS[func.family][1:derivatives]...)
n_spin = getfield(func.spin_dimensions, symbol)
if n_spin > 1
outargs[symbol] = similar(rho, n_spin, shape...)
outargs_allocated = Dict{Symbol, AbstractArray}()
outargs = Dict{Symbol, AbstractArray}()
for symbol in vcat(:zk, ARGUMENTS[func.family][1:derivatives]...)
if symbol in keys(kwargs)
outargs_allocated[symbol] = kwargs[symbol]
else
outargs[symbol] = similar(rho, shape...)
n_spin = getfield(func.spin_dimensions, symbol)
if n_spin > 1
outargs[symbol] = similar(rho, n_spin, shape...)
else
outargs[symbol] = similar(rho, shape)
end
end
end

evaluate!(func; rho=rho, kwargs..., outargs...)
(; outargs...)
(; outargs..., outargs_allocated...)
end


Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end

# LSDA
for sym in (:lda_x, :lda_c_vwn)
res = evaluate(Functional(sym, n_spin=1), rho=rho)
res = evaluate(Functional(sym, n_spin=1), rho=rho, zk=zeros(shape))
@test size(res.zk) == shape
@test size(res.vrho) == shape

Expand Down

2 comments on commit abee8ca

@mfherbst
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/15839

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" abee8ca42973eb898ea17d3fea8ce124a2c5f546
git push origin v0.3.1

Please sign in to comment.