|
42 | 42 |
|
43 | 43 | @testset "rule_definition_tools.jl" begin
|
44 | 44 | @testset "@non_differentiable" begin
|
| 45 | + @testset "`_make_pullback_for_non_differentiable`" begin |
| 46 | + f = ChainRulesCore._make_pullback_for_non_differentiable |
| 47 | + @testset "throws on invalid input" begin |
| 48 | + @test_throws Exception f(Val(0.0)) |
| 49 | + @test_throws Exception f(Val(-1)) |
| 50 | + end |
| 51 | + @testset "identical objects" begin |
| 52 | + for i ∈ 0:5 |
| 53 | + v = Val(i) |
| 54 | + @test f(v) === f(v) |
| 55 | + end |
| 56 | + end |
| 57 | + @testset "correctness" begin |
| 58 | + for i ∈ 0:5 |
| 59 | + expected = ntuple((_ -> NoTangent()), i) |
| 60 | + @test f(Val(i))(:arbitrary) === expected |
| 61 | + end |
| 62 | + end |
| 63 | + @testset "dispatch" begin |
| 64 | + for i ∈ 0:5 |
| 65 | + pullback = f(Val(i)) |
| 66 | + @test_throws MethodError pullback() |
| 67 | + @test_throws MethodError pullback(1, 2) |
| 68 | + end |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + @testset "issue #678: identical pullback objects" begin |
| 73 | + issue_678_f(::Any) = nothing |
| 74 | + issue_678_g(::Any) = nothing |
| 75 | + issue_678_h(::Any...) = nothing |
| 76 | + @non_differentiable issue_678_f(::Any) |
| 77 | + @non_differentiable issue_678_g(::Any) |
| 78 | + @non_differentiable issue_678_h(::Any...) |
| 79 | + @test ( |
| 80 | + last(rrule(issue_678_f, 0.1)) === |
| 81 | + last(rrule(issue_678_g, 0.2)) === |
| 82 | + last(rrule(issue_678_h, 0.3)) |
| 83 | + ) |
| 84 | + end |
| 85 | + |
45 | 86 | @testset "two input one output function" begin
|
46 | 87 | nondiff_2_1(x, y) = fill(7.5, 100)[x + y]
|
47 | 88 | @non_differentiable nondiff_2_1(::Any, ::Any)
|
|
0 commit comments