# Correct Way to Compose ReverseDiff and ForwardDiff

**URL:** <https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708>\
**Category:** Optimization (Mathematical)\
**Tags:** forwarddiff, reversediff, dual\
**Created:** [July 3, 2022, 4:35pm UTC](https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708 "2022-07-03T16:35:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [July 4, 2022, 2:54am UTC](https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708/2 "2022-07-04T02:54:05Z")

</div>

Related thread:

> [@Mixed-mode automatic differentiation using ForwardDiff and ReverseDiff](https://discourse.julialang.org/t/mixed-mode-automatic-differentiation-using-forwarddiff-and-reversediff/74440):
>
> I need to take the gradient of a function. I can use ForwardDiff without any issues, but for part of my code I have found ReverseDiff to run much faster. The issue is that the other part of my code errors with ReverseDiff. The basic structure of my code looks something like function take\_my\_gradient(x) tmp = errors\_with\_reversediff(x) faster\_with\_reversediff(tmp) end Is it possible to differentiate my function using ForwardDiff on the part that doesn’t work with ReverseDiff and using…

---

_[View the full topic](https://discourse.julialang.org/t/correct-way-to-compose-reversediff-and-forwarddiff/83708)._
