# Ambiguity error on vcat()

**URL:** https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845
**Category:** General Usage
**Tags:** question
**Created:** [May 4, 2019, 12:19pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845 "2019-05-04T12:19:39Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [May 4, 2019, 12:19pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/1 "2019-05-04T12:19:39Z")

</div>

I have this error

```julia
ERROR: MethodError: vcat(::Array{Real,2}, ::TrackedArray{…,Array{Float32,2}}) is ambiguous. Candidates:
  vcat(364::AbstractArray, x::Union{TrackedArray, TrackedReal}, xs::Union{Number, AbstractArray}...) in Tracker at C:\Users\Henri\.julia\packages\Tracker\6wcYJ\src\lib\array.jl:167
  vcat(A::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T...) in Base at abstractarray.jl:1296
Possible fix, define
  vcat(::Union{AbstractArray{T,2}, AbstractArray{T,1}} where T, ::Union{TrackedArray{T,1,A} where A<:AbstractArray{T,1} where T, TrackedArray{T,2,A} where A<:AbstractArray{T,2} where T}, ::Vararg{Union{AbstractArray{T,2}, AbstractArray{T,1}} where T,N} where N)

```

Telling me that two `vcat()` functions are ambiguous. I want to use the `Base.vcat()` function but using it explicitly throws the same error. Why is that ? And what is this “possible fix” proposed by the error throw?

Here is a code that reproduces the error:

```julia
using Flux

function loss(a, b, net, net2)
    net2(vcat(net(a),a))
    
end

function test()    
    opt = ADAM()
    net = Chain(Dense(3,3))
    net2 = Chain(Dense(6,1))
    L(a, b) = loss(a, b, net, net2)

    data = tuple(rand(3,1), rand(3,1))
    xs = Flux.params(net)
    gs = Tracker.gradient(() -> L(data...), xs)
    Tracker.update!(opt, xs, gs)
end

```

Moreover, when I call manually each line inside the function in the REPL no error is thrown. I do not understand this behavior. This only happens when vcat() is in a function called inside another function. Like in my example above.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 4, 2019, 5:03pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/2 "2019-05-04T17:03:46Z")

</div>

I can replicate this. The fix is suggested in the error message (define a method for the intersection). Check if there is an issue for Flux about this, and if not, open one. Or ideally, you could make a PR fixing this.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [May 4, 2019, 5:37pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/3 "2019-05-04T17:37:16Z")

</div>

Already reported to Flux (by OP?) but seems it was closed: [https://github.com/FluxML/Flux.jl/issues/763](https://github.com/FluxML/Flux.jl/issues/763)

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [May 4, 2019, 5:51pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/4 "2019-05-04T17:51:09Z")

</div>

> [@kristoffer.carlsson](#):
>
> Already reported to Flux (by OP?) but seems it was closed: [ambiguity error on vcat · Issue #27 · FluxML/Tracker.jl · GitHub](https://github.com/FluxML/Flux.jl/issues/763)

Yes, I closed because I thought this was not related to Flux. You think I should re-open ?

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [May 4, 2019, 5:51pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/5 "2019-05-04T17:51:14Z")

</div>

Hi, @Tamas_Papp

I’d gladly make a PR to fix this but here are three things:

1. The error can be corrected by calling `net2(vcat(net(a), Float32.(a)))`
2. The error message I show is from my actual project, where instead of an `Array{Float64,2}` (as in my example) it’s an `Array{Real,2}`. That, I think would have to be corrected using another new definition.
3. I don’t really know what to put in the body of the new definition of vcat(). I’m kind of a beginner.

(Still, the fact that the error happens when called inside a function but not when lines are sequentially sent to the REPL is weird and) I’m not even sure that’s specific to `TrackedArray`, thus not specific to Flux. This may happen with other packages proposing AbstractArrays.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 4, 2019, 6:23pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/6 "2019-05-04T18:23:48Z")

</div>

> [@HenriDeh](#):
>
> the error happens when called inside a function but not when lines are sequentially sent to the REPL

I get the same error when sending the lines in `test()` to the REPL directly.

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [May 4, 2019, 6:36pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/7 "2019-05-04T18:36:18Z")

</div>

@Tamas_Papp Oh… yes. I guess I must have been doing it slightly different in the REPL to not get the error. My bad, not very rigorous of me. Still, the rest of my message stays relevant.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 4, 2019, 6:49pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/8 "2019-05-04T18:49:42Z")

</div>

> [@HenriDeh](#):
>
> Still, the rest of my message stays relevant.

So does mine about opening an issue. You may want to just reopen the one above, edit and remove the red herring about the REPL, and then it can be fixed in Flux.

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [May 4, 2019, 7:05pm UTC](https://discourse.julialang.org/t/ambiguity-error-on-vcat/23845/9 "2019-05-04T19:05:18Z")

</div>

Okay sure, it’s done. Thank you for your help.
