@@ -10,9 +10,12 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
10
10
n0, n1, n2 = rand (), rand (), rand ()
11
11
x0, x1, x2 = rand (k), rand (k, k), rand (k, k, k)
12
12
s0, s1, s2 = SVector {k} (rand (k)), SMatrix {k,k} (rand (k, k)), SArray {Tuple{k,k,k}} (rand (k, k, k))
13
+ m0, m1, m2 = MVector {k} (rand (k)), MMatrix {k,k} (rand (k, k)), MArray {Tuple{k,k,k}} (rand (k, k, k))
14
+
13
15
rn = DiffResult (n0, n1, n2)
14
16
rx = DiffResult (x0, x1, x2)
15
17
rs = DiffResult (s0, s1, s2)
18
+ rm = DiffResult (m0, m1, m2)
16
19
rsmix = DiffResult (n0, s0, s1)
17
20
18
21
issimilar (x, y) = typeof (x) == typeof (y) && size (x) == size (y)
@@ -22,6 +25,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
22
25
@test rn === DiffResult (n0, n1, n2)
23
26
@test rx == DiffResult (x0, x1, x2)
24
27
@test rs === DiffResult (s0, s1, s2)
28
+ @test rm == DiffResult (m0, m1, m2)
25
29
@test rsmix === DiffResult (n0, s0, s1)
26
30
27
31
@test issimilar (GradientResult (x0), DiffResult (first (x0), x0))
@@ -34,9 +38,15 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
34
38
@test JacobianResult (SVector {k+1} (vcat (s0, 0.0 )), s0) === DiffResult (SVector {k+1} (vcat (s0, 0.0 )), zeros (SMatrix{k+ 1 ,k,Float64}))
35
39
@test HessianResult (s0) === DiffResult (first (s0), s0, zeros (SMatrix{k,k,Float64}))
36
40
41
+ @test issimilar (GradientResult (m0), DiffResult (first (m0), m0))
42
+ @test issimilar (JacobianResult (m0), DiffResult (m0, zeros (MMatrix{k,k,Float64})))
43
+ @test issimilar (JacobianResult (MVector {k + 1} (vcat (m0, 0.0 )), m0), DiffResult (MVector {k + 1} (vcat (m0, 0.0 )), zeros (MMatrix{k + 1 ,k,Float64})))
44
+ @test issimilar (HessianResult (m0), DiffResult (first (m0), m0, zeros (MMatrix{k,k,Float64})))
45
+
37
46
@test eltype (rn) === typeof (n0)
38
47
@test eltype (rx) === eltype (x0)
39
48
@test eltype (rs) === eltype (s0)
49
+ @test eltype (rm) === eltype (m0)
40
50
41
51
rn_copy = copy (rn)
42
52
@test rn == rn_copy
@@ -50,6 +60,10 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
50
60
@test rs == rs_copy
51
61
@test rs === rs_copy
52
62
63
+ rm_copy = copy (rm)
64
+ @test rm == rm_copy
65
+ @test rm != = rm_copy
66
+
53
67
rsmix_copy = copy (rsmix)
54
68
@test rsmix == rsmix_copy
55
69
@test rsmix === rsmix_copy
@@ -59,6 +73,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
59
73
@test value (rn) === n0
60
74
@test value (rx) === x0
61
75
@test value (rs) === s0
76
+ @test value (rm) === m0
62
77
@test value (rsmix) === n0
63
78
64
79
rn = value! (rn, n1)
@@ -76,6 +91,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
76
91
@test typeof (value (rs)) === typeof (s0)
77
92
rs = value! (rs, s0)
78
93
94
+ m0_new, m0_copy = rand (k), copy (m0)
95
+ rm = value! (rm, m0_new)
96
+ @test value (rm) === m0 == m0_new
97
+ rm = value! (rm, m0_copy)
98
+
79
99
rsmix = value! (rsmix, n1)
80
100
@test value (rsmix) === n1
81
101
rsmix = value! (rsmix, n0)
@@ -95,6 +115,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
95
115
@test typeof (value (rs)) === typeof (s0)
96
116
rs = value! (rs, s0)
97
117
118
+ m0_new, m0_copy = rand (k), copy (m0)
119
+ rm = value! (exp, rm, m0_new)
120
+ @test value (rm) === m0 == exp .(m0_new)
121
+ rm = value! (rm, m0_copy)
122
+
98
123
rsmix = value! (exp, rsmix, n1)
99
124
@test value (rsmix) === exp (n1)
100
125
rsmix = value! (rsmix, n0)
@@ -116,6 +141,9 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
116
141
@test derivative (rs) === s1
117
142
@test derivative (rs, Val{2 }) === s2
118
143
144
+ @test derivative (rm) === m1
145
+ @test derivative (rm, Val{2 }) === m2
146
+
119
147
@test derivative (rsmix) === s0
120
148
@test derivative (rsmix, Val{2 }) === s1
121
149
@@ -140,6 +168,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
140
168
@test typeof (derivative (rsmix)) === typeof (s0)
141
169
rsmix = derivative! (rsmix, s0)
142
170
171
+ m1_new, m1_copy = rand (k, k), copy (m1)
172
+ rm = derivative! (rm, m1_new)
173
+ @test derivative (rm) === m1 == m1_new
174
+ rm = derivative! (rm, m1_copy)
175
+
143
176
rn = derivative! (rn, n1, Val{2 })
144
177
@test derivative (rn, Val{2 }) === n1
145
178
rn = derivative! (rn, n2, Val{2 })
@@ -161,6 +194,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
161
194
@test typeof (derivative (rsmix, Val{2 })) === typeof (s1)
162
195
rsmix = derivative! (rsmix, s1, Val{2 })
163
196
197
+ m2_new, m2_copy = rand (k, k, k), copy (m2)
198
+ rm = derivative! (rm, m2_new, Val{2 })
199
+ @test derivative (rm, Val{2 }) === m2 == m2_new
200
+ rm = derivative! (rm, m2_copy, Val{2 })
201
+
164
202
rn = derivative! (exp, rn, n0)
165
203
@test derivative (rn) === exp (n0)
166
204
rn = derivative! (rn, n1)
@@ -182,6 +220,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
182
220
@test typeof (derivative (rsmix)) === typeof (s0)
183
221
rsmix = derivative! (exp, rsmix, s0)
184
222
223
+ m1_new, m1_copy = rand (k, k), copy (m1)
224
+ rm = derivative! (exp, rm, m1_new)
225
+ @test derivative (rm) === m1 == exp .(m1_new)
226
+ rm = derivative! (exp, rm, m1_copy)
227
+
185
228
rn = derivative! (exp, rn, n1, Val{2 })
186
229
@test derivative (rn, Val{2 }) === exp (n1)
187
230
rn = derivative! (rn, n2, Val{2 })
@@ -202,6 +245,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
202
245
@test derivative (rsmix, Val{2 }) == exp .(s1_new)
203
246
@test typeof (derivative (rsmix, Val{2 })) === typeof (s1)
204
247
rsmix = derivative! (exp, rsmix, s1, Val{2 })
248
+
249
+ m2_new, m2_copy = rand (k, k, k), copy (m2)
250
+ rm = derivative! (exp, rm, m2_new, Val{2 })
251
+ @test derivative (rm, Val{2 }) === m2 == exp .(m2_new)
252
+ rm = derivative! (exp, rm, m2_copy, Val{2 })
205
253
end
206
254
207
255
@testset " gradient/gradient!" begin
@@ -217,6 +265,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
217
265
@test typeof (gradient (rs)) === typeof (s1)
218
266
rs = gradient! (rs, s1)
219
267
268
+ m1_new, m1_copy = rand (k, k), copy (m1)
269
+ rm = gradient! (rm, m1_new)
270
+ @test gradient (rm) === m1 == m1_new
271
+ rm = gradient! (rm, m1_copy)
272
+
220
273
x1_new, x1_copy = rand (k, k), copy (x1)
221
274
rx = gradient! (exp, rx, x1_new)
222
275
@test gradient (rx) === x1 == exp .(x1_new)
@@ -228,6 +281,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
228
281
@test typeof (gradient (rsmix)) === typeof (s0)
229
282
rsmix = gradient! (exp, rsmix, s0)
230
283
284
+ m1_new, m1_copy = rand (k, k), copy (m1)
285
+ rm = gradient! (exp, rm, m1_new)
286
+ @test gradient (rm) === m1 == exp .(m1_new)
287
+ rm = gradient! (exp, rm, m1_copy)
288
+
231
289
T = typeof (SVector {k*k} (rand (k* k)))
232
290
rs_new = gradient! (rs, convert (T, gradient (rs)))
233
291
@test rs_new === rs
@@ -246,6 +304,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
246
304
@test typeof (jacobian (rs)) === typeof (s1)
247
305
rs = jacobian! (rs, s1)
248
306
307
+ m1_new, m1_copy = rand (k, k), copy (m1)
308
+ rm = jacobian! (rm, m1_new)
309
+ @test jacobian (rm) === m1 == m1_new
310
+ rm = jacobian! (rm, m1_copy)
311
+
249
312
x1_new, x1_copy = rand (k, k), copy (x1)
250
313
rx = jacobian! (exp, rx, x1_new)
251
314
@test jacobian (rx) === x1 == exp .(x1_new)
@@ -257,6 +320,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
257
320
@test typeof (jacobian (rsmix)) === typeof (s0)
258
321
rsmix = jacobian! (exp, rsmix, s0)
259
322
323
+ m1_new, m1_copy = rand (k, k), copy (m1)
324
+ rm = jacobian! (exp, rm, m1_new)
325
+ @test jacobian (rm) === m1 == exp .(m1_new)
326
+ rm = jacobian! (exp, rm, m1_copy)
327
+
260
328
T = typeof (SVector {k*k} (rand (k* k)))
261
329
rs_new = jacobian! (rs, convert (T, jacobian (rs)))
262
330
@test rs_new === rs
@@ -275,6 +343,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
275
343
@test typeof (hessian (rs)) === typeof (s2)
276
344
rs = hessian! (rs, s2)
277
345
346
+ m2_new, m2_copy = rand (k, k, k), copy (m2)
347
+ rm = hessian! (rm, m2_new)
348
+ @test hessian (rm) === m2 == m2_new
349
+ rm = hessian! (rm, m2_copy)
350
+
278
351
x2_new, x2_copy = rand (k, k, k), copy (x2)
279
352
rx = hessian! (exp, rx, x2_new)
280
353
@test hessian (rx) === x2 == exp .(x2_new)
@@ -286,6 +359,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
286
359
@test typeof (hessian (rsmix)) === typeof (s1)
287
360
rsmix = hessian! (exp, rsmix, s1)
288
361
362
+ m2_new, m2_copy = rand (k, k, k), copy (m2)
363
+ rm = hessian! (exp, rm, m2_new)
364
+ @test hessian (rm) === m2 == exp .(m2_new)
365
+ rm = hessian! (exp, rm, m2_copy)
366
+
289
367
T = typeof (SVector {k*k*k} (rand (k* k* k)))
290
368
rs_new = hessian! (rs, convert (T, hessian (rs)))
291
369
@test rs_new === rs
0 commit comments