Skip to content
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

Generic rrule for constructors #510

Open
oxinabox opened this issue Aug 24, 2021 · 0 comments
Open

Generic rrule for constructors #510

oxinabox opened this issue Aug 24, 2021 · 0 comments

Comments

@oxinabox
Copy link
Member

Like #154

I am pretty sure there is a generic rrule for constructors.
Pretty sure I even wrote it down somewhere.

It is something like

function rrule(::Type{T}, args...) where T
    constructor_pullback(dx::Tangent{T}) = (NoTangent(), canonicalize(dx)...)
    
    # Special case for Zygote, which loses the primal type but also is always in canonical form anyway.
    constructor_pullback(dx::Tangent{Any}) = (NoTangent(), dx...)
    
    return T(args...), constructor_pullback
end

OTOH we only want to hit this for the default constructor (what Zygote basically has as __new__ I think)

Adding this more generally might break like all kinds of random constructors that we should be leaving alone?
idk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant