ChainRules.jl icon indicating copy to clipboard operation
ChainRules.jl copied to clipboard

Rule for `foldl` fails on empty tuple

Open mcabbott opened this issue 3 years ago • 0 comments

Found here: https://github.com/FluxML/Zygote.jl/issues/1297

julia> using ChainRules, ChainRulesCore, ChainRulesTestUtils

julia> const CFG = ChainRulesTestUtils.TestConfig();

julia> foldl(/, (), init=0)
0

julia> rrule(CFG, foldl, /, (), init=0)
ERROR: BoundsError: attempt to access Tuple{} at index [0]
Stacktrace:
 [1] getindex(t::Tuple, i::Int64)
   @ Base ./tuple.jl:29
 [2] last(a::Tuple{})
   @ Base ./abstractarray.jl:500
 [3] rrule(config::ChainRulesTestUtils.TestConfig, ::typeof(foldl), op::typeof(/), x::Tuple{}; init::Int64)
   @ ChainRules ~/.julia/packages/ChainRules/fgVxV/src/rulesets/Base/mapreduce.jl:448

mcabbott avatar Aug 29 '22 18:08 mcabbott