Relabeling nodes

I am looking for an efficient way to relabel the node IDs of a DGLGraph based on a dictionary where the keys represent the old node IDs and the values are the new node IDs. In NetworkX, a similar task can be accomplished using the relabel_nodes(G, mapping, copy=True) function. However, I specifically need a solution tailored for DGLGraph, and I want to avoid using any NetworkX functions.

Although I have implemented a node relabeling (IDs) function by looping through all the nodes, this method is currently too slow for my requirements. I am seeking a faster alternative to relabel DGLGraph nodes based on the provided dictionary. Your assistance in providing an optimized solution is greatly appreciated. Thank you.

Hello, although I may not be very familiar with the DGL API, I believe that if you can convert a dictionary into a tensor mapping (assuming your IDs are numeric), and then obtain the mapped results for all edges in your graph using new_edge = map[edge] , you can reconstruct a new DGLGraph. I think this should give you the desired result (of course, you may need to adjust the mapping for other attributes of the graph). By leveraging the parallelism of tensors, I believe there should be good efficiency assurance. If there are already implemented APIs for this in DGL, I will also learn about them later.

1 Like

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