JuliaDiff / JuliaDiff/ChainRules.jl

Rule for `foldl` fails on empty tuple

Open
#672 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
475
Forks
98
PR merge metrics
No merged PRs in 30d

Description

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

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

The failing entry point is the foldl rrule in src/rulesets/Base/mapreduce.jl around line 448. Reproduce the reported rrule(CFG, foldl, /, (), init=0) call first; done means the empty-tuple case no longer raises BoundsError and preserves foldl's result.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.