@@ -305,44 +305,56 @@ function DI.value_and_gradient!(
305
305
f:: F ,
306
306
grad,
307
307
prep:: ForwardDiffGradientPrep ,
308
- :: AutoForwardDiff ,
308
+ backend :: AutoForwardDiff ,
309
309
x,
310
310
contexts:: Vararg{Constant,C} ,
311
311
) where {F,C}
312
312
fc = with_contexts (f, contexts... )
313
313
result = DiffResult (zero (eltype (x)), (grad,))
314
- result = gradient! (result, fc, x, prep. config)
314
+ CHK = tag_type (backend) === Nothing
315
+ result = gradient! (result, fc, x, prep. config, Val (CHK))
315
316
y = DR. value (result)
316
317
grad === DR. gradient (result) || copyto! (grad, DR. gradient (result))
317
318
return y, grad
318
319
end
319
320
320
321
function DI. value_and_gradient (
321
- f:: F , prep:: ForwardDiffGradientPrep , :: AutoForwardDiff , x, contexts:: Vararg{Constant,C}
322
+ f:: F ,
323
+ prep:: ForwardDiffGradientPrep ,
324
+ backend:: AutoForwardDiff ,
325
+ x,
326
+ contexts:: Vararg{Constant,C} ,
322
327
) where {F,C}
323
328
fc = with_contexts (f, contexts... )
324
329
result = GradientResult (x)
325
- result = gradient! (result, fc, x, prep. config)
330
+ CHK = tag_type (backend) === Nothing
331
+ result = gradient! (result, fc, x, prep. config, Val (CHK))
326
332
return DR. value (result), DR. gradient (result)
327
333
end
328
334
329
335
function DI. gradient! (
330
336
f:: F ,
331
337
grad,
332
338
prep:: ForwardDiffGradientPrep ,
333
- :: AutoForwardDiff ,
339
+ backend :: AutoForwardDiff ,
334
340
x,
335
341
contexts:: Vararg{Constant,C} ,
336
342
) where {F,C}
337
343
fc = with_contexts (f, contexts... )
338
- return gradient! (grad, fc, x, prep. config)
344
+ CHK = tag_type (backend) === Nothing
345
+ return gradient! (grad, fc, x, prep. config, Val (CHK))
339
346
end
340
347
341
348
function DI. gradient (
342
- f:: F , prep:: ForwardDiffGradientPrep , :: AutoForwardDiff , x, contexts:: Vararg{Constant,C}
349
+ f:: F ,
350
+ prep:: ForwardDiffGradientPrep ,
351
+ backend:: AutoForwardDiff ,
352
+ x,
353
+ contexts:: Vararg{Constant,C} ,
343
354
) where {F,C}
344
355
fc = with_contexts (f, contexts... )
345
- return gradient (fc, x, prep. config)
356
+ CHK = tag_type (backend) === Nothing
357
+ return gradient (fc, x, prep. config, Val (CHK))
346
358
end
347
359
348
360
# # Jacobian
@@ -422,14 +434,15 @@ function DI.value_and_jacobian!(
422
434
f:: F ,
423
435
jac,
424
436
prep:: ForwardDiffOneArgJacobianPrep ,
425
- :: AutoForwardDiff ,
437
+ backend :: AutoForwardDiff ,
426
438
x,
427
439
contexts:: Vararg{Constant,C} ,
428
440
) where {F,C}
429
441
fc = with_contexts (f, contexts... )
430
442
y = fc (x)
431
443
result = DiffResult (y, (jac,))
432
- result = jacobian! (result, fc, x, prep. config)
444
+ CHK = tag_type (backend) === Nothing
445
+ result = jacobian! (result, fc, x, prep. config, Val (CHK))
433
446
y = DR. value (result)
434
447
jac === DR. jacobian (result) || copyto! (jac, DR. jacobian (result))
435
448
return y, jac
@@ -438,35 +451,38 @@ end
438
451
function DI. value_and_jacobian (
439
452
f:: F ,
440
453
prep:: ForwardDiffOneArgJacobianPrep ,
441
- :: AutoForwardDiff ,
454
+ backend :: AutoForwardDiff ,
442
455
x,
443
456
contexts:: Vararg{Constant,C} ,
444
457
) where {F,C}
445
458
fc = with_contexts (f, contexts... )
446
- return fc (x), jacobian (fc, x, prep. config)
459
+ CHK = tag_type (backend) === Nothing
460
+ return fc (x), jacobian (fc, x, prep. config, Val (CHK))
447
461
end
448
462
449
463
function DI. jacobian! (
450
464
f:: F ,
451
465
jac,
452
466
prep:: ForwardDiffOneArgJacobianPrep ,
453
- :: AutoForwardDiff ,
467
+ backend :: AutoForwardDiff ,
454
468
x,
455
469
contexts:: Vararg{Constant,C} ,
456
470
) where {F,C}
457
471
fc = with_contexts (f, contexts... )
458
- return jacobian! (jac, fc, x, prep. config)
472
+ CHK = tag_type (backend) === Nothing
473
+ return jacobian! (jac, fc, x, prep. config, Val (CHK))
459
474
end
460
475
461
476
function DI. jacobian (
462
477
f:: F ,
463
478
prep:: ForwardDiffOneArgJacobianPrep ,
464
- :: AutoForwardDiff ,
479
+ backend :: AutoForwardDiff ,
465
480
x,
466
481
contexts:: Vararg{Constant,C} ,
467
482
) where {F,C}
468
483
fc = with_contexts (f, contexts... )
469
- return jacobian (fc, x, prep. config)
484
+ CHK = tag_type (backend) === Nothing
485
+ return jacobian (fc, x, prep. config, Val (CHK))
470
486
end
471
487
472
488
# # Second derivative
@@ -681,44 +697,56 @@ function DI.hessian!(
681
697
f:: F ,
682
698
hess,
683
699
prep:: ForwardDiffHessianPrep ,
684
- :: AutoForwardDiff ,
700
+ backend :: AutoForwardDiff ,
685
701
x,
686
702
contexts:: Vararg{Constant,C} ,
687
703
) where {F,C}
688
704
fc = with_contexts (f, contexts... )
689
- return hessian! (hess, fc, x, prep. array_config)
705
+ CHK = tag_type (backend) === Nothing
706
+ return hessian! (hess, fc, x, prep. array_config, Val (CHK))
690
707
end
691
708
692
709
function DI. hessian (
693
- f:: F , prep:: ForwardDiffHessianPrep , :: AutoForwardDiff , x, contexts:: Vararg{Constant,C}
710
+ f:: F ,
711
+ prep:: ForwardDiffHessianPrep ,
712
+ backend:: AutoForwardDiff ,
713
+ x,
714
+ contexts:: Vararg{Constant,C} ,
694
715
) where {F,C}
695
716
fc = with_contexts (f, contexts... )
696
- return hessian (fc, x, prep. array_config)
717
+ CHK = tag_type (backend) === Nothing
718
+ return hessian (fc, x, prep. array_config, Val (CHK))
697
719
end
698
720
699
721
function DI. value_gradient_and_hessian! (
700
722
f:: F ,
701
723
grad,
702
724
hess,
703
725
prep:: ForwardDiffHessianPrep ,
704
- :: AutoForwardDiff ,
726
+ backend :: AutoForwardDiff ,
705
727
x,
706
728
contexts:: Vararg{Constant,C} ,
707
729
) where {F,C}
708
730
fc = with_contexts (f, contexts... )
709
731
result = DiffResult (one (eltype (x)), (grad, hess))
710
- result = hessian! (result, fc, x, prep. result_config)
732
+ CHK = tag_type (backend) === Nothing
733
+ result = hessian! (result, fc, x, prep. result_config, Val (CHK))
711
734
y = DR. value (result)
712
735
grad === DR. gradient (result) || copyto! (grad, DR. gradient (result))
713
736
hess === DR. hessian (result) || copyto! (hess, DR. hessian (result))
714
737
return (y, grad, hess)
715
738
end
716
739
717
740
function DI. value_gradient_and_hessian (
718
- f:: F , prep:: ForwardDiffHessianPrep , :: AutoForwardDiff , x, contexts:: Vararg{Constant,C}
741
+ f:: F ,
742
+ prep:: ForwardDiffHessianPrep ,
743
+ backend:: AutoForwardDiff ,
744
+ x,
745
+ contexts:: Vararg{Constant,C} ,
719
746
) where {F,C}
720
747
fc = with_contexts (f, contexts... )
721
748
result = HessianResult (x)
722
- result = hessian! (result, fc, x, prep. result_config)
749
+ CHK = tag_type (backend) === Nothing
750
+ result = hessian! (result, fc, x, prep. result_config, Val (CHK))
723
751
return (DR. value (result), DR. gradient (result), DR. hessian (result))
724
752
end
0 commit comments