-
Notifications
You must be signed in to change notification settings - Fork 89
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
Add missing subtract rule #782
Conversation
src/rulesets/Base/arraymath.jl
Outdated
frule((_, Δx, Δy), ::typeof(-), x::AbstractArray, y::AbstractArray) = x-y, Δx-Δy | ||
|
||
function rrule(::typeof(-), x::AbstractArray, y::AbstractArray) | ||
subtract_pullback(dy) = (NoTangent(), dy, -dy) | ||
return x-y, subtract_pullback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the autoformatter is probably complaining about spaces around binary operators
frule((_, Δx, Δy), ::typeof(-), x::AbstractArray, y::AbstractArray) = x-y, Δx-Δy | |
function rrule(::typeof(-), x::AbstractArray, y::AbstractArray) | |
subtract_pullback(dy) = (NoTangent(), dy, -dy) | |
return x-y, subtract_pullback | |
frule((_, Δx, Δy), ::typeof(-), x::AbstractArray, y::AbstractArray) = (x - y), (Δx - Δy) | |
function rrule(::typeof(-), x::AbstractArray, y::AbstractArray) | |
subtract_pullback(dy) = (NoTangent(), dy, -dy) | |
return x - y, subtract_pullback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, fixed already!:)
@oxinabox the ChainRules.jl/src/rulesets/Base/arraymath.jl Lines 454 to 462 in 98f893f
should those be added here as well? |
yes, in particular it should be done with Basically I believe a pertianant example of the kinds that fall out from the math here would be:
Which (untested) with code as stands I believe would give a complex vector tangent to the first input. |
Ahh, that makes sense! thank you! |
Shall we add a test that exercises the |
So far there was only a rule for negation, this adds a rule for subtraction (two-argument
-
).