Skip to content

Commit

Permalink
Remove pullback for Wishart (#212)
Browse files Browse the repository at this point in the history
* Remove pullback for `Wishart`

* Update Project.toml
  • Loading branch information
devmotion authored Jan 26, 2022
1 parent 9461c6b commit 1a3a50b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 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.36"
version = "0.6.37"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
24 changes: 0 additions & 24 deletions src/zygote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,6 @@ end

## Wishart ##

# Custom adjoint since Zygote can't differentiate through `@warn`
# TODO: Remove when fixed upstream in Distributions
ZygoteRules.@adjoint function Wishart(df::T, S::AbstractPDMat{T}, warn::Bool = true) where T<:Real
function _Wishart(df::T, S::AbstractPDMat{T}, warn::Bool = true) where T
df > 0 || throw(ArgumentError("df must be positive. got $(df)."))
p = dim(S)
rnk = p
singular = df <= p - 1
if singular
isinteger(df) || throw(ArgumentError("singular df must be an integer. got $(df)."))
rnk = convert(Integer, df)
warn && _warn("got df <= dim - 1; returning a singular Wishart")
end
logc0 = Distributions.wishart_logc0(df, S, rnk)
R = Base.promote_eltype(T, logc0)
prom_S = convert(AbstractArray{T}, S)
Wishart{R, typeof(prom_S), typeof(rnk)}(R(df), prom_S, R(logc0), rnk, singular)
end
return ZygoteRules.pullback(_Wishart, df, S, warn)
end

_warn(msg) = @warn(msg)
@non_differentiable _warn(msg)

ZygoteRules.@adjoint function Distributions.Wishart(df::Real, S::AbstractMatrix{<:Real})
return ZygoteRules.pullback(TuringWishart, df, S)
end
Expand Down

2 comments on commit 1a3a50b

@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/53211

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.37 -m "<description of version>" 1a3a50b8f8ba06152c1feba3492962c08e55ac14
git push origin v0.6.37

Please sign in to comment.