-
Notifications
You must be signed in to change notification settings - Fork 92
Add rules for det
and logdet
of Cholesky
#613
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
Changes from 8 commits
54995d6
ac246e7
40e0890
e7e929b
92385c9
6d11837
c4f0d7a
1482a95
d831cd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,3 +551,31 @@ function rrule(::typeof(getproperty), F::T, x::Symbol) where {T <: Cholesky} | |
end | ||
return getproperty(F, x), getproperty_cholesky_pullback | ||
end | ||
|
||
# `det` and `logdet` for `Cholesky` | ||
function rrule(::typeof(det), C::Cholesky) | ||
y = det(C) | ||
diagF = _diag_view(C.factors) | ||
function det_Cholesky_pullback(ȳ) | ||
ΔF = Diagonal(_x_divide_conj_y.(2 * ȳ * conj(y), diagF)) | ||
ΔC = Tangent{typeof(C)}(; factors=ΔF) | ||
return NoTangent(), ΔC | ||
end | ||
return y, det_Cholesky_pullback | ||
end | ||
# compute `x / conj(y)`, handling `x = y = 0` | ||
function _x_divide_conj_y(x, y) | ||
z = x / conj(y) | ||
# in our case `iszero(x)` implies `iszero(y)` | ||
return iszero(x) ? zero(z) : z | ||
end | ||
devmotion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
function rrule(::typeof(logdet), C::Cholesky) | ||
y = logdet(C) | ||
diagF = _diag_view(C.factors) | ||
function logdet_Cholesky_pullback(ȳ) | ||
ΔC = Tangent{typeof(C)}(; factors=Diagonal((2 * ȳ) ./ conj.(diagF))) | ||
|
||
return NoTangent(), ΔC | ||
end | ||
return y, logdet_Cholesky_pullback | ||
end |
Uh oh!
There was an error while loading. Please reload this page.