JuliaArrays / BlockDiagonals.jl

Functionality for working efficiently with block diagonal matrices.
MIT License
49 stars 11 forks source link

Projecting a `ZeroTangent` onto a `BlockDiagonal` is Method-Ambiguous #84

Closed SBuercklin closed 2 years ago

SBuercklin commented 2 years ago

Attempting to ProjectTo a ZeroTangent from ChainRulesCore.jl onto a BlockDiagonal gives a method error, complaining that the operation is ambiguous:

using ChainRulesCore, BlockDiagonals

a = randn(2,2)
bd = BlockDiagonal([a,a])

julia> ProjectTo(bd)(ChainRulesCore.ZeroTangent())
# ERROR: MethodError: (::ProjectTo{BlockDiagonal, NamedTuple{(:blocks, :blocksizes), Tuple{Vector{ProjectTo{AbstractArray, NamedTuple{(:element, :axes), Tuple{ProjectTo{Float64, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}}}, Vector{Tuple{Int64, Int64}}}}})(::ZeroTangent) is ambiguous. Candidates:
#   (project::ProjectTo{BlockDiagonal})(dx) in BlockDiagonals at /home/sam/.julia/packages/BlockDiagonals/rUwoj/src/chainrules.jl:87
#   (::ProjectTo{T})(dx::AbstractZero) where T in ChainRulesCore at /home/sam/.julia/packages/ChainRulesCore/sHMAp/src/projection.jl:120
# Possible fix, define
#   (::ProjectTo{BlockDiagonal})(::AbstractZero)
# Stacktrace:
#  [1] top-level scope
#    @ REPL[6]:1

This was on 1.7.0 with the following environment:

(jl_vzzVL5) pkg> st                                                                                           
      Status `/tmp/jl_vzzVL5/Project.toml`
  [0a1fb500] BlockDiagonals v0.1.24
  [d360d2e6] ChainRulesCore v1.11.2