Skip to content

Commit aa4338f

Browse files
authored
Merge branch 'master' into roots.jl
2 parents 9374853 + a1010e4 commit aa4338f

20 files changed

+277
-111
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Distributions"
22
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
33
authors = ["JuliaStats"]
4-
version = "0.25.111"
4+
version = "0.25.112"
55

66
[deps]
77
AliasTables = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"

src/Distributions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export
129129
MatrixBeta,
130130
MatrixFDist,
131131
MatrixNormal,
132-
MatrixReshaped,
133132
MatrixTDist,
134133
MixtureModel,
135134
Multinomial,

src/deprecates.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,20 @@ end
5353
@deprecate expectation(distr::Union{UnivariateDistribution,MultivariateDistribution}, g::Function; kwargs...) expectation(g, distr; kwargs...) false
5454

5555
# Deprecate `MatrixReshaped`
56+
# This is very similar to `Base.@deprecate_binding MatrixReshaped{...} ReshapedDistribution{...}`
57+
# However, `Base.@deprecate_binding` does not support type parameters
58+
export MatrixReshaped
5659
const MatrixReshaped{S<:ValueSupport,D<:MultivariateDistribution{S}} = ReshapedDistribution{2,S,D}
5760
Base.deprecate(@__MODULE__, :MatrixReshaped)
58-
@deprecate MatrixReshaped(
59-
d::MultivariateDistribution, n::Integer, p::Integer=n
60-
) reshape(d, (n, p))
61+
# This is very similar to `Base.@deprecate MatrixReshaped(...) reshape(...)`
62+
# We use another (unexported!) alias here to not throw a deprecation warning/error
63+
# Unexported aliases do not affect the type printing
64+
# In Julia >= 1.6, instead of a new alias we could have defined a method for (ReshapedDistribution{2,S,D} where {S<:ValueSupport,D<:MultivariateDistribution{S}})
65+
const _MatrixReshaped{S<:ValueSupport,D<:MultivariateDistribution{S}} = ReshapedDistribution{2,S,D}
66+
function _MatrixReshaped(d::MultivariateDistribution, n::Integer, p::Integer=n)
67+
Base.depwarn("`MatrixReshaped(d, n, p)` is deprecated, use `reshape(d, (n, p))` instead.", :MatrixReshaped)
68+
return reshape(d, (n, p))
69+
end
6170

6271
for D in (:InverseWishart, :LKJ, :MatrixBeta, :MatrixFDist, :Wishart)
6372
@eval @deprecate dim(d::$D) size(d, 1)

src/univariate/continuous/exponential.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ cf(d::Exponential, t::Real) = 1/(1 - t * im * scale(d))
107107
#### Sampling
108108
rand(rng::AbstractRNG, d::Exponential{T}) where {T} = xval(d, randexp(rng, float(T)))
109109

110+
function rand!(rng::AbstractRNG, d::Exponential, A::AbstractArray{<:Real})
111+
randexp!(rng, A)
112+
map!(Base.Fix1(xval, d), A, A)
113+
return A
114+
end
110115

111116
#### Fit model
112117

src/univariate/continuous/logitnormal.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ end
157157

158158
#### Sampling
159159

160-
rand(rng::AbstractRNG, d::LogitNormal) = logistic(randn(rng) * d.σ + d.μ)
160+
xval(d::LogitNormal, z::Real) = logistic(muladd(d.σ, z, d.μ))
161+
162+
rand(rng::AbstractRNG, d::LogitNormal) = xval(d, randn(rng))
163+
function rand!(rng::AbstractRNG, d::LogitNormal, A::AbstractArray{<:Real})
164+
randn!(rng, A)
165+
map!(Base.Fix1(xval, d), A, A)
166+
return A
167+
end
161168

162169
## Fitting
163170

src/univariate/continuous/lognormal.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@ end
156156

157157
#### Sampling
158158

159-
rand(rng::AbstractRNG, d::LogNormal) = exp(randn(rng) * d.σ + d.μ)
159+
xval(d::LogNormal, z::Real) = exp(muladd(d.σ, z, d.μ))
160+
161+
rand(rng::AbstractRNG, d::LogNormal) = xval(d, randn(rng))
162+
function rand!(rng::AbstractRNG, d::LogNormal, A::AbstractArray{<:Real})
163+
randn!(rng, A)
164+
map!(Base.Fix1(xval, d), A, A)
165+
return A
166+
end
160167

161168
## Fitting
162169

src/univariate/continuous/normal.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ Base.:*(c::Real, d::Normal) = Normal(c * d.μ, abs(c) * d.σ)
114114

115115
#### Sampling
116116

117-
rand(rng::AbstractRNG, d::Normal{T}) where {T} = d.μ + d.σ * randn(rng, float(T))
117+
xval(d::Normal, z::Real) = muladd(d.σ, z, d.μ)
118118

119-
rand!(rng::AbstractRNG, d::Normal, A::AbstractArray{<:Real}) = A .= muladd.(d.σ, randn!(rng, A), d.μ)
119+
rand(rng::AbstractRNG, d::Normal{T}) where {T} = xval(d, randn(rng, float(T)))
120+
function rand!(rng::AbstractRNG, d::Normal, A::AbstractArray{<:Real})
121+
randn!(rng, A)
122+
map!(Base.Fix1(xval, d), A, A)
123+
return A
124+
end
120125

121126
#### Fitting
122127

src/univariate/continuous/normalcanon.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ invlogccdf(d::NormalCanon, lp::Real) = xval(d, norminvlogccdf(lp))
8787

8888
#### Sampling
8989

90-
rand(rng::AbstractRNG, cf::NormalCanon) = cf.μ + randn(rng) / sqrt(cf.λ)
90+
rand(rng::AbstractRNG, cf::NormalCanon) = xval(cf, randn(rng))
91+
92+
function rand!(rng::AbstractRNG, cf::NormalCanon, A::AbstractArray{<:Real})
93+
randn!(rng, A)
94+
map!(Base.Fix1(xval, cf), A, A)
95+
return A
96+
end
9197

9298
#### Affine transformations
9399

src/univariate/continuous/pareto.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ quantile(d::Pareto, p::Real) = cquantile(d, 1 - p)
110110

111111
#### Sampling
112112

113-
rand(rng::AbstractRNG, d::Pareto) = d.θ * exp(randexp(rng) / d.α)
113+
xval(d::Pareto, z::Real) = d.θ * exp(z / d.α)
114+
115+
rand(rng::AbstractRNG, d::Pareto) = xval(d, randexp(rng))
116+
function rand!(rng::AbstractRNG, d::Pareto, A::AbstractArray{<:Real})
117+
randexp!(rng, A)
118+
map!(Base.Fix1(xval, d), A, A)
119+
return A
120+
end
114121

115122
## Fitting
116123

src/univariate/continuous/pgeneralizedgaussian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function rand(rng::AbstractRNG, d::PGeneralizedGaussian)
141141
inv_p = inv(d.p)
142142
g = Gamma(inv_p, 1)
143143
z = d.α * rand(rng, g)^inv_p
144-
if rand(rng) < 0.5
144+
if rand(rng, Bool)
145145
return d.μ - z
146146
else
147147
return d.μ + z

0 commit comments

Comments
 (0)