Skip to content

Commit

Permalink
make @non_differentiable use identical pullbacks when possible (#679)
Browse files Browse the repository at this point in the history
* make `@non_differentiable` use identical pullbacks when possible

Fixes #678

* simpler

* bump version
  • Loading branch information
nsajko authored May 31, 2024
1 parent 3da9c1a commit b9ea5d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.23.0"
version = "1.24.0"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
2 changes: 1 addition & 1 deletion src/ChainRulesCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ChainRulesCore
using Base.Broadcast: broadcasted, Broadcasted, broadcastable, materialize, materialize!
using Base.Meta
using LinearAlgebra
using Compat: hasfield, hasproperty, ismutabletype
using Compat: hasfield, hasproperty, ismutabletype, Returns

export frule, rrule # core function
# rule configurations
Expand Down
4 changes: 1 addition & 3 deletions src/rule_definition_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,7 @@ function _nondiff_rrule_expr(__source__, primal_sig_parts, primal_invoke)
tup_expr = tuple_expression(primal_sig_parts)
primal_name = first(primal_invoke.args)
pullback_expr = @strip_linenos quote
function $(esc(propagator_name(primal_name, :pullback)))(@nospecialize(_))
return $(tup_expr)
end
Returns($(tup_expr))
end

@gensym kwargs
Expand Down
14 changes: 14 additions & 0 deletions test/rule_definition_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ end

@testset "rule_definition_tools.jl" begin
@testset "@non_differentiable" begin
@testset "issue #678: identical pullback objects" begin
issue_678_f(::Any) = nothing
issue_678_g(::Any) = nothing
issue_678_h(::Any...) = nothing
@non_differentiable issue_678_f(::Any)
@non_differentiable issue_678_g(::Any)
@non_differentiable issue_678_h(::Any...)
@test (
last(rrule(issue_678_f, 0.1)) ===
last(rrule(issue_678_g, 0.2)) ===
last(rrule(issue_678_h, 0.3))
)
end

@testset "two input one output function" begin
nondiff_2_1(x, y) = fill(7.5, 100)[x + y]
@non_differentiable nondiff_2_1(::Any, ::Any)
Expand Down

2 comments on commit b9ea5d7

@devmotion
Copy link
Member

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

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.24.0 -m "<description of version>" b9ea5d70569ff23e6b7880355b8f461939a13c97
git push origin v1.24.0

Please sign in to comment.