Skip to content

Commit

Permalink
Don't depend on ChainRules internals (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmheim authored Dec 11, 2020
1 parent ef1ffba commit beddedd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 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.12"
version = "0.6.13"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
36 changes: 10 additions & 26 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,28 @@ function turing_chol(A::AbstractMatrix, check)
chol = cholesky(A, check=check)
(chol.factors, chol.info)
end
function ChainRules.rrule(::typeof(turing_chol), A::AbstractMatrix, check)
factors, info = turing_chol(A, check)
function turing_chol_pullback(Ȳ)
= Ȳ[1]
∂A = ChainRules.chol_blocked_rev(f̄, factors, 25, true)
return (ChainRules.NO_FIELDS, ∂A, ChainRules.DoesNotExist())
end
(factors,info), turing_chol_pullback
end
function turing_chol_back(A::AbstractMatrix, check)
C, dC_pullback = rrule(turing_chol, A, check)
C, chol_pullback = rrule(cholesky, A, Val(false), check=check)
function back(Δ)
_, dC = dC_pullback(Δ)
(dC, nothing)
= Composite{typeof(C)}((U=Δ[1]))
∂C = chol_pullback(Ȳ)[2]
(∂C, nothing)
end
C, back
(C.factors,C.info), back
end

function symm_turing_chol(A::AbstractMatrix, check, uplo)
chol = cholesky(Symmetric(A, uplo), check=check)
(chol.factors, chol.info)
end
function ChainRules.rrule(::typeof(symm_turing_chol), A::AbstractMatrix, check, uplo)
factors, info = symm_turing_chol(A, check, uplo)
function symm_turing_chol_pullback(Ȳ)
= Ȳ[1]
∂A = ChainRules.chol_blocked_rev(f̄, factors, 25, true)
return (ChainRules.NO_FIELDS, ∂A, ChainRules.DoesNotExist(), ChainRules.DoesNotExist())
end
return (factors,info), symm_turing_chol_pullback
end
function symm_turing_chol_back(A::AbstractMatrix, check, uplo)
C, dC_pullback = rrule(symm_turing_chol, A, check, uplo)
C, chol_pullback = rrule(cholesky, Symmetric(A,uplo), Val(false), check=check)
function back(Δ)
_, dC = dC_pullback(Δ)
(dC, nothing, nothing)
= Composite{typeof(C)}((U=Δ[1]))
∂C = chol_pullback(Ȳ)[2]
(∂C, nothing, nothing)
end
C, back
(C.factors, C.info), back
end


Expand Down

2 comments on commit beddedd

@devmotion
Copy link
Member

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/26259

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.13 -m "<description of version>" beddedd3b424bfbcded1ff5c676173f3210f7b50
git push origin v0.6.13

Please sign in to comment.