Skip to content

Commit a490d1d

Browse files
jClugstorChrisRackauckas
authored andcommitted
add Dual problem JET tests
1 parent 16c6dc8 commit a490d1d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test/nopre/jet.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LinearSolve, RecursiveFactorization, LinearAlgebra, SparseArrays, Test
1+
using LinearSolve, ForwardDiff, RecursiveFactorization, LinearAlgebra, SparseArrays, Test
22
using JET
33

44
# Dense problem setup
@@ -22,6 +22,18 @@ prob_sparse = LinearProblem(A_sparse, b)
2222
A_sparse_spd = sparse(A_spd)
2323
prob_sparse_spd = LinearProblem(A_sparse_spd, b)
2424

25+
# Dual problem set up
26+
function h(p)
27+
(A = [p[1] p[2]+1 p[2]^3;
28+
3*p[1] p[1]+5 p[2] * p[1]-4;
29+
p[2]^2 9*p[1] p[2]],
30+
b = [p[1] + 1, p[2] * 2, p[1]^2])
31+
end
32+
33+
A, b = h([ForwardDiff.Dual(5.0, 1.0, 0.0), ForwardDiff.Dual(5.0, 0.0, 1.0)])
34+
35+
dual_prob = LinearProblem(A, b)
36+
2537
@testset "JET Tests for Dense Factorizations" begin
2638
# Working tests - these pass JET optimization checks
2739
JET.@test_opt init(prob, nothing)
@@ -109,3 +121,11 @@ end
109121
JET.@test_opt solve(prob) broken=true
110122
JET.@test_opt solve(prob_sparse) broken=true
111123
end
124+
125+
@testset "JET Tests for creating Dual solutions" begin
126+
# Make sure there's no runtime dispatch when making solutions of Dual problems
127+
dual_cache = init(prob)
128+
ext = Base.get_extension(LinearSolve, :LinearSolveForwardDiffExt)
129+
JET.@test_opt ext.linearsolve_dual_solution(
130+
[1.0, 1.0, 1.0], [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]], cache)
131+
end

0 commit comments

Comments
 (0)