Skip to content

Commit

Permalink
Merge pull request #651 from JuliaDiff/ox/non_diff_ambig
Browse files Browse the repository at this point in the history
Fix ambig with configured frule created by non_differentiable rule
  • Loading branch information
oxinabox authored Jan 12, 2024
2 parents 17a83d4 + 161e5f1 commit 77748b3
Show file tree
Hide file tree
Showing 3 changed files with 21 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 = "ChainRulesCore"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.19.0"
version = "1.19.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
4 changes: 2 additions & 2 deletions src/rule_definition_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ function _nondiff_frule_expr(__source__, primal_sig_parts, primal_invoke)
function (::Core.kwftype(typeof(ChainRulesCore.frule)))(
@nospecialize($kwargs::Any),
frule::typeof(ChainRulesCore.frule),
@nospecialize(::Any),
@nospecialize(::Tuple),
$(map(esc, primal_sig_parts)...),
)
return ($(esc(_with_kwargs_expr(primal_invoke, kwargs))), NoTangent())
end
function ChainRulesCore.frule(
@nospecialize(::Any), $(map(esc, primal_sig_parts)...)
@nospecialize(::Tuple), $(map(esc, primal_sig_parts)...)
)
$(__source__)
# Julia functions always only have 1 output, so return a single NoTangent()
Expand Down
18 changes: 18 additions & 0 deletions test/rule_definition_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ end
@test pullback(4.5) == (NoTangent(), NoTangent(), NoTangent())
end

@testset "interactions with configs" begin
struct AllConfig <: RuleConfig{Union{HasForwardsMode,NoReverseMode}} end

foo_ndc1(x) = string(x)
@non_differentiable foo_ndc1(x)
@test frule(AllConfig(), (NoTangent(), NoTangent()), foo_ndc1, 2.0) == (string(2.0), NoTangent())
r1, pb1 = rrule(AllConfig(), foo_ndc1, 2.0)
@test r1 == string(2.0)
@test pb1(NoTangent()) == (NoTangent(), NoTangent())

foo_ndc2(x; y=0) = string(x + y)
@non_differentiable foo_ndc2(x)
@test frule(AllConfig(), (NoTangent(), NoTangent()), foo_ndc2, 2.0; y=4.0) == (string(6.0), NoTangent())
r2, pb2 = rrule(AllConfig(), foo_ndc2, 2.0; y=4.0)
@test r2 == string(6.0)
@test pb2(NoTangent()) == (NoTangent(), NoTangent())
end

@testset "Not supported (Yet)" begin
# Where clauses are not supported.
@test_macro_throws(
Expand Down

2 comments on commit 77748b3

@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/98763

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.19.1 -m "<description of version>" 77748b3c176d2c0e62195b91e4e283cf7e7934e6
git push origin v1.19.1

Please sign in to comment.