|
79 | 79 | @testset "($x) * ($y)" for |
80 | 80 | x in test_points, y in test_points |
81 | 81 |
|
82 | | - # ensure all complex if any complex for FiniteDifferences |
83 | | - x, y = Base.promote(x, y) |
| 82 | + # all complex if any complex, was a limitation of FiniteDifferences? |
| 83 | + xx, yy = Base.promote(x, y) |
| 84 | + test_frule(*, xx, yy) |
| 85 | + test_rrule(*, xx, yy) |
84 | 86 |
|
| 87 | + # explicitly allow mixed types |
85 | 88 | test_frule(*, x, y) |
86 | 89 | test_rrule(*, x, y) |
| 90 | + rrule(*, x, y)[2](1)[2] isa typeof(x) |
| 91 | + rrule(*, x, y)[2](1)[3] isa typeof(y) |
87 | 92 | end |
88 | 93 | end |
89 | 94 |
|
|
117 | 122 | test_rrule(identity, Tuple(randn(T, 3))) |
118 | 123 | end |
119 | 124 |
|
120 | | - @testset "Constants" for x in (-0.1, 6.4, 1.0+0.5im, -10.0+0im, 0.0+200im) |
| 125 | + @testset "one(::Number), zero(::Number)" for x in (-0.1, 6.4, 1.0+0.5im, -10.0+0im, 0.0+200im) |
121 | 126 | test_scalar(one, x) |
122 | 127 | test_scalar(zero, x) |
| 128 | + |
| 129 | + rrule(one, x)[2](1) === (NoTangent(), zero(x)) |
| 130 | + rrule(zero, x)[2](1) === (NoTangent(), zero(x)) |
123 | 131 | end |
124 | 132 |
|
125 | 133 | @testset "muladd(x::$T, y::$T, z::$T)" for T in (Float64, ComplexF64) |
126 | | - test_frule(muladd, 10randn(), randn(), randn()) |
127 | | - test_rrule(muladd, 10randn(), randn(), randn()) |
| 134 | + test_frule(muladd, 10randn(T), randn(T), randn(T)) |
| 135 | + test_rrule(muladd, 10randn(T), randn(T), randn(T)) |
128 | 136 | end |
129 | 137 |
|
130 | 138 | @testset "fma" begin |
|
144 | 152 | # to right |
145 | 153 | test_frule(clamp, 4., 2., 3.) |
146 | 154 | test_rrule(clamp, 4., 2., 3.) |
| 155 | + |
| 156 | + # nonzero gradient at the boundaries |
| 157 | + @test frule((0,1,0,0), clamp, 2, 2, 3) == (2, 1) |
| 158 | + @test rrule(clamp, 2.0, 2, 3)[2](1)[2] == 1.0 |
| 159 | + |
| 160 | + @test frule((0,1,0,0), clamp, 3, 2, 3) == (3, 1) |
| 161 | + @test rrule(clamp, 3, 2, 3)[2](1)[2] == 1.0 |
147 | 162 | end |
148 | 163 |
|
149 | 164 | @testset "rounding" begin |
|
0 commit comments