Skip to content

Commit

Permalink
Merge pull request #797 from nsajko/zero_one_identically_same_pullback
Browse files Browse the repository at this point in the history
make `rrule` return identical pullback for `zero` as for `one`
  • Loading branch information
oxinabox authored May 31, 2024
2 parents 2c6621c + 363aa6c commit 9dd39bd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.66.0"
version = "1.67.0"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
4 changes: 2 additions & 2 deletions src/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function frule((_, _), ::typeof(zero), x)
end

function rrule(::typeof(zero), x)
zero_pullback(_) = (NoTangent(), ZeroTangent())
zero_pullback = Returns((NoTangent(), ZeroTangent()))
return (zero(x), zero_pullback)
end

Expand All @@ -22,7 +22,7 @@ function frule((_, _), ::typeof(one), x)
end

function rrule(::typeof(one), x)
one_pullback(_) = (NoTangent(), ZeroTangent())
one_pullback = Returns((NoTangent(), ZeroTangent()))
return (one(x), one_pullback)
end

Expand Down
1 change: 1 addition & 0 deletions test/rulesets/Base/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ end

@testset "base.jl" begin
@testset "zero/one" begin
@test last(rrule(zero, 0.1)) === last(rrule(one, 0.2f0))
for f in [zero, one]
for x in [1.0, 1.0im, [10.0+im 11.0-im; 12.0+2im 13.0-3im]]
test_frule(f, x)
Expand Down

2 comments on commit 9dd39bd

@oxinabox
Copy link
Member Author

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/108021

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v1.67.0 -m "<description of version>" 9dd39bdbb66819ad26d19ebbe62b76c1ede56f66
git push origin v1.67.0

Please sign in to comment.