Skip to content

Commit 074af7f

Browse files
authored
Do not use internal functions from Distributions (#208)
1 parent 0cbe98f commit 074af7f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributionsAD"
22
uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
3-
version = "0.6.33"
3+
version = "0.6.34"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/multivariate.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ function Distributions._rand!(
4545
@inbounds for (i, αi) in zip(eachindex(x), d.alpha)
4646
x[i] = rand(rng, Gamma(αi))
4747
end
48-
Distributions.multiply!(x, inv(sum(x))) # this returns x
48+
lmul!(inv(sum(x)), x) # this returns x
4949
end
5050
function Distributions._rand!(
5151
rng::AbstractRNG,
5252
d::TuringDirichlet{<:Real,<:FillArrays.AbstractFill},
5353
x::AbstractVector{<:Real}
5454
)
5555
rand!(rng, Gamma(FillArrays.getindex_value(d.alpha)), x)
56-
Distributions.multiply!(x, inv(sum(x))) # this returns x
56+
lmul!(inv(sum(x)), x) # this returns x
5757
end
5858

5959
function Distributions._logpdf(d::TuringDirichlet, x::AbstractVector{<:Real})
@@ -246,10 +246,14 @@ MvLogNormal(d::TuringDiagMvNormal) = TuringMvLogNormal(d)
246246
MvLogNormal(d::TuringScalMvNormal) = TuringMvLogNormal(d)
247247
Distributions.length(d::TuringMvLogNormal) = length(d.normal)
248248
function Distributions.rand(rng::Random.AbstractRNG, d::TuringMvLogNormal)
249-
return Distributions.exp!(rand(rng, d.normal))
249+
x = rand(rng, d.normal)
250+
map!(exp, x, x)
251+
return x
250252
end
251253
function Distributions.rand(rng::Random.AbstractRNG, d::TuringMvLogNormal, n::Int)
252-
return Distributions.exp!(rand(rng, d.normal, n))
254+
x = rand(rng, d.normal, n)
255+
map!(exp, x, x)
256+
return x
253257
end
254258

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

0 commit comments

Comments
 (0)