How to get message

In the dgl library, the function fn.u_mul_e('ft', 'a', 'm') is used, but I cannot see the contents of ‘m’. How can I see the contents of ‘m’?

Hello, this code might be helpful for you:

import dgl
import torch
import dgl.function as fn

# Define a graph
g = dgl.graph(([0, 1, 2, 0], [1, 2, 3, 2]))
g.ndata['ft'] = torch.tensor([[2, 6, 7], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=torch.float32)
g.edata['a'] = torch.tensor([[12, 16, 17], [14, 15, 16], [17, 18, 19], [110, 111, 112]], dtype=torch.float32)

# Print node and edge data
print("g.nodes()= ", g.nodes())
print("g.ndata['ft']= ", g.ndata["ft"])
print("g.edata['a']= ", g.edata["a"])

# Define a message function
message_func = fn.u_mul_e('ft', 'a', 'm')

# Define a function to show the messages during message passing
def show_m(nodes):
    print("nodes={}, @@ nodes.mailbox={}, @@ nodes.mailbox.shape={}".
          format(nodes.nodes(), nodes.mailbox['m'], nodes.mailbox['m'].shape))
    return {'m': torch.max(nodes.mailbox["m"], 1)[0]}

# Apply message passing and show the result
g.update_all(message_func, show_m)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.