Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodError: vcat(::ReverseDiff.TrackedArray{Float32, Float32, 2, Matrix{Float32}, Matrix{Float32}}, ::Matrix{Float32}) is ambiguous. #242

Open
prbzrg opened this issue Oct 27, 2023 · 4 comments

Comments

@prbzrg
Copy link

prbzrg commented Oct 27, 2023

I get this error on Julia 1.10, it's working on Julia 1.9 or if I use cat(...; dims=1) instead.

  MethodError: vcat(::ReverseDiff.TrackedArray{Float32, Float32, 2, Matrix{Float32}, Matrix{Float32}}, ::Matrix{Float32}) is ambiguous.
  
  Candidates:
    vcat(x::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, xs::AbstractMatrix...)
      @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/derivatives/arrays.jl:53
    vcat(X::Union{Number, AbstractVecOrMat{<:Number}}...)
      @ SparseArrays /opt/hostedtoolcache/julia/1.10.0-beta3/x64/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1229
    vcat(x::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, xs::AbstractVecOrMat...)
      @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/derivatives/arrays.jl:53
  
  Possible fix, define
    vcat(::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, ::Vararg{AbstractMatrix{<:Number}})
  

https://github.com/impICNF/ContinuousNormalizingFlows.jl/actions/runs/6660418729/job/18101501796#step:5:18373

@devmotion
Copy link
Member

    vcat(X::Union{Number, AbstractVecOrMat{<:Number}}...)

This method signature seems pretty bad, it's incredibly generic and even covers vcat(). Maybe this is actually a SparseArrays issue?

@prbzrg
Copy link
Author

prbzrg commented Oct 30, 2023

Yes, I agree. But I think arrays should have an eltype in the definitions. e.g. AbstractMatrix{<:Real}.

for T in [
:AbstractVector,
:AbstractMatrix,
:Number,
:AbstractVecOrMat,
:(Union{AbstractVector, Number}),
:Vector,
]
@eval begin
Base.$f($([:($x::$c) for (x, c) in zip(cnames, c)]...), x::TrackedVector, xs::$T...) = track($f, $(cnames...), x, xs...)
Base.$f($([:($x::$c) for (x, c) in zip(cnames, c)]...), x::TrackedMatrix, xs::$T...) = track($f, $(cnames...), x, xs...)
Base.$f($([:($x::$c) for (x, c) in zip(cnames, c)]...), x::TrackedReal, xs::$T...) = track($f, $(cnames...), x, xs...)

@prbzrg
Copy link
Author

prbzrg commented Oct 30, 2023

@prbzrg
Copy link
Author

prbzrg commented Jan 18, 2024

The original error is fixed now, but I'm getting a new error somewhere else in my codes:

  MethodError: vcat(::ReverseDiff.TrackedArray{Float32, Float32, 2, Matrix{Float32}, Matrix{Float32}}, ::Matrix{ReverseDiff.TrackedReal{Float32, Float32, ReverseDiff.TrackedArray{Float32, Float32, 2, Matrix{Float32}, Matrix{Float32}}}}) is ambiguous.
  
  Candidates:
    vcat(x::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, xs::AbstractMatrix...)
      @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/derivatives/arrays.jl:53
    vcat(X1::Union{Number, AbstractVecOrMat{<:Number}}, X::Union{Number, AbstractVecOrMat{<:Number}}...)
      @ SparseArrays /opt/hostedtoolcache/julia/1.10.0/x64/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1235
    vcat(x::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, xs::AbstractVecOrMat...)
      @ ReverseDiff ~/.julia/packages/ReverseDiff/UJhiD/src/derivatives/arrays.jl:53
  
  Possible fix, define
    vcat(::ReverseDiff.TrackedArray{V, D, 2} where {V, D}, ::Vararg{AbstractMatrix{<:Number}})
  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants