ChainRulesCore.jl icon indicating copy to clipboard operation
ChainRulesCore.jl copied to clipboard

Make ZeroTangent() == 0

Open oxinabox opened this issue 2 years ago • 3 comments

I feel like we can overload == for ZeroTangent()`
to do something like

==(::ZeroTangent, a) = iszero(a)

would also need to overload hash since all things that are equal to zero in julia have the same hash, buit we can just call hash(0, h)

this would be useful for testhing some of the stuff i am working on to not AD things that don't appear in this function.

oxinabox avatar Mar 13 '23 11:03 oxinabox

For testing purposes, would it be sufficient to overload instead? That would avoid hash complications, and maybe invalidations.

Like here: https://github.com/JuliaDiff/Diffractor.jl/pull/73/files#diff-fba4d4a7c64aacd9b1a662bca4487f3e849b43f09e65f6c8788a3f142b989f65R27-R32

mcabbott avatar Mar 14 '23 02:03 mcabbott

I want to test exact equality, though, not approximate. And I want equality on tuples to work. (isapprox isn't defined for tuples)

The hash complication is trivially resolved. I hope there are not major invalidation issues, especially if we restrict it to Number. (or perhaps Union{Number,Array}) We did have to remove it from thunks, but that was unrestricted: https://github.com/JuliaDiff/ChainRulesCore.jl/pull/524

oxinabox avatar Mar 14 '23 02:03 oxinabox

Not having this is causing issues for Diffractor I look into this further soon and see what (if any) invalidation issues there are.

oxinabox avatar Oct 16 '23 13:10 oxinabox