Skip to content

Chain forgets names under fmap #1857

@mcabbott

Description

@mcabbott

From FluxML/Optimisers.jl#49 (comment), this isn't great:

julia> fmap(identity, Chain(x=sin, y=cos))
Chain(sin, cos)

The culprit is this functor method, which could be extended to deal with this.

functor(::Type{<:Chain}, c) = c.layers, ls -> Chain(ls...)

Or we could delete it, and let Chain be more like Parallel:

julia> Flux.functor(Chain(x=sin, y=cos))
((x = sin, y = cos), Flux.var"#154#155"())

julia> Flux.functor(Parallel(vcat, (x=sin, y=cos)))
((connection = vcat, layers = (x = sin, y = cos)), Flux.var"#178#179"())

Then we would want delete the inner constructor for Chain, so that it accepts a tuple, Chain((sin, cos)) == Chain(sin, cos). That would line up with #1809 allowing Chain([sin, cos]) as a type-unstable variant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions