CarloLucibello / GraphNeuralNetworks.jl

Graph Neural Networks in Julia
https://carlolucibello.github.io/GraphNeuralNetworks.jl/dev/
MIT License
214 stars 47 forks source link

`@functor` default for `GNNLayer`s #288

Closed CarloLucibello closed 2 weeks ago

CarloLucibello commented 1 year ago

Consider adding the definitions

function Functors.functor(::Type{<:GNNLayer}, m::T) where T
    childr = (; (f => getfield(m, f) for f in fieldnames(T))...)
    Tstripped = Base.typename(T).wrapper # remove all parameters. From https://discourse.julialang.org/t/stripping-parameter-from-parametric-types/8293/16
    re = x -> Tstripped(x...)
    return childr, re
end

so that we don't need to add @functor to types inheriting from GNNLayer.

I'm not sure if this change should be considered breaking.

CarloLucibello commented 2 weeks ago

Now that we use Flux.@layer instead (#452) marking every subtype of GNNLayer a @layer by default would be more complicated. We would also lose the customization opportunities (e.g. for show) given by the @layer macro. Since the gain would be very little I think we shouldn't do this.