Skip to content

Commit

Permalink
Don't allow sum of anything in rrule
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Oct 18, 2019
1 parent 9e4cb76 commit 0ff02a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/rulesets/Base/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function frule(::typeof(sum), x)
return sum(x), sum_pushforward
end

function rrule(::typeof(sum), x)
function rrule(::typeof(sum), x::AbstractArray{<:Real})
function sum_pullback(ȳ)
return (NO_FIELDS, @thunk(fill(ȳ, size(x))))
end
Expand All @@ -67,15 +67,15 @@ end
function rrule(::typeof(sum), f, x::AbstractArray{<:Real}; dims=:)
y, mr_pullback = rrule(mapreduce, f, Base.add_sum, x; dims=dims)
function sum_pullback(ȳ)
NO_FIELDS, DNE(), last(mr_pullback(ȳ))
return NO_FIELDS, DNE(), last(mr_pullback(ȳ))
end
return y, sum_pullback
end

function rrule(::typeof(sum), x::AbstractArray{<:Real}; dims=:)
y, inner_pullback = rrule(sum, identity, x; dims=dims)
function sum_pullback(ȳ)
NO_FIELDS, last(inner_pullback(ȳ))
return NO_FIELDS, last(inner_pullback(ȳ))
end
return y, sum_pullback
end
Expand Down

0 comments on commit 0ff02a1

Please sign in to comment.