(edge_index: torch.LongTensor, edge_weight: torch.FloatTensor = None,
add_self_loop: bool = True)
| 247 | |
| 248 | |
| 249 | def get_sparse_adj(edge_index: torch.LongTensor, edge_weight: torch.FloatTensor = None, |
| 250 | add_self_loop: bool = True) -> torch.sparse.Tensor: |
| 251 | num_nodes = edge_index.max().item() + 1 |
| 252 | num_edges = edge_index.size(1) |
| 253 | |
| 254 | if edge_weight is None: |
| 255 | edge_weight = torch.ones((num_edges,), dtype=torch.float32, device=edge_index.device) |
| 256 | |
| 257 | if add_self_loop: |
| 258 | edge_index, edge_weight = add_self_loops( |
| 259 | edge_index, edge_weight, fill_value=1, num_nodes=num_nodes) |
| 260 | edge_index, edge_weight = coalesce(edge_index, edge_weight, num_nodes, num_nodes) |
| 261 | |
| 262 | edge_index, edge_weight = GDC().transition_matrix( |
| 263 | edge_index, edge_weight, num_nodes, normalization='sym') |
| 264 | |
| 265 | adj_t = torch.sparse_coo_tensor(edge_index, edge_weight, size=(num_nodes, num_nodes)).coalesce() |
| 266 | |
| 267 | return adj_t.t() |
| 268 | |
| 269 | |
| 270 | def compute_markov_diffusion( |
no outgoing calls
no test coverage detected