JuliaDiff / ReverseDiff.jl

Reverse Mode Automatic Differentiation for Julia
Other
347 stars 56 forks source link

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

Open prbzrg opened 10 months ago

prbzrg commented 10 months ago

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 commented 10 months ago
    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 commented 10 months ago

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

https://github.com/JuliaDiff/ReverseDiff.jl/blob/b669294586b0789ab10bbda223543bcec64cf8aa/src/derivatives/arrays.jl#L43-L54

prbzrg commented 10 months ago

CI failed too. so I close the PR. https://github.com/JuliaDiff/ReverseDiff.jl/actions/runs/6694385459/job/18187563784?pr=244#step:6:549

prbzrg commented 7 months ago

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}})