|
136 | 136 |
|
137 | 137 | z̄ = rand(3, 5) |
138 | 138 | (ds, dx, dy) = pullback(z̄) |
139 | | - |
| 139 | + |
140 | 140 | @test ds === NO_FIELDS |
141 | 141 |
|
142 | 142 | @test extern(dx) == extern(accumulate(zeros(3, 2), dx)) |
|
147 | 147 | end |
148 | 148 |
|
149 | 149 | @testset "hypot(x, y)" begin |
150 | | - x, y = rand(2) |
151 | | - h, pushforward = frule(hypot, x, y) |
152 | | - dxy(x, y) = pushforward(NamedTuple(), x, y) |
153 | | - |
154 | | - @test extern(dxy(One(), Zero())) === x / h |
155 | | - @test extern(dxy(Zero(), One())) === y / h |
156 | | - |
157 | | - cx, cy = cast((One(), Zero())), cast((Zero(), One())) |
158 | | - dx, dy = extern(dxy(cx, cy)) |
159 | | - @test dx === x / h |
160 | | - @test dy === y / h |
161 | | - |
162 | | - cx, cy = cast((rand(), Zero())), cast((Zero(), rand())) |
163 | | - dx, dy = extern(dxy(cx, cy)) |
164 | | - @test dx === x / h * cx.value[1] |
165 | | - @test dy === y / h * cy.value[2] |
| 150 | + rng = MersenneTwister(123456) |
| 151 | + x, Δx, x̄ = randn(rng, 3) |
| 152 | + y, Δy, ȳ = randn(rng, 3) |
| 153 | + Δz = randn(rng) |
| 154 | + |
| 155 | + frule_test(hypot, (x, Δx), (y, Δy)) |
| 156 | + rrule_test(hypot, Δz, (x, x̄), (y, ȳ)) |
166 | 157 | end |
167 | 158 |
|
168 | 159 | @testset "identity" begin |
|
0 commit comments