@@ -175,6 +175,38 @@ Enzyme.autodiff(set_runtime_activity(Reverse), f3, Duplicated(copy(A), dA), Dupl
175175@test db1 ≈ db12
176176@test db2 ≈ db22
177177
178+ function f4 (A, b1, b2; alg = LUFactorization ())
179+ prob = LinearProblem (A, b1)
180+ cache = init (prob, alg)
181+ solve! (cache)
182+ s1 = copy (cache. u)
183+ cache. b = b2
184+ solve! (cache)
185+ s2 = copy (cache. u)
186+ norm (s1 + s2)
187+ end
188+
189+ A = rand (n, n);
190+ dA = zeros (n, n);
191+ b1 = rand (n);
192+ db1 = zeros (n);
193+ b2 = rand (n);
194+ db2 = zeros (n);
195+
196+ f4 (A, b1, b2)
197+ @test_throws " Adjoint case currently not handled" Enzyme. autodiff (Reverse, f4, Duplicated (copy (A), dA),
198+ Duplicated (copy (b1), db1), Duplicated (copy (b2), db2))
199+
200+ #=
201+ dA2 = ForwardDiff.gradient(x -> f4(x, eltype(x).(b1), eltype(x).(b2)), copy(A))
202+ db12 = ForwardDiff.gradient(x -> f4(eltype(x).(A), x, eltype(x).(b2)), copy(b1))
203+ db22 = ForwardDiff.gradient(x -> f4(eltype(x).(A), eltype(x).(b1), x), copy(b2))
204+
205+ @test dA ≈ dA2
206+ @test db1 ≈ db12
207+ @test db2 ≈ db22
208+ =#
209+
178210A = rand (n, n);
179211dA = zeros (n, n);
180212b1 = rand (n);
215247
216248 @test en_jac≈ fd_jac rtol= 1e-4
217249end
250+
251+ # https://github.com/SciML/LinearSolve.jl/issues/479
252+ function testls (A, b, u)
253+ oa = OperatorAssumptions (true , condition = LinearSolve. OperatorCondition. WellConditioned)
254+ prob = LinearProblem (A, b)
255+ linsolve = init (prob, LUFactorization (), assumptions = oa)
256+ cache = solve! (linsolve)
257+ sum (cache. u)
258+ end
259+
260+ A = [1. 2. ; 3. 4. ]
261+ b = [1. , 2. ]
262+ u = zero (b)
263+ dA = deepcopy (A)
264+ db = deepcopy (b)
265+ du = deepcopy (u)
266+ Enzyme. autodiff (Reverse, testls, Duplicated (A, dA), Duplicated (b, db), Duplicated (u, du))
267+
268+ function testls (A, b, u)
269+ oa = OperatorAssumptions (true , condition = LinearSolve. OperatorCondition. WellConditioned)
270+ prob = LinearProblem (A, b)
271+ linsolve = init (prob, LUFactorization (), assumptions = oa)
272+ solve! (linsolve)
273+ sum (linsolve. u)
274+ end
275+ A = [1. 2. ; 3. 4. ]
276+ b = [1. , 2. ]
277+ u = zero (b)
278+ dA2 = deepcopy (A)
279+ db2 = deepcopy (b)
280+ du2 = deepcopy (u)
281+ Enzyme. autodiff (Reverse, testls, Duplicated (A, dA2), Duplicated (b, db2), Duplicated (u, du2))
282+
283+ @test dA == dA2
284+ @test db == db2
285+ @test du == du2
0 commit comments