ChainRulesCore.jl
ChainRulesCore.jl copied to clipboard
WIP: handle zero_tangent from cyclic data structures v2 Via premapping
This is an alternative to https://github.com/JuliaDiff/ChainRulesCore.jl/pull/654 I think it is more promising and should minimize the type instability outside of cyclic locations
Basically here is the idea:
- Identify all objects that have multiple references to them
- Go through and construct tangents for everything;
- save the tangents for things with >1 reference into an IdDict keyed by primal
- when constructing tangent fields for things that have >1 reference to them, initially treat them as per
undefelements, so set the tangent value as alsoundefor to aZeroTangent - go back through the tangent object and set the values for things with multiple references
This will also handle aliases outside of loops correctly.