ChainRules.jl
ChainRules.jl copied to clipboard
Add getproperty for Tangent{<:Cholesky}
Initial code for closing #640. I'm open to changing what it checks, but this seems like any easy way to minimize breaking changes for now.
My intuition is that we would want getproperty(x::Tangent{<:Cholesky}, :U) == getproperty(x::Tangent{<:Cholesky}, :L)'. I think that's not satisfied by the PR?
I guess it might also be useful to define getproperty(x::Tangent{<:Cholesky}, :UL) (at least for completeness and to avoid ZeroTangents in that case as well).
One of the challenges with this approach is that we can't capture the logic present in this rule: https://github.com/JuliaDiff/ChainRules.jl/blob/6ff4c319f8fd25f27636d28144d78c92f81d8753/src/rulesets/LinearAlgebra/factorization.jl#L531-L543
Because we don't have access to the Cholesky object's uplo field, we don't know the relationship between factors, U, and L. e.g. if uplo=='L', then a user requesting ΔC.L should be given LowerTriangular(ΔC.factors), and a user requesting ΔC.U should be given LowerTriangular(ΔC.factors)', but the case is completely different if uplo=='U'. Currently this rule will only work when Symbol(C.uplo) == sym. I'm not certain if/how this can be resolved, short of modifying Tangent to include metadata from the primal object.