|
1 | 1 | """ |
2 | | - bypass_graph(nf_func, ef_func, gf_func) |
3 | | -
|
4 | | -Bypassing graph in FeaturedGraph and let other layer process (node, edge and global)features only. |
| 2 | +Bypassing graph in FeaturedGraph and let other layer process (node, edge and global) features only. |
5 | 3 | """ |
6 | | -function bypass_graph(nf_func=identity, ef_func=identity, gf_func=identity) |
7 | | - return function (fg::FeaturedGraph) |
8 | | - FeaturedGraph(fg, |
9 | | - nf=nf_func(node_feature(fg)), |
10 | | - ef=ef_func(edge_feature(fg)), |
11 | | - gf=gf_func(global_feature(fg))) |
12 | | - end |
| 4 | +struct Bypass{N,E,G} |
| 5 | + node_layer::N |
| 6 | + edge_layer::E |
| 7 | + global_layer::G |
| 8 | +end |
| 9 | + |
| 10 | +@functor Bypass |
| 11 | + |
| 12 | +Bypass(; node_layer=identity, edge_layer=identity, global_layer=identity) = |
| 13 | + Bypass(node_layer, edge_layer, global_layer) |
| 14 | + |
| 15 | +function (l::Bypass)(fg::FeaturedGraph) |
| 16 | + nf = l.node_layer(node_feature(fg)) |
| 17 | + ef = l.edge_layer(edge_feature(fg)) |
| 18 | + gf = l.global_layer(global_feature(fg)) |
| 19 | + return FeaturedGraph(fg, nf=nf, ef=ef, gf=gf) |
| 20 | +end |
| 21 | + |
| 22 | +function (l::Bypass)(fsg::FeaturedSubgraph) |
| 23 | + nf = l.node_layer(node_feature(fsg)) |
| 24 | + ef = l.edge_layer(edge_feature(fsg)) |
| 25 | + gf = l.global_layer(global_feature(fsg)) |
| 26 | + fg = parent(fsg) |
| 27 | + vidx = fsg.nodes |
| 28 | + nf = NNlib.scatter(+, nf, vidx; init=0, dstsize=(size(nf,1), nv(fg))) |
| 29 | + ef = NNlib.scatter(+, ef, edges(fsg); init=0, dstsize=(size(ef,1), ne(fg))) |
| 30 | + fg = FeaturedGraph(fg, nf=nf, ef=ef, gf=gf) |
| 31 | + return subgraph(fg, vidx) |
13 | 32 | end |
0 commit comments