@@ -20,19 +20,20 @@ using Zygote: hessian_dual, hessian_reverse
2020end
2121
2222VERSION > 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-
2723 @test diaghessian (x -> x[1 ]* x[2 ]^ 2 , [1 , pi ]) == ([0 , 2 ],)
2824
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
3637
3738 zs = randn (7 ,13 ) # test chunk mode
3839 @test length (zs) > ForwardDiff. DEFAULT_CHUNK_THRESHOLD
0 commit comments