# ForwardDiff - slowed down by Real vs. Float operations

**URL:** <https://discourse.julialang.org/t/forwarddiff-slowed-down-by-real-vs-float-operations/36987>\
**Category:** General Usage\
**Tags:** question, type\
**Created:** [April 3, 2020, 9:10pm UTC](https://discourse.julialang.org/t/forwarddiff-slowed-down-by-real-vs-float-operations/36987 "2020-04-03T21:10:51Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [April 3, 2020, 9:42pm UTC](https://discourse.julialang.org/t/forwarddiff-slowed-down-by-real-vs-float-operations/36987/4 "2020-04-03T21:42:30Z")

</div>

Building off on @Elrod’s suggestion, note that you can also do

```julia
julia> function foo(x::Array{T}) where {T<:Real}
           M = zeros(T, 1, 1, 1)
           # do stuff with M
       end
foo (generic function with 1 methods)

julia> ForwardDiff.gradient(foo, rand(31))

```

Note that parametrizing the type of the input function will also lead to the kind of specialized code which I think @Sukera is hinting at in his reply. The current issue seems to be that the conversion to `Real` is happening at run-time which is slowing down your code.

---

_[View the full topic](https://discourse.julialang.org/t/forwarddiff-slowed-down-by-real-vs-float-operations/36987)._
