-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Derivatives of constant functions return nothing. #329
Comments
This is currently the expected behaviour; we use |
This is problematic because julia> g(f, x) = f'(x) + x
g (generic function with 1 method)
julia> g(x -> 2, 1)
ERROR: MethodError: no method matching +(::Nothing, ::Int64) Yeah, I think some sort of struct Zero end
Base.:(+)(z::Zero, x) = x
Base.:(+)(x, z::Zero) = x
Base.:(-)(z::Zero, x) = -x
Base.:(-)(x, z::Zero) = x
Base.:(*)(z::Zero, x) = z
Base.:(*)(x, z::Zero) = z
Base.:(/)(z::Zero, x) = z
Base.:(^)(z::Zero, x) = z
Base.:(^)(x, z::Zero) = one(x) etc. This could actually potentially go into |
It's an option, but note that this (or The current recommended way to deal with this is to just use |
For reference, ChainRules.jl is making use of some Zero type, but I believe it has been questioned at some point |
I've tested this on
Zygote#master
and latest release:Probably this should give
false
or something like that instead ofnothing
.The text was updated successfully, but these errors were encountered: