Multiple built-in functions in message

Hi!
Suppose, I have these UDF:

def message_func(edges: dgl.EdgeBatch) -> Dict:
    return {
        'a': edges.src['a'],
        'b': edges.src['b'],
    }

def reduce_func(nodes: dgl.NodeBatch) -> Dict:
    a_sum = torch.sum(nodes.mailbox['a'], 1)
    b_sum = torch.sum(nodes.mailbox['b'], 1)
    return {'a_sum': a_sum, 'b_sum': b_sum}

I know, that for one feature, I can use built-in functions: copy_u and sum, but can I do something similar for features or more? What if message or reducing functions different?

Hi,
You can do g.update_all([fn.copy_u('a', 'a'), fn.copy_u('b','b')], [fn.sum('a', 'a_sum'), fn.sum('b', 'b_sum')])

2 Likes

Could you please give an example for G.multi_update_all using an heterogeneous graph? I get the error: TypeError: 'list' object is not callable. Thank you!!

G.multi_update_all({etype : ([fn.copy_u('v', 'm'), fn.copy_u('node_att', 'node_att_src')], [fn.sum('m', 't'), fn.sum('node_att_src', 'att')]) \
                                for etype in G.canonical_etypes}, cross_reducer = 'mean')

Same happens if I create a subgraph and use subgraph.update_all

subgraph = G[etype]
subgraph.update_all([fn.copy_u('v', 'a'), fn.copy_u('node_att','b')], [fn.sum('a', 'a_sum'), fn.sum('b', 'b_sum')])
>>TypeError: 'list' object is not callable

We no longer support this feature in dgl 0.7. Move discussion to https://github.com/dmlc/dgl/issues/3319. If you still have similar questions, please start a new post. Thanks