|
70 | 70 | end |
71 | 71 | end |
72 | 72 |
|
73 | | - @testset "_is_fallback" begin |
74 | | - _is_fallback = ChainRulesOverloadGeneration._is_fallback |
75 | | - @test _is_fallback(rrule, first(methods(rrule, (Nothing,)))) |
76 | | - @test _is_fallback(frule, first(methods(frule, (Tuple{}, Nothing,)))) |
77 | | - end |
78 | | - |
79 | 73 | @testset "_rule_list" begin |
80 | 74 | _rule_list = ChainRulesOverloadGeneration._rule_list |
81 | 75 | @testset "should not have frules that need RuleConfig" begin |
|
112 | 106 | # Above would error if we were not handling UnionAll's right |
113 | 107 | end |
114 | 108 | end |
| 109 | + |
| 110 | + |
| 111 | + @testset "opting out" begin |
| 112 | + oa_id(x, y) = x |
| 113 | + @scalar_rule(oa_id(x::Number), 1) |
| 114 | + @opt_out ChainRulesCore.rrule(::typeof(oa_id), x::Float32) |
| 115 | + @opt_out ChainRulesCore.frule(::Any, ::typeof(oa_id), x::Float32) |
| 116 | + |
| 117 | + # In theses tests we `@assert` the behavour that `methods` has |
| 118 | + # and then `@test` that `_rule_list` differs from that, in the way we want |
| 119 | + |
| 120 | + @test !isempty([m for m in _rule_list(rrule) if m.sig <: Tuple{Any,typeof(oa_id),Number}]) |
| 121 | + # Opted out |
| 122 | + @assert !isempty([m for m in methods(rrule) if m.sig <: Tuple{Any,typeof(oa_id),Float32}]) |
| 123 | + @test isempty([m for m in _rule_list(rrule) if m.sig <: Tuple{Any,typeof(oa_id),Float32}]) |
| 124 | + # fallback |
| 125 | + @test !isempty([m for m in methods(rrule) if m.sig == Tuple{typeof(rrule),Any,Vararg{Any}}]) |
| 126 | + @test isempty([m for m in _rule_list(rrule) if m.sig == Tuple{typeof(rrule),Any,Vararg{Any}}]) |
| 127 | + |
| 128 | + @test !isempty([m for m in _rule_list(frule) if m.sig <: Tuple{Any,Any,typeof(oa_id),Number}]) |
| 129 | + # Opted out |
| 130 | + @assert !isempty([m for m in methods(frule) if m.sig <: Tuple{Any,Any,typeof(oa_id),Float32}]) |
| 131 | + @test isempty([m for m in _rule_list(frule) if m.sig <: Tuple{Any,Any,typeof(oa_id),Float32}]) |
| 132 | + # fallback |
| 133 | + @assert !isempty([m for m in methods(frule) if m.sig == Tuple{typeof(frule),Any,Any,Vararg{Any}}]) |
| 134 | + @test isempty([m for m in _rule_list(frule) if m.sig == Tuple{typeof(frule),Any,Any,Vararg{Any}}]) |
| 135 | + end |
115 | 136 | end |
116 | 137 | end |
0 commit comments