Skip to content

Commit 8f754f3

Browse files
authored
Allow keyword arguments in the fallback rrule/frule methods (#60)
This permits using `rrule(f, args...; kwargs...)` unconditionally and receiving `nothing` as expected rather than an error about `rrule` not taking keyword arguments.
1 parent c12f953 commit 8f754f3

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/rules.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ true
319319
320320
See also: [`rrule`](@ref), [`AbstractRule`](@ref), [`@scalar_rule`](@ref)
321321
"""
322-
frule(::Any, ::Vararg{Any}) = nothing
322+
frule(::Any, ::Vararg{Any}; kwargs...) = nothing
323323

324324
"""
325325
rrule(f, x...)
@@ -375,7 +375,7 @@ true
375375
376376
See also: [`frule`](@ref), [`AbstractRule`](@ref), [`@scalar_rule`](@ref)
377377
"""
378-
rrule(::Any, ::Vararg{Any}) = nothing
378+
rrule(::Any, ::Vararg{Any}; kwargs...) = nothing
379379

380380
@noinline function _throw_checked_rrule_error(f, args...; kwargs...)
381381
io = IOBuffer()

test/rules.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ cool(x, y) = x + y + 1
44
@testset "rules" begin
55
@testset "frule and rrule" begin
66
@test frule(cool, 1) === nothing
7+
@test frule(cool, 1; iscool=true) === nothing
78
@test rrule(cool, 1) === nothing
9+
@test rrule(cool, 1; iscool=true) === nothing
810
ChainRules.@scalar_rule(Main.cool(x), one(x))
911
frx, fr = frule(cool, 1)
1012
@test frx == 2

0 commit comments

Comments
 (0)