Add nodes with features

Hi all,

I have a graph g and in this graph, I have node features. I want to add nodes to this graph and add the features of the nodes at the same time. I am trying to use :
g.add_nodes(1, {‘features’: torch.tensor([i for i in range(21)], dtype = torch.float64)})
But it does not work, i have the following issue :
DGLError: Cannot update column of scheme Scheme(shape=(), dtype=torch.float32) using feature of scheme Scheme(shape=(21,), dtype=torch.float32).

I want to point out that my features tensor of the initial graph has 21 columns.

Have you an idea of how to add node to an existing graph and modifying the g.ndata[‘features’] with the features of the new nodes?

Thank you all !

It’s probably easier to do something as follows:

feat = g.ndata.pop('feat')
g.add_nodes(num_new_nodes)
feat = torch.cat([feat, new_feat], dim=0)
g.ndata['feat'] = feat
1 Like

yes it is bassicaly what I’ve done.

Thanks

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