| 45 | # The following code snippet shows how to do global pooling to sum over features of nodes in each graph: |
| 46 | # -------------------------------------------------------------------------------------------------------- |
| 47 | def batch_sum_pooling(x, batch): |
| 48 | batch_size = int(torch.max(batch.cpu())) + 1 |
| 49 | res = torch.zeros(batch_size, x.size(1)).to(x.device) |
| 50 | out = res.scatter_add_( |
| 51 | dim=0, |
| 52 | index=batch.unsqueeze(-1).expand_as(x), |
| 53 | src=x |
| 54 | ) |
| 55 | return out |
| 56 | |
| 57 | return out |
| 58 | |
| 59 | # %% |
| 60 | # How to edit the graph? |