Skip to content

MethodError: *(::Diagonal, ::ReverseDiff.TrackedArray) is ambiguous. #223

New issue

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

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

Already on GitHub? # to your account

Open
tmigot opened this issue Mar 23, 2023 · 0 comments · May be fixed by #231
Open

MethodError: *(::Diagonal, ::ReverseDiff.TrackedArray) is ambiguous. #223

tmigot opened this issue Mar 23, 2023 · 0 comments · May be fixed by #231

Comments

@tmigot
Copy link

tmigot commented Mar 23, 2023

I got the following error when using ReverseDiff

using LinearAlgebra, ReverseDiff
n = 30
D = Diagonal([0.1 + 0.9 * (i - 1) / (n - 1) for i = 1:n])
F = x -> sqrt.(D) * (x .- 1)
x = ones(n)
ReverseDiff.gradient(x -> dot(F(x), x), x)

and got the following error

ERROR: MethodError: *(::Diagonal{Float64, Vector{Float64}}, ::ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}) is ambiguous. Candidates:
  *(x::AbstractMatrix, y::ReverseDiff.TrackedArray{V, D, 1}) where {V, D} in ReverseDiff at .julia\packages\ReverseDiff\YkVxM\src\derivatives\linalg\arithmetic.jl:214
  *(x::AbstractArray, y::ReverseDiff.TrackedArray{V, D, 1}) where {V, D} in ReverseDiff at .julia\packages\ReverseDiff\YkVxM\src\derivatives\linalg\arithmetic.jl:214
  *(x::AbstractMatrix, y::ReverseDiff.TrackedArray{V, D}) where {V, D} in ReverseDiff at .julia\packages\ReverseDiff\YkVxM\src\derivatives\linalg\arithmetic.jl:214
  *(x::AbstractArray, y::ReverseDiff.TrackedArray{V, D}) where {V, D} in ReverseDiff at .julia\packages\ReverseDiff\YkVxM\src\derivatives\linalg\arithmetic.jl:214
  *(D::Diagonal, V::AbstractVector) in LinearAlgebra at julia-1.8.0\share\julia\stdlib\v1.8\LinearAlgebra\src\diagonal.jl:242
Possible fix, define
  *(::Diagonal, ::ReverseDiff.TrackedArray{V, D, 1}) where {V, D}
Stacktrace:
 [1] (::var"#3#4")(x::ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}})
   @ Main .\REPL[6]:1
 [2] (::var"#7#8")(x::ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}})
   @ Main .\REPL[9]:1
 [3] ReverseDiff.GradientTape(f::var"#7#8", input::Vector{Float64}, cfg::ReverseDiff.GradientConfig{ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}})
   @ ReverseDiff .julia\packages\ReverseDiff\YkVxM\src\api\tape.jl:199
 [4] gradient(f::Function, input::Vector{Float64}, cfg::ReverseDiff.GradientConfig{ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}}) (repeats 2 times)
   @ ReverseDiff .julia\packages\ReverseDiff\YkVxM\src\api\gradients.jl:22
 [5] top-level scope
   @ REPL[9]:1
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant