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

use ProjectTo in Array addition #578

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ end

function rrule(::typeof(+), arrs::AbstractArray...)
y = +(arrs...)
arr_axs = map(axes, arrs)
projects = map(ProjectTo, arrs)
function add_pullback(dy)
return (NoTangent(), map(ax -> reshape(dy, ax), arr_axs)...)
return (NoTangent(), map(project->project(dy), projects)...)
end
return y, add_pullback
end
3 changes: 3 additions & 0 deletions test/rulesets/Base/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,8 @@
@testset "addition" begin
test_rrule(+, randn(4, 4), randn(4, 4), randn(4, 4))
test_rrule(+, randn(3), randn(3,1), randn(3,1,1))
test_rrule(+, randn(3,3), Diagonal(randn(3)), randn(3,3,1))
test_rrule(+, randn(3,3), Diagonal(randn(3)), Symmetric(randn(3,3)))

end
end