Skip to content

Commit

Permalink
Allow keyword arguments in the fallback rrule/frule methods
Browse files Browse the repository at this point in the history
This permits using `rrule(f, args...; kwargs...)` unconditionally and
receiving `nothing` as expected rather than an error about `rrule` not
taking keyword arguments.
  • Loading branch information
ararslan committed Jun 19, 2019
1 parent c12f953 commit 545981a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ true
See also: [`rrule`](@ref), [`AbstractRule`](@ref), [`@scalar_rule`](@ref)
"""
frule(::Any, ::Vararg{Any}) = nothing
frule(::Any, ::Vararg{Any}; kwargs...) = nothing

"""
rrule(f, x...)
Expand Down Expand Up @@ -375,7 +375,7 @@ true
See also: [`frule`](@ref), [`AbstractRule`](@ref), [`@scalar_rule`](@ref)
"""
rrule(::Any, ::Vararg{Any}) = nothing
rrule(::Any, ::Vararg{Any}; kwargs...) = nothing

@noinline function _throw_checked_rrule_error(f, args...; kwargs...)
io = IOBuffer()
Expand Down
2 changes: 2 additions & 0 deletions test/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ cool(x, y) = x + y + 1
@testset "rules" begin
@testset "frule and rrule" begin
@test frule(cool, 1) === nothing
@test frule(cool, 1; iscool=true) === nothing
@test rrule(cool, 1) === nothing
@test rrule(cool, 1; iscool=true) === nothing
ChainRules.@scalar_rule(Main.cool(x), one(x))
frx, fr = frule(cool, 1)
@test frx == 2
Expand Down

0 comments on commit 545981a

Please sign in to comment.