Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: reducing over empty collection #87

Merged
merged 1 commit into from
Jul 31, 2024
Merged

Conversation

avik-pal
Copy link
Member

Before the patch

julia> Functors.fleaves((; a = (;), b=[1, 2]))
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
       internal @ Base, Unknown
  [9] reduce(op::Function, itr::@NamedTuple{}; kw::@Kwargs{})
    @ Base ./reduce.jl:487
 [10] (::Functors.FlattenWalk)(::Function, ::@NamedTuple{})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:318
 [11] (::Functors.ExcludeWalk{Functors.FlattenWalk, Functors.var"#52#53", typeof(Functors.isleaf)})(::Function, ::@NamedTuple{})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:144
 [12] (::Functors.var"#recurse#26"{Functors.ExcludeWalk{Functors.FlattenWalk, Functors.var"#52#53", typeof(Functors.isleaf)}})(xs::@NamedTuple{})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:52
       internal @ Unknown
 [14] map(::Function, ::@NamedTuple{a::@NamedTuple{}, b::Vector{Int64}})
    @ Base ./namedtuple.jl:266
 [15] _map
    @ /mnt/research/lux/Functors.jl/src/walks.jl:3 [inlined]
 [16] (::Functors.FlattenWalk)(::Function, ::@NamedTuple{a::@NamedTuple{}, b::Vector{Int64}})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:317
 [17] (::Functors.ExcludeWalk{Functors.FlattenWalk, Functors.var"#52#53", typeof(Functors.isleaf)})(::Function, ::@NamedTuple{a::@NamedTuple{}, b::Vector{Int64}})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:144
 [18] execute(::Functors.ExcludeWalk{Functors.FlattenWalk, Functors.var"#52#53", typeof(Functors.isleaf)}, ::@NamedTuple{a::@NamedTuple{}, b::Vector{Int64}})
    @ Functors /mnt/research/lux/Functors.jl/src/walks.jl:53
 [19] fleaves(x::@NamedTuple{a::@NamedTuple{}, b::Vector{Int64}}; exclude::Function)
    @ Functors /mnt/research/lux/Functors.jl/src/maps.jl:33
 [20] top-level scope
    @ REPL[4]:1
 [21] top-level scope
    @ none:1
Use `err` to retrieve the full stack trace.

PR Checklist

  • Tests are added
  • Documentation, if applicable

@darsnack darsnack merged commit b597d47 into FluxML:master Jul 31, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants