|
13 | 13 | @testset "DiffRules" begin |
14 | 14 | @testset "check rules" begin |
15 | 15 |
|
16 | | -non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3)] |
| 16 | +non_diffeable_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ldexp, 2), (:Base, :ifelse, 3)] |
17 | 17 |
|
18 | 18 | for (M, f, arity) in DiffRules.diffrules(; filter_modules=nothing) |
19 | | - (M, f, arity) ∈ non_numeric_arg_functions && continue |
| 19 | + (M, f, arity) ∈ non_diffeable_arg_functions && continue |
20 | 20 | if arity == 1 |
21 | 21 | @test DiffRules.hasdiffrule(M, f, 1) |
22 | 22 | deriv = DiffRules.diffrule(M, f, :goo) |
@@ -95,6 +95,23 @@ for xtype in [:Float64, :BigFloat, :Int64] |
95 | 95 | end |
96 | 96 | end |
97 | 97 | end |
| 98 | + |
| 99 | +# Treat ldexp separately because of its integer second argument: |
| 100 | +derivs = DiffRules.diffrule(:Base, :ldexp, :x, :y) |
| 101 | +for xtype in [:Float64, :BigFloat] |
| 102 | + for ytype in [:Integer, :UInt64, :Int64] |
| 103 | + @eval begin |
| 104 | + let |
| 105 | + x = rand($xtype) |
| 106 | + y = $ytype(rand(1 : 10)) |
| 107 | + dx, dy = $(derivs[1]), $(derivs[2]) |
| 108 | + @test isapprox(dx, finitediff(z -> ldexp(z, y), x), rtol=0.05) |
| 109 | + @test isnan(dy) |
| 110 | + end |
| 111 | + end |
| 112 | + end |
| 113 | +end |
| 114 | + |
98 | 115 | end |
99 | 116 |
|
100 | 117 | @testset "diffrules" begin |
|
0 commit comments