Skip to content

Commit

Permalink
Replace broadcasting over distributions with broadcasting with partia…
Browse files Browse the repository at this point in the history
…lly applied functions
  • Loading branch information
devmotion committed Jan 4, 2024
1 parent 9e72f1f commit c7b9218
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 77 deletions.
8 changes: 4 additions & 4 deletions src/deprecates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ for fun in [:pdf, :logpdf,
fun! = Symbol(fun, '!')

@eval begin
@deprecate ($_fun!)(r::AbstractArray{<:Real}, d::UnivariateDistribution, X::AbstractArray{<:Real}) r .= ($fun).(d, X) false
@deprecate ($fun!)(r::AbstractArray{<:Real}, d::UnivariateDistribution, X::AbstractArray{<:Real}) r .= ($fun).(d, X) false
@deprecate ($fun)(d::UnivariateDistribution, X::AbstractArray{<:Real}) ($fun).(d, X)
@deprecate ($_fun!)(r::AbstractArray{<:Real}, d::UnivariateDistribution, X::AbstractArray{<:Real}) r .= Base.Fix1($fun, d).(X) false
@deprecate ($fun!)(r::AbstractArray{<:Real}, d::UnivariateDistribution, X::AbstractArray{<:Real}) r .= Base.Fix1($fun, d).(X) false
@deprecate ($fun)(d::UnivariateDistribution, X::AbstractArray{<:Real}) map(Base.Fix1($fun, d), X)
end
end

@deprecate pdf(d::DiscreteUnivariateDistribution) pdf.(Ref(d), support(d))
@deprecate pdf(d::DiscreteUnivariateDistribution) map(Base.Fix1(pdf, d), support(d))

# Wishart constructors
@deprecate Wishart(df::Real, S::AbstractPDMat, warn::Bool) Wishart(df, S)
Expand Down
8 changes: 4 additions & 4 deletions src/mixtures/mixturemodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function _mixpdf!(r::AbstractArray, d::AbstractMixtureModel, x)
pi = p[i]
if pi > 0.0
if d isa UnivariateMixture
t .= pdf.(component(d, i), x)
t .= Base.Fix1(pdf, component(d, i)).(x)
else
pdf!(t, component(d, i), x)
end
Expand Down Expand Up @@ -326,7 +326,7 @@ function _mixlogpdf!(r::AbstractArray, d::AbstractMixtureModel, x)
lp_i = view(Lp, :, i)
# compute logpdf in batch and store
if d isa UnivariateMixture
lp_i .= logpdf.(component(d, i), x)
lp_i .= Base.Fix1(logpdf, component(d, i)).(x)
else
logpdf!(lp_i, component(d, i), x)
end
Expand Down Expand Up @@ -398,7 +398,7 @@ function _cwise_pdf!(r::AbstractMatrix, d::AbstractMixtureModel, X)
size(r) == (n, K) || error("The size of r is incorrect.")
for i = 1:K
if d isa UnivariateMixture
view(r,:,i) .= pdf.(Ref(component(d, i)), X)
view(r,:,i) .= Base.Fix1(pdf, component(d, i)).(X)
else
pdf!(view(r,:,i),component(d, i), X)
end
Expand All @@ -412,7 +412,7 @@ function _cwise_logpdf!(r::AbstractMatrix, d::AbstractMixtureModel, X)
size(r) == (n, K) || error("The size of r is incorrect.")
for i = 1:K
if d isa UnivariateMixture
view(r,:,i) .= logpdf.(Ref(component(d, i)), X)
view(r,:,i) .= Base.Fix1(logpdf, component(d, i)).(X)
else
logpdf!(view(r,:,i), component(d, i), X)
end
Expand Down
2 changes: 1 addition & 1 deletion src/multivariate/jointorderstatistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function _rand!(rng::AbstractRNG, d::JointOrderStatistics, x::AbstractVector{<:R
else
s += randexp(rng, T)
end
x .= quantile.(d.dist, x ./ s)
x .= Base.Fix1(quantile, d.dist).(x ./ s)
end
return x
end
Loading

0 comments on commit c7b9218

Please sign in to comment.