Skip to content

Commit

Permalink
Use similar in creation of DiffResults buffer (#95)
Browse files Browse the repository at this point in the history
* use similar in creation of diffresults buffer
* use the input to make the DiffResults buffer
* remove the logdensity argument from _diffresults_buffer
* removed type-annotation
* patch version bump
  • Loading branch information
torfjelde authored Nov 22, 2022
1 parent a6a5707 commit d4f03be
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LogDensityProblems"
uuid = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
authors = ["Tamas K. Papp <[email protected]>"]
version = "1.0.2"
version = "1.0.3"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
2 changes: 1 addition & 1 deletion src/AD_ForwardDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

function logdensity_and_gradient(fℓ::ForwardDiffLogDensity, x::AbstractVector)
@unpack ℓ, gradientconfig = fℓ
buffer = _diffresults_buffer(ℓ, x)
buffer = _diffresults_buffer(x)
result = ForwardDiff.gradient!(buffer, Base.Fix1(logdensity, ℓ), x, gradientconfig)
_diffresults_extract(result)
end
2 changes: 1 addition & 1 deletion src/AD_ReverseDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end

function logdensity_and_gradient(∇ℓ::ReverseDiffLogDensity, x::AbstractVector)
@unpack ℓ, compiledtape = ∇ℓ
buffer = _diffresults_buffer(ℓ, x)
buffer = _diffresults_buffer(x)
if compiledtape === nothing
result = ReverseDiff.gradient!(buffer, Base.Fix1(logdensity, ℓ), x)
else
Expand Down
6 changes: 3 additions & 3 deletions src/DiffResults_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ $(SIGNATURES)
Allocate a DiffResults buffer for a gradient, taking the element type of `x` into account
(heuristically).
"""
function _diffresults_buffer(ℓ, x)
function _diffresults_buffer(x)
T = eltype(x)
S = T <: Real ? float(Real) : Float64 # heuristic
DiffResults.MutableDiffResult(zero(S), (Vector{S}(undef, dimension(ℓ)), ))
DiffResults.MutableDiffResult(zero(S), (similar(x, S), ))
end

"""
Expand All @@ -25,5 +25,5 @@ constructed with [`diffresults_buffer`](@ref). Gradient is not copied as caller
vector.
"""
function _diffresults_extract(diffresult::DiffResults.DiffResult)
DiffResults.value(diffresult)::Real, DiffResults.gradient(diffresult)
DiffResults.value(diffresult), DiffResults.gradient(diffresult)
end

2 comments on commit d4f03be

@tpapp
Copy link
Owner

@tpapp tpapp commented on d4f03be Nov 22, 2022

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 created: JuliaRegistries/General/72639

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 v1.0.3 -m "<description of version>" d4f03be595b4d99a26c45ecbdb507bd3ed11358f
git push origin v1.0.3

Please sign in to comment.