@@ -3,6 +3,7 @@ module GradientTest
33import Calculus
44
55using Test
6+ using LinearAlgebra
67using ForwardDiff
78using ForwardDiff: Dual, Tag
89using StaticArrays
148149 @test isequal (ForwardDiff. gradient (t -> t[1 ]^ t[2 ], [0.0 , 1.5 ]), [0.0 , 0.0 ])
149150end
150151
152+ # ############
153+ # bug fixes #
154+ # ############
155+
151156# Issue 399
152157@testset " chunk size zero" begin
153158 f_const (x) = 1.0
@@ -162,11 +167,29 @@ end
162167 @test_throws DimensionMismatch ForwardDiff. gradient (identity, fill (2pi , 10 ^ 6 )) # chunk_mode_gradient
163168end
164169
170+ # Issue 548
165171@testset " ArithmeticStyle" begin
166172 function f (p)
167173 sum (collect (0.0 : p[1 ]: p[2 ]))
168174 end
169175 @test ForwardDiff. gradient (f, [0.2 ,25.0 ]) == [7875.0 , 0.0 ]
170176end
171177
178+ # Issue 197
179+ @testset " det with branches" begin
180+ det2 (A) = return (
181+ A[1 ,1 ]* (A[2 ,2 ]* A[3 ,3 ]- A[2 ,3 ]* A[3 ,2 ]) -
182+ A[1 ,2 ]* (A[2 ,1 ]* A[3 ,3 ]- A[2 ,3 ]* A[3 ,1 ]) +
183+ A[1 ,3 ]* (A[2 ,1 ]* A[3 ,2 ]- A[2 ,2 ]* A[3 ,1 ])
184+ )
185+
186+ A = [1 0 0 ; 0 2 0 ; 0 pi 3 ]
187+ @test det2 (A) == det (A) == 6
188+ @test istril (A)
189+
190+ ∇A = [6 0 0 ; 0 3 - pi ; 0 0 2 ]
191+ @test ForwardDiff. gradient (det2, A) ≈ ∇A
192+ @test ForwardDiff. gradient (det, A) ≈ ∇A
193+ end
194+
172195end # module
0 commit comments