Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecations #229

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.42"
version = "0.6.43"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AD of `logpdf` is fully supported and tested for the following distributions wrt
- `Chi`
- `Chisq`
- `Cosine`
- `Distributions.AffineDistribution`
- `Epanechnikov`
- `Erlang`
- `Exponential`
Expand All @@ -38,7 +39,6 @@ AD of `logpdf` is fully supported and tested for the following distributions wrt
- `Kolmogorov`
- `Laplace`
- `Levy`
- `LocationScale`
- `Logistic`
- `LogitNormal`
- `LogNormal`
Expand Down
6 changes: 4 additions & 2 deletions src/common.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## Linear Algebra ##

const CHOLESKY_NoPivot = VERSION >= v"1.8.0-rc1" ? LinearAlgebra.NoPivot() : Val(false)

function turing_chol(A::AbstractMatrix, check)
chol = cholesky(A, check=check)
(chol.factors, chol.info)
end
function turing_chol_back(A::AbstractMatrix, check)
C, chol_pullback = rrule(cholesky, A, Val(false), check=check)
C, chol_pullback = rrule(cholesky, A, CHOLESKY_NoPivot; check=check)
function back(Δ)
Ȳ = Tangent{typeof(C)}(; factors=Δ[1])
∂C = chol_pullback(Ȳ)[2]
Expand All @@ -19,7 +21,7 @@ function symm_turing_chol(A::AbstractMatrix, check, uplo)
(chol.factors, chol.info)
end
function symm_turing_chol_back(A::AbstractMatrix, check, uplo)
C, chol_pullback = rrule(cholesky, Symmetric(A,uplo), Val(false), check=check)
C, chol_pullback = rrule(cholesky, Symmetric(A,uplo), CHOLESKY_NoPivot; check=check)
function back(Δ)
Ȳ = Tangent{typeof(C)}(; factors=Δ[1])
∂C = chol_pullback(Ȳ)[2]
Expand Down
2 changes: 1 addition & 1 deletion src/flatten.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const flattened_dists = [ Bernoulli,
Kolmogorov,
Laplace,
Levy,
LocationScale,
Distributions.AffineDistribution,
Logistic,
LogitNormal,
LogNormal,
Expand Down
4 changes: 2 additions & 2 deletions src/reversediff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ function Gamma(α::T, θ::T; check_args=true) where {T <: TrackedReal}
end

# Work around to stop TrackedReal of Inf and -Inf from producing NaN in the derivative
function Base.minimum(d::LocationScale{T}) where {T <: TrackedReal}
function Base.minimum(d::Distributions.AffineDistribution{T}) where {T <: TrackedReal}
if isfinite(minimum(d.ρ))
return d.μ + d.σ * minimum(d.ρ)
else
return convert(T, ReverseDiff.@skip(minimum)(d.ρ))
end
end
function Base.maximum(d::LocationScale{T}) where {T <: TrackedReal}
function Base.maximum(d::Distributions.AffineDistribution{T}) where {T <: TrackedReal}
if isfinite(minimum(d.ρ))
return d.μ + d.σ * maximum(d.ρ)
else
Expand Down
3 changes: 2 additions & 1 deletion test/ad/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@
DistSpec(Levy, (0.0,), 0.5),
DistSpec(Levy, (0.0, 2.0), 0.5),

DistSpec((a, b) -> LocationScale(a, b, Normal()), (1.0, 2.0), 0.5),
# Test AffineDistribution
DistSpec((a, b) -> a + b * Beta(), (1.0, 2.0), 2.0),
devmotion marked this conversation as resolved.
Show resolved Hide resolved

DistSpec(Logistic, (), 0.5),
DistSpec(Logistic, (1.0,), 0.5),
Expand Down