-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
MWE:
using ReverseDiff
function f2(x)
xv = @view x[1:end-1]
xend = x[end]
x = [xv; xend]
return sum(x)
end
ReverseDiff.gradient(f2, rand(10)) # works
using SparseArrays
ReverseDiff.gradient(f2, rand(10)) # fails
#=
ERROR: MethodError: vcat(::SubArray{…}, ::ReverseDiff.TrackedReal{…}) is ambiguous.
Candidates:
vcat(var"389"::AbstractVector, x::ReverseDiff.TrackedReal)
@ ReverseDiff ~/.julia/packages/ReverseDiff/rKZaG/src/derivatives/arrays.jl:41
vcat(X1::Union{Number, AbstractVecOrMat{<:Number}}, X::Union{Number, AbstractVecOrMat{<:Number}}...)
@ SparseArrays ~/.julia/juliaup/julia-1.12.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/SparseArrays/src/sparsevector.jl:1275
Possible fix, define
vcat(::AbstractVector{<:Number}, ::ReverseDiff.TrackedReal)
=#The issues caused by the SparseArrays.jl definitions of hcat/vcat are I think well known (JuliaSparse/SparseArrays.jl#431) but what I'm seeing from is that the solution for now is to define the necessary methods in ReverseDiff (?).
I think just adding :(AbstractVector{<:Number}) (and :(AbstractMatrix{<:Number})) to this line should fix it?
ReverseDiff.jl/src/derivatives/arrays.jl
Line 36 in 7cc6588
| for i = 0:2, c = combinations([:AbstractVector, :Vector, :TrackedVector, :AbstractMatrix, :TrackedMatrix, :Number, :TrackedReal], i) |
Metadata
Metadata
Assignees
Labels
No labels