| 313 | |
| 314 | @property |
| 315 | def D_v(self): |
| 316 | import torch |
| 317 | |
| 318 | r"""Return the diagnal matrix of vertex degree :math:`\mathbf{D}_v` with ``torch.sparse_coo_tensor`` format. Size :math:`(|\mathcal{V}|, |\mathcal{V}|)`. |
| 319 | """ |
| 320 | if self.cache.get("D_v") is None: |
| 321 | _tmp = torch.sparse.sum(self.A, dim=1).to_dense().clone().view(-1) |
| 322 | self.cache["D_v"] = torch.sparse_coo_tensor( |
| 323 | torch.arange(0, len(self.nodes)).view(1, -1).repeat(2, 1), |
| 324 | _tmp, |
| 325 | torch.Size([len(self.nodes), len(self.nodes)]), |
| 326 | device=self.device, |
| 327 | ).coalesce() |
| 328 | return self.cache["D_v"] |
| 329 | |
| 330 | def add_extra_selfloop(self): |
| 331 | r"""Add extra selfloops to the graph.""" |