MCPcopy Create free account
hub / github.com/PyGCL/PyGCL / get_sparse_adj

Function get_sparse_adj

GCL/augmentors/functional.py:249–267  ·  view source on GitHub ↗
(edge_index: torch.LongTensor, edge_weight: torch.FloatTensor = None,
                   add_self_loop: bool = True)

Source from the content-addressed store, hash-verified

247
248
249def 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
270def compute_markov_diffusion(

Callers 1

compute_markov_diffusionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected