From 6ae55dd12cbb93eecb94ac60d21a3cfe0f946b4e Mon Sep 17 00:00:00 2001 From: rofinn Date: Tue, 28 Jun 2022 19:12:37 -0700 Subject: [PATCH] Add getproperty for Tangent{<:Cholesky}. --- src/rulesets/LinearAlgebra/factorization.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rulesets/LinearAlgebra/factorization.jl b/src/rulesets/LinearAlgebra/factorization.jl index f2f8d32d1..af651baa5 100644 --- a/src/rulesets/LinearAlgebra/factorization.jl +++ b/src/rulesets/LinearAlgebra/factorization.jl @@ -578,3 +578,11 @@ function _x_divide_conj_y(x, y) z = x / conj(y) return iszero(x) ? zero(z) : z end + +# Support both factors and U / L properties on cholesky tangent types +# TOODO: Maybe we should check the type of U or L first? +function Base.getproperty(tangent::Tangent{P, T}, sym::Symbol) where {P <: Cholesky, T <: NamedTuple} + idx = if hasfield(T, :factors) && sym in (:U, :L) ? :factors : sym + hasfield(T, idx) || return ZeroTangent() + return unthunk(getfield(ChainRulesCore.backing(tangent), idx)) +end