-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chain rule for
EachVariate
constructor (#1627)
* added chain rule for eachvariate * version bump * added comment to explain why to_vec overload is needed * simplified impl of rrule * Update src/eachvariate.jl Co-authored-by: David Widmann <[email protected]> * Update runtests.jl * Update src/eachvariate.jl Co-authored-by: David Widmann <[email protected]>
- Loading branch information
Showing
4 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using ChainRulesTestUtils | ||
using ChainRulesTestUtils: FiniteDifferences | ||
|
||
# Without this, `to_vec` will also include the `axes` field of `EachVariate`. | ||
function FiniteDifferences.to_vec(xs::Distributions.EachVariate{V}) where {V} | ||
vals, vals_from_vec = FiniteDifferences.to_vec(xs.parent) | ||
return vals, x -> Distributions.EachVariate{V}(vals_from_vec(x)) | ||
end | ||
|
||
@testset "eachvariate.jl" begin | ||
@testset "ChainRules" begin | ||
xs = randn(2, 3, 4, 5) | ||
test_rrule(Distributions.EachVariate{1}, xs) | ||
test_rrule(Distributions.EachVariate{2}, xs) | ||
test_rrule(Distributions.EachVariate{3}, xs) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a31ebc4
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.
@JuliaRegistrator register
a31ebc4
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.
Registration pull request created: JuliaRegistries/General/69907
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: