@@ -34,7 +34,7 @@ function test_elementwise(f, fopt, x, tp)
3434 # reverse
3535 out = similar(y, (length(x), length(x)))
3636 ReverseDiff. seeded_reverse_pass!(out, yt, xt, tp)
37- test_approx(out, ForwardDiff. jacobian(z -> map(f, z), x))
37+ test_approx(out, ForwardDiff. jacobian(z -> map(f, z), x); nans = true )
3838
3939 # forward
4040 x2 = x .- offset
@@ -57,7 +57,7 @@ function test_elementwise(f, fopt, x, tp)
5757 # reverse
5858 out = similar(y, (length(x), length(x)))
5959 ReverseDiff. seeded_reverse_pass!(out, yt, xt, tp)
60- test_approx(out, ForwardDiff. jacobian(z -> broadcast(f, z), x))
60+ test_approx(out, ForwardDiff. jacobian(z -> broadcast(f, z), x); nans = true )
6161
6262 # forward
6363 x2 = x .- offset
@@ -81,9 +81,9 @@ function test_map(f, fopt, a, b, tp)
8181 @test length(tp) == 1
8282
8383 # reverse
84- out = similar(c, (length(a ), length(a)))
84+ out = similar(c, (length(c ), length(a)))
8585 ReverseDiff. seeded_reverse_pass!(out, ct, at, tp)
86- test_approx(out, ForwardDiff. jacobian(x -> map(f, x, b), a))
86+ test_approx(out, ForwardDiff. jacobian(x -> map(f, x, b), a); nans = true )
8787
8888 # forward
8989 a2 = a .- offset
@@ -102,9 +102,9 @@ function test_map(f, fopt, a, b, tp)
102102 @test length(tp) == 1
103103
104104 # reverse
105- out = similar(c, (length(a ), length(a )))
105+ out = similar(c, (length(c ), length(b )))
106106 ReverseDiff. seeded_reverse_pass!(out, ct, bt, tp)
107- test_approx(out, ForwardDiff. jacobian(x -> map(f, a, x), b))
107+ test_approx(out, ForwardDiff. jacobian(x -> map(f, a, x), b); nans = true )
108108
109109 # forward
110110 b2 = b .- offset
@@ -123,13 +123,17 @@ function test_map(f, fopt, a, b, tp)
123123 @test length(tp) == 1
124124
125125 # reverse
126- out_a = similar(c, (length(a ), length(a)))
127- out_b = similar(c, (length(a ), length(a )))
126+ out_a = similar(c, (length(c ), length(a)))
127+ out_b = similar(c, (length(c ), length(b )))
128128 ReverseDiff. seeded_reverse_pass!(out_a, ct, at, tp)
129129 ReverseDiff. seeded_reverse_pass!(out_b, ct, bt, tp)
130- test_approx(out_a, ForwardDiff. jacobian(x -> map(f, x, b), a))
131- test_approx(out_b, ForwardDiff. jacobian(x -> map(f, a, x), b))
132-
130+ jac = let a= a, b= b, f= f
131+ ForwardDiff. jacobian(vcat(vec(a), vec(b))) do x
132+ map(f, reshape(x[1 : length(a)], size(a)), reshape(x[(length(a) + 1 ): end ], size(b)))
133+ end
134+ end
135+ test_approx(out_a, jac[:, 1 : length(a)]; nans= true )
136+ test_approx(out_b, jac[:, (length(a) + 1 ): end ]; nans= true )
133137 # forward
134138 a2, b2 = a .- offset, b .- offset
135139 ReverseDiff. value!(at, a2)
@@ -163,7 +167,7 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
163167 # reverse
164168 out = similar(c, (length(c), length(a)))
165169 ReverseDiff. seeded_reverse_pass!(out, ct, at, tp)
166- test_approx(out, ForwardDiff. jacobian(x -> g(x, b), a))
170+ test_approx(out, ForwardDiff. jacobian(x -> g(x, b), a); nans = true )
167171
168172 # forward
169173 a2 = a .- offset
@@ -184,7 +188,7 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
184188 # reverse
185189 out = similar(c, (length(c), length(b)))
186190 ReverseDiff. seeded_reverse_pass!(out, ct, bt, tp)
187- test_approx(out, ForwardDiff. jacobian(x -> g(a, x), b))
191+ test_approx(out, ForwardDiff. jacobian(x -> g(a, x), b); nans = true )
188192
189193 # forward
190194 b2 = b .- offset
@@ -207,8 +211,13 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
207211 out_b = similar(c, (length(c), length(b)))
208212 ReverseDiff. seeded_reverse_pass!(out_a, ct, at, tp)
209213 ReverseDiff. seeded_reverse_pass!(out_b, ct, bt, tp)
210- test_approx(out_a, ForwardDiff. jacobian(x -> g(x, b), a))
211- test_approx(out_b, ForwardDiff. jacobian(x -> g(a, x), b))
214+ jac = let a= a, b= b, g= g
215+ ForwardDiff. jacobian(vcat(vec(a), vec(b))) do x
216+ g(reshape(x[1 : length(a)], size(a)), reshape(x[(length(a) + 1 ): end ], size(b)))
217+ end
218+ end
219+ test_approx(out_a, jac[:, 1 : length(a)]; nans= true )
220+ test_approx(out_b, jac[:, (length(a) + 1 ): end ]; nans= true )
212221
213222 # forward
214223 a2, b2 = a .- offset, b .- offset
@@ -243,7 +252,7 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
243252 # reverse
244253 out = similar(y)
245254 ReverseDiff. seeded_reverse_pass!(out, yt, nt, tp)
246- test_approx(out, ForwardDiff. derivative(z -> g(z, x), n))
255+ test_approx(out, ForwardDiff. derivative(z -> g(z, x), n); nans = true )
247256
248257 # forward
249258 n2 = n + offset
@@ -264,7 +273,7 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
264273 # reverse
265274 out = similar(y, (length(y), length(x)))
266275 ReverseDiff. seeded_reverse_pass!(out, yt, xt, tp)
267- test_approx(out, ForwardDiff. jacobian(z -> g(n, z), x))
276+ test_approx(out, ForwardDiff. jacobian(z -> g(n, z), x); nans = true )
268277
269278 # forward
270279 x2 = x .- offset
@@ -287,8 +296,11 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
287296 out_x = similar(y, (length(y), length(x)))
288297 ReverseDiff. seeded_reverse_pass!(out_n, yt, nt, tp)
289298 ReverseDiff. seeded_reverse_pass!(out_x, yt, xt, tp)
290- test_approx(out_n, ForwardDiff. derivative(z -> g(z, x), n))
291- test_approx(out_x, ForwardDiff. jacobian(z -> g(n, z), x))
299+ jac = let x= x, g= g
300+ ForwardDiff. jacobian(z -> g(z[1 ], reshape(z[2 : end ], size(x))), vcat(n, vec(x)))
301+ end
302+ test_approx(out_n, reshape(jac[:, 1 ], size(y)); nans= true )
303+ test_approx(out_x, jac[:, 2 : end ]; nans= true )
292304
293305 # forward
294306 n2, x2 = n + offset , x .- offset
@@ -323,7 +335,7 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
323335 # reverse
324336 out = similar(y)
325337 ReverseDiff. seeded_reverse_pass!(out, yt, nt, tp)
326- test_approx(out, ForwardDiff. derivative(z -> g(x, z), n))
338+ test_approx(out, ForwardDiff. derivative(z -> g(x, z), n); nans = true )
327339
328340 # forward
329341 n2 = n + offset
@@ -344,7 +356,7 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
344356 # reverse
345357 out = similar(y, (length(y), length(x)))
346358 ReverseDiff. seeded_reverse_pass!(out, yt, xt, tp)
347- test_approx(out, ForwardDiff. jacobian(z -> g(z, n), x))
359+ test_approx(out, ForwardDiff. jacobian(z -> g(z, n), x); nans = true )
348360
349361 # forward
350362 x2 = x .- offset
@@ -367,8 +379,11 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
367379 out_x = similar(y, (length(y), length(x)))
368380 ReverseDiff. seeded_reverse_pass!(out_n, yt, nt, tp)
369381 ReverseDiff. seeded_reverse_pass!(out_x, yt, xt, tp)
370- test_approx(out_n, ForwardDiff. derivative(z -> g(x, z), n))
371- test_approx(out_x, ForwardDiff. jacobian(z -> g(z, n), x))
382+ jac = let x= x, g= g
383+ ForwardDiff. jacobian(z -> g(reshape(z[1 : (end - 1 )], size(x)), z[end ]), vcat(vec(x), n))
384+ end
385+ test_approx(out_x, jac[:, 1 : (end - 1 )]; nans= true )
386+ test_approx(out_n, reshape(jac[:, end ], size(y)); nans= true )
372387
373388 # forward
374389 x2, n2 = x .- offset, n + offset
@@ -393,7 +408,7 @@ for (M, fsym, arity) in DiffRules.diffrules(; filter_modules=nothing)
393408 if ! (isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), fsym))
394409 error(" $M .$fsym is not available" )
395410 end
396- fsym === :rem2pi && continue
411+ (M, fsym) in ReverseDiff . SKIPPED_DIFFRULES && continue
397412 if arity == 1
398413 f = eval(:($ M.$ fsym))
399414 test_println(" forward-mode unary scalar functions" , f)
0 commit comments