Skip to content

Commit

Permalink
Merge d9461cd into f63f385
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Oct 15, 2020
2 parents f63f385 + d9461cd commit 3f50382
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,14 @@ function rrule(::typeof(\), b::Real, A::AbstractArray{<:Real})
end
return Y, backslash_pullback
end

#####
##### Negation (Unary -)
#####

function rrule(::typeof(-), x::AbstractArray)
function negation_pullback(ȳ)
return NO_FIELDS, InplaceableThunk(@thunk(-ȳ), ā ->.-= ȳ)
end
return -x, negation_pullback
end
9 changes: 9 additions & 0 deletions test/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@
rrule_test(/, Ȳ, (A, Ā), (7.2, 2.3))
rrule_test(\, Ȳ, (7.2, 2.3), (A, Ā))
end


@testset "negation" begin
A = randn(4, 4)
= randn(4, 4)
= randn(4, 4)
rrule_test(-, Ȳ, (A, Ā))
rrule_test(-, Diagonal(Ȳ), (Diagonal(A), Diagonal(Ā)))
end
end

0 comments on commit 3f50382

Please sign in to comment.