Skip to content

Commit

Permalink
Do not use internal functions from Distributions (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Nov 26, 2021
1 parent 0cbe98f commit 074af7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DistributionsAD"
uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
version = "0.6.33"
version = "0.6.34"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
12 changes: 8 additions & 4 deletions src/multivariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ function Distributions._rand!(
@inbounds for (i, αi) in zip(eachindex(x), d.alpha)
x[i] = rand(rng, Gamma(αi))
end
Distributions.multiply!(x, inv(sum(x))) # this returns x
lmul!(inv(sum(x)), x) # this returns x
end
function Distributions._rand!(
rng::AbstractRNG,
d::TuringDirichlet{<:Real,<:FillArrays.AbstractFill},
x::AbstractVector{<:Real}
)
rand!(rng, Gamma(FillArrays.getindex_value(d.alpha)), x)
Distributions.multiply!(x, inv(sum(x))) # this returns x
lmul!(inv(sum(x)), x) # this returns x
end

function Distributions._logpdf(d::TuringDirichlet, x::AbstractVector{<:Real})
Expand Down Expand Up @@ -246,10 +246,14 @@ MvLogNormal(d::TuringDiagMvNormal) = TuringMvLogNormal(d)
MvLogNormal(d::TuringScalMvNormal) = TuringMvLogNormal(d)
Distributions.length(d::TuringMvLogNormal) = length(d.normal)
function Distributions.rand(rng::Random.AbstractRNG, d::TuringMvLogNormal)
return Distributions.exp!(rand(rng, d.normal))
x = rand(rng, d.normal)
map!(exp, x, x)
return x
end
function Distributions.rand(rng::Random.AbstractRNG, d::TuringMvLogNormal, n::Int)
return Distributions.exp!(rand(rng, d.normal, n))
x = rand(rng, d.normal, n)
map!(exp, x, x)
return x
end

function Distributions._logpdf(d::TuringMvLogNormal, x::AbstractVector{T}) where {T<:Real}
Expand Down

2 comments on commit 074af7f

@devmotion
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 created: JuliaRegistries/General/49450

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.6.34 -m "<description of version>" 074af7f3a22e808158adc51e5640ec0ca6584e73
git push origin v0.6.34

Please sign in to comment.