Skip to content

Commit

Permalink
Fix rrule for matrix valued and multi-dimensional interpolation. (#487)
Browse files Browse the repository at this point in the history
* Fix rrule for matrix valued and multi-dimensional interpolation.

* Fix syntax for v1.3
  • Loading branch information
contradict authored Apr 17, 2022
1 parent 3421847 commit a4e1c66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chainrules/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function ChainRulesCore.rrule(itp::AbstractInterpolation, x...)
y = itp(x...)
function interpolate_pullback(Δy)
nope = ChainRulesCore.@not_implemented "`Interpolations.gradient` does not calculate a gradient with respect to the original data, only the evaluation point"
(nope, (Δy * Interpolations.gradient(itp, x...))...)
(nope, (sum(Δy .* g) for g in Interpolations.gradient(itp, x...))...)
end
y, interpolate_pullback
end
11 changes: 11 additions & 0 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ using Zygote
else
@test_skip Zygote.gradient(itp2,1,2) == Tuple(Interpolations.gradient(itp2,1,2))
end

# Matrix-valued
y=[[[0 0; 0 0]] [[1 2; 0 0]];
[[0 0; 3 4]] [[1 2; 3 4]]]
itp_m = interpolate(y, BSpline(Linear()))
if VERSION v"1.3"
@test Zygote.jacobian(itp_m, 1,1) == Tuple((x->[x...]).(Interpolations.gradient(itp_m, 1,1)))
else
@test_skip Zygote.jacobian(itp_m, 1,1) == Tuple((x->[x...]).(Interpolations.gradient(itp_m, 1,1)))
end

end

2 comments on commit a4e1c66

@mkitti
Copy link
Collaborator

@mkitti mkitti commented on a4e1c66 Apr 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/58656

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.6 -m "<description of version>" a4e1c664c8473b5d36dde5104ad77205c7799c02
git push origin v0.13.6

Please sign in to comment.