JuliaDiff / JuliaDiff/ReverseDiff.jl

Ambiguity issue with transposed of sparse matrices from SparseArrays.jl

Open
#131 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
393
Forks
60
Avg merge
18h 24m
Merged PRs (30d)
8

Description

Ran into the following issue:

julia> using SparseArrays, ReverseDiff

julia> A
3×1 SparseArrays.SparseMatrixCSC{Bool,Int64} with 1 stored entry:
  [1, 1]  =  1

julia> ReverseDiff.jacobian(x -> A' * x, ones(1))
ERROR: MethodError: *(::LinearAlgebra.Adjoint{Bool,SparseArrays.SparseMatrixCSC{Bool,Int64}}, ::ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}) is ambiguous. Candidates:
  *(adjA::LinearAlgebra.Adjoint{#s662,#s661} where #s661<:AbstractArray{T,2} where #s662, x::AbstractArray{S,1}) where {T, S} in LinearAlgebra at /opt/julia-1.4.0/share/julia/stdlib/v1.4/LinearAlgebra/src/matmul.jl:111
  *(x::LinearAlgebra.Adjoint{#s54,#s53} where #s53<:(AbstractArray{T,2} where T) where #s54, y::ReverseDiff.TrackedArray{V,D,1,VA,DA} where DA where VA) where {V, D} in ReverseDiff at /home/tor/.julia/packages/ReverseDiff/uy0uk/src/derivatives/linalg/arithmetic.jl:222
Possible fix, define
  *(::LinearAlgebra.Adjoint{#s54,#s53} where #s53<:AbstractArray{T,2} where #s54, ::ReverseDiff.TrackedArray{V,D,1,VA,DA}) where {V, D, T, VA, DA}
Stacktrace:
 [1] (::var"#15#16")(::ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}) at ./REPL[33]:1
 [2] ReverseDiff.JacobianTape(::var"#15#16", ::Array{Float64,1}, ::ReverseDiff.JacobianConfig{ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Nothing}) at /home/tor/.julia/packages/ReverseDiff/uy0uk/src/api/tape.jl:229
 [3] jacobian(::Function, ::Array{Float64,1}, ::ReverseDiff.JacobianConfig{ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},Nothing}) at /home/tor/.julia/packages/ReverseDiff/uy0uk/src/api/jacobians.jl:23 (repeats 2 times)
 [4] top-level scope at REPL[33]:1

Ran into similar issues with Tracker.jl a good while back and this PR fixed those issues: https://github.com/FluxML/Tracker.jl/pull/37. Related?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Julia snippet with SparseArrays and ReverseDiff, then inspect ReverseDiff/src/derivatives/linalg/arithmetic.jl around line 222 alongside the LinearAlgebra matmul method reported in the error. The work is done when the transposed sparse matrix multiplication has no ambiguous method and ReverseDiff.jacobian returns successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.