@@ -20,19 +20,20 @@ using Zygote: hessian_dual, hessian_reverse
20
20
end
21
21
22
22
VERSION > v " 1.6-" && @testset " diagonal hessian" begin
23
- # Avoiding this error on Julia 1.3 CI, not sure the exact test which causes it:
24
- # julia> log(Dual(1,0) + 0im)
25
- # ERROR: StackOverflowError:
26
-
27
23
@test diaghessian (x -> x[1 ]* x[2 ]^ 2 , [1 , pi ]) == ([0 , 2 ],)
28
24
29
- xs, y = randn (2 ,3 ), rand ()
30
- f34 (xs, y) = xs[1 ] * (sum (xs .^ (1 : 3 )' ) + y^ 4 ) # non-diagonal Hessian, two arguments
31
-
32
- dx, dy = diaghessian (f34, xs, y)
33
- @test size (dx) == size (xs)
34
- @test vec (dx) ≈ diag (hessian (x -> f34 (x,y), xs))
35
- @test dy ≈ hessian (y -> f34 (xs,y), y)
25
+ if VERSION > v " 1.6-"
26
+ # Gradient of ^ may contain log(complex(...)), which interacts badly with Dual below Julia 1.6:
27
+ # julia> log(ForwardDiff.Dual(1,0) + 0im)
28
+ # ERROR: StackOverflowError:
29
+ xs, y = randn (2 ,3 ), rand ()
30
+ f34 (xs, y) = xs[1 ] * (sum (xs .^ (1 : 3 )' ) + y^ 4 ) # non-diagonal Hessian, two arguments
31
+
32
+ dx, dy = diaghessian (f34, xs, y)
33
+ @test size (dx) == size (xs)
34
+ @test vec (dx) ≈ diag (hessian (x -> f34 (x,y), xs))
35
+ @test dy ≈ hessian (y -> f34 (xs,y), y)
36
+ end
36
37
37
38
zs = randn (7 ,13 ) # test chunk mode
38
39
@test length (zs) > ForwardDiff. DEFAULT_CHUNK_THRESHOLD
0 commit comments