@@ -34,7 +34,7 @@ function test_elementwise(f, fopt, x, tp)
34
34
# reverse
35
35
out = similar (y, (length (x), length (x)))
36
36
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 )
38
38
39
39
# forward
40
40
x2 = x .- offset
@@ -57,7 +57,7 @@ function test_elementwise(f, fopt, x, tp)
57
57
# reverse
58
58
out = similar (y, (length (x), length (x)))
59
59
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 )
61
61
62
62
# forward
63
63
x2 = x .- offset
@@ -81,9 +81,9 @@ function test_map(f, fopt, a, b, tp)
81
81
@test length (tp) == 1
82
82
83
83
# reverse
84
- out = similar (c, (length (a ), length (a)))
84
+ out = similar (c, (length (c ), length (a)))
85
85
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 )
87
87
88
88
# forward
89
89
a2 = a .- offset
@@ -102,9 +102,9 @@ function test_map(f, fopt, a, b, tp)
102
102
@test length (tp) == 1
103
103
104
104
# reverse
105
- out = similar (c, (length (a ), length (a )))
105
+ out = similar (c, (length (c ), length (b )))
106
106
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 )
108
108
109
109
# forward
110
110
b2 = b .- offset
@@ -123,13 +123,17 @@ function test_map(f, fopt, a, b, tp)
123
123
@test length (tp) == 1
124
124
125
125
# 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 )))
128
128
ReverseDiff. seeded_reverse_pass! (out_a, ct, at, tp)
129
129
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 )
133
137
# forward
134
138
a2, b2 = a .- offset, b .- offset
135
139
ReverseDiff. value! (at, a2)
@@ -163,7 +167,7 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
163
167
# reverse
164
168
out = similar (c, (length (c), length (a)))
165
169
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 )
167
171
168
172
# forward
169
173
a2 = a .- offset
@@ -184,7 +188,7 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
184
188
# reverse
185
189
out = similar (c, (length (c), length (b)))
186
190
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 )
188
192
189
193
# forward
190
194
b2 = b .- offset
@@ -207,8 +211,13 @@ function test_broadcast(f, fopt, a::AbstractArray, b::AbstractArray, tp, builtin
207
211
out_b = similar (c, (length (c), length (b)))
208
212
ReverseDiff. seeded_reverse_pass! (out_a, ct, at, tp)
209
213
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 )
212
221
213
222
# forward
214
223
a2, b2 = a .- offset, b .- offset
@@ -243,7 +252,7 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
243
252
# reverse
244
253
out = similar (y)
245
254
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 )
247
256
248
257
# forward
249
258
n2 = n + offset
@@ -264,7 +273,7 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
264
273
# reverse
265
274
out = similar (y, (length (y), length (x)))
266
275
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 )
268
277
269
278
# forward
270
279
x2 = x .- offset
@@ -287,8 +296,11 @@ function test_broadcast(f, fopt, n::Number, x::AbstractArray, tp, builtin::Bool
287
296
out_x = similar (y, (length (y), length (x)))
288
297
ReverseDiff. seeded_reverse_pass! (out_n, yt, nt, tp)
289
298
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 )
292
304
293
305
# forward
294
306
n2, x2 = n + offset , x .- offset
@@ -323,7 +335,7 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
323
335
# reverse
324
336
out = similar (y)
325
337
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 )
327
339
328
340
# forward
329
341
n2 = n + offset
@@ -344,7 +356,7 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
344
356
# reverse
345
357
out = similar (y, (length (y), length (x)))
346
358
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 )
348
360
349
361
# forward
350
362
x2 = x .- offset
@@ -367,8 +379,11 @@ function test_broadcast(f, fopt, x::AbstractArray, n::Number, tp, builtin::Bool
367
379
out_x = similar (y, (length (y), length (x)))
368
380
ReverseDiff. seeded_reverse_pass! (out_n, yt, nt, tp)
369
381
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 )
372
387
373
388
# forward
374
389
x2, n2 = x .- offset, n + offset
@@ -393,7 +408,7 @@ for (M, fsym, arity) in DiffRules.diffrules(; filter_modules=nothing)
393
408
if ! (isdefined (@__MODULE__ , M) && isdefined (getfield (@__MODULE__ , M), fsym))
394
409
error (" $M .$fsym is not available" )
395
410
end
396
- fsym === :rem2pi && continue
411
+ (M, fsym) in ReverseDiff . SKIPPED_DIFFRULES && continue
397
412
if arity == 1
398
413
f = eval (:($ M.$ fsym))
399
414
test_println (" forward-mode unary scalar functions" , f)
0 commit comments