1
1
using LinearSolve
2
2
using ForwardDiff
3
3
using Test
4
+ using SparseArrays
4
5
5
6
function h (p)
6
7
(A = [p[1 ] p[2 ]+ 1 p[2 ]^ 3 ;
@@ -48,6 +49,9 @@ new_A, new_b = h([ForwardDiff.Dual(5.0, 1.0, 0.0), ForwardDiff.Dual(5.0, 0.0, 1.
48
49
cache. A = new_A
49
50
cache. b = new_b
50
51
52
+ @test cache. A == new_A
53
+ @test cache. b == new_b
54
+
51
55
x_p = solve! (cache)
52
56
backslash_x_p = new_A \ new_b
53
57
@@ -61,7 +65,7 @@ cache = init(prob)
61
65
62
66
new_A, _ = h ([ForwardDiff. Dual (5.0 , 1.0 , 0.0 ), ForwardDiff. Dual (5.0 , 0.0 , 1.0 )])
63
67
cache. A = new_A
64
- @test cache. A = new_A
68
+ @test cache. A == new_A
65
69
66
70
x_p = solve! (cache)
67
71
backslash_x_p = new_A \ b
139
143
140
144
@test ≈ (ForwardDiff. hessian (slash_f_hes, [5.0 ]),
141
145
ForwardDiff. hessian (linprob_f_hes, [5.0 ]))
146
+
147
+
148
+ # Test aliasing
149
+
150
+ prob = LinearProblem (A, b)
151
+ cache = init (prob)
152
+
153
+ new_A, new_b = h ([ForwardDiff. Dual (5.0 , 1.0 , 0.0 ), ForwardDiff. Dual (5.0 , 0.0 , 1.0 )])
154
+ cache. A = new_A
155
+ cache. b = new_b
156
+
157
+ linu = [ForwardDiff. Dual (0.0 , 0.0 , 0.0 ), ForwardDiff. Dual (0.0 , 0.0 , 0.0 ),
158
+ ForwardDiff. Dual (0.0 , 0.0 , 0.0 )]
159
+ cache. u = linu
160
+ x_p = solve! (cache)
161
+ backslash_x_p = new_A \ new_b
162
+
163
+ @test linu == cache. u
164
+
165
+
166
+ # Test Float Only solvers
167
+
168
+ A, b = h ([ForwardDiff. Dual (5.0 , 1.0 , 0.0 ), ForwardDiff. Dual (5.0 , 0.0 , 1.0 )])
169
+
170
+ prob = LinearProblem (sparse (A), sparse (b))
171
+ overload_x_p = solve (prob, KLUFactorization ())
172
+ backslash_x_p = A \ b
173
+
174
+ @test ≈ (overload_x_p, backslash_x_p, rtol = 1e-9 )
175
+
176
+ A, b = h ([ForwardDiff. Dual (5.0 , 1.0 , 0.0 ), ForwardDiff. Dual (5.0 , 0.0 , 1.0 )])
177
+
178
+ prob = LinearProblem (A, b)
179
+ overload_x_p = solve (prob, UMFPACKFactorization ())
180
+ backslash_x_p = A \ b
181
+
182
+ @test ≈ (overload_x_p, backslash_x_p, rtol = 1e-9 )
0 commit comments