# Dual{::ForwardDiff...} type error when JuMP tries autodiff User-defined Function

**URL:** https://discourse.julialang.org/t/dual-forwarddiff-type-error-when-jump-tries-autodiff-user-defined-function/25639
**Category:** Optimization (Mathematical)
**Created:** [June 25, 2019, 6:20am UTC](https://discourse.julialang.org/t/dual-forwarddiff-type-error-when-jump-tries-autodiff-user-defined-function/25639 "2019-06-25T06:20:46Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [July 1, 2019, 8:21pm UTC](https://discourse.julialang.org/t/dual-forwarddiff-type-error-when-jump-tries-autodiff-user-defined-function/25639/6 "2019-07-01T20:21:26Z")

</div>

The problem is that typing the elements of the vector as `Real` is not a concrete type.

Instead of

```nohighlight
function foo(x)
    y = Vector{Real}(undef, 2)
    y[1] = x
    y[2] = 2 * x
    return sum(y)
end

```

Type the elements of the vector based on the input arguments

```nohighlight
function foo(x::T) where {T <: Real}
    y = Vector{T}(undef, 2)
    y[1] = x
    y[2] = 2 * x
    return sum(y)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/dual-forwarddiff-type-error-when-jump-tries-autodiff-user-defined-function/25639)._
