@@ -10,9 +10,12 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
1010 n0, n1, n2 = rand (), rand (), rand ()
1111 x0, x1, x2 = rand (k), rand (k, k), rand (k, k, k)
1212 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+
1315 rn = DiffResult (n0, n1, n2)
1416 rx = DiffResult (x0, x1, x2)
1517 rs = DiffResult (s0, s1, s2)
18+ rm = DiffResult (m0, m1, m2)
1619 rsmix = DiffResult (n0, s0, s1)
1720
1821 issimilar (x, y) = typeof (x) == typeof (y) && size (x) == size (y)
@@ -22,6 +25,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
2225 @test rn === DiffResult (n0, n1, n2)
2326 @test rx == DiffResult (x0, x1, x2)
2427 @test rs === DiffResult (s0, s1, s2)
28+ @test rm == DiffResult (m0, m1, m2)
2529 @test rsmix === DiffResult (n0, s0, s1)
2630
2731 @test issimilar (GradientResult (x0), DiffResult (first (x0), x0))
@@ -34,9 +38,15 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
3438 @test JacobianResult (SVector {k+1} (vcat (s0, 0.0 )), s0) === DiffResult (SVector {k+1} (vcat (s0, 0.0 )), zeros (SMatrix{k+ 1 ,k,Float64}))
3539 @test HessianResult (s0) === DiffResult (first (s0), s0, zeros (SMatrix{k,k,Float64}))
3640
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+
3746 @test eltype (rn) === typeof (n0)
3847 @test eltype (rx) === eltype (x0)
3948 @test eltype (rs) === eltype (s0)
49+ @test eltype (rm) === eltype (m0)
4050
4151 rn_copy = copy (rn)
4252 @test rn == rn_copy
@@ -50,6 +60,10 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
5060 @test rs == rs_copy
5161 @test rs === rs_copy
5262
63+ rm_copy = copy (rm)
64+ @test rm == rm_copy
65+ @test rm != = rm_copy
66+
5367 rsmix_copy = copy (rsmix)
5468 @test rsmix == rsmix_copy
5569 @test rsmix === rsmix_copy
@@ -59,6 +73,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
5973 @test value (rn) === n0
6074 @test value (rx) === x0
6175 @test value (rs) === s0
76+ @test value (rm) === m0
6277 @test value (rsmix) === n0
6378
6479 rn = value! (rn, n1)
@@ -76,6 +91,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
7691 @test typeof (value (rs)) === typeof (s0)
7792 rs = value! (rs, s0)
7893
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+
7999 rsmix = value! (rsmix, n1)
80100 @test value (rsmix) === n1
81101 rsmix = value! (rsmix, n0)
@@ -95,6 +115,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
95115 @test typeof (value (rs)) === typeof (s0)
96116 rs = value! (rs, s0)
97117
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+
98123 rsmix = value! (exp, rsmix, n1)
99124 @test value (rsmix) === exp (n1)
100125 rsmix = value! (rsmix, n0)
@@ -116,6 +141,9 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
116141 @test derivative (rs) === s1
117142 @test derivative (rs, Val{2 }) === s2
118143
144+ @test derivative (rm) === m1
145+ @test derivative (rm, Val{2 }) === m2
146+
119147 @test derivative (rsmix) === s0
120148 @test derivative (rsmix, Val{2 }) === s1
121149
@@ -140,6 +168,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
140168 @test typeof (derivative (rsmix)) === typeof (s0)
141169 rsmix = derivative! (rsmix, s0)
142170
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+
143176 rn = derivative! (rn, n1, Val{2 })
144177 @test derivative (rn, Val{2 }) === n1
145178 rn = derivative! (rn, n2, Val{2 })
@@ -161,6 +194,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
161194 @test typeof (derivative (rsmix, Val{2 })) === typeof (s1)
162195 rsmix = derivative! (rsmix, s1, Val{2 })
163196
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+
164202 rn = derivative! (exp, rn, n0)
165203 @test derivative (rn) === exp (n0)
166204 rn = derivative! (rn, n1)
@@ -182,6 +220,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
182220 @test typeof (derivative (rsmix)) === typeof (s0)
183221 rsmix = derivative! (exp, rsmix, s0)
184222
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+
185228 rn = derivative! (exp, rn, n1, Val{2 })
186229 @test derivative (rn, Val{2 }) === exp (n1)
187230 rn = derivative! (rn, n2, Val{2 })
@@ -202,6 +245,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
202245 @test derivative (rsmix, Val{2 }) == exp .(s1_new)
203246 @test typeof (derivative (rsmix, Val{2 })) === typeof (s1)
204247 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 })
205253 end
206254
207255 @testset " gradient/gradient!" begin
@@ -217,6 +265,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
217265 @test typeof (gradient (rs)) === typeof (s1)
218266 rs = gradient! (rs, s1)
219267
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+
220273 x1_new, x1_copy = rand (k, k), copy (x1)
221274 rx = gradient! (exp, rx, x1_new)
222275 @test gradient (rx) === x1 == exp .(x1_new)
@@ -228,6 +281,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
228281 @test typeof (gradient (rsmix)) === typeof (s0)
229282 rsmix = gradient! (exp, rsmix, s0)
230283
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+
231289 T = typeof (SVector {k*k} (rand (k* k)))
232290 rs_new = gradient! (rs, convert (T, gradient (rs)))
233291 @test rs_new === rs
@@ -246,6 +304,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
246304 @test typeof (jacobian (rs)) === typeof (s1)
247305 rs = jacobian! (rs, s1)
248306
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+
249312 x1_new, x1_copy = rand (k, k), copy (x1)
250313 rx = jacobian! (exp, rx, x1_new)
251314 @test jacobian (rx) === x1 == exp .(x1_new)
@@ -257,6 +320,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
257320 @test typeof (jacobian (rsmix)) === typeof (s0)
258321 rsmix = jacobian! (exp, rsmix, s0)
259322
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+
260328 T = typeof (SVector {k*k} (rand (k* k)))
261329 rs_new = jacobian! (rs, convert (T, jacobian (rs)))
262330 @test rs_new === rs
@@ -275,6 +343,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
275343 @test typeof (hessian (rs)) === typeof (s2)
276344 rs = hessian! (rs, s2)
277345
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+
278351 x2_new, x2_copy = rand (k, k, k), copy (x2)
279352 rx = hessian! (exp, rx, x2_new)
280353 @test hessian (rx) === x2 == exp .(x2_new)
@@ -286,6 +359,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
286359 @test typeof (hessian (rsmix)) === typeof (s1)
287360 rsmix = hessian! (exp, rsmix, s1)
288361
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+
289367 T = typeof (SVector {k*k*k} (rand (k* k* k)))
290368 rs_new = hessian! (rs, convert (T, hessian (rs)))
291369 @test rs_new === rs
0 commit comments