MCPcopy
hub / github.com/dmlc/dgl / _build_neg_graph

Method _build_neg_graph

python/dgl/dataloading/base.py:420–444  ·  view source on GitHub ↗
(self, g, seed_edges)

Source from the content-addressed store, hash-verified

418 self.output_device = sampler.output_device
419
420 def _build_neg_graph(self, g, seed_edges):
421 neg_srcdst = self.negative_sampler(g, seed_edges)
422 if not isinstance(neg_srcdst, Mapping):
423 assert len(g.canonical_etypes) == 1, (
424 "graph has multiple or no edge types; "
425 "please return a dict in negative sampler."
426 )
427 neg_srcdst = {g.canonical_etypes[0]: neg_srcdst}
428
429 dtype = F.dtype(list(neg_srcdst.values())[0][0])
430 ctx = context_of(seed_edges) if seed_edges is not None else g.device
431 neg_edges = {
432 etype: neg_srcdst.get(
433 etype,
434 (
435 F.copy_to(F.tensor([], dtype), ctx=ctx),
436 F.copy_to(F.tensor([], dtype), ctx=ctx),
437 ),
438 )
439 for etype in g.canonical_etypes
440 }
441 neg_pair_graph = heterograph(
442 neg_edges, {ntype: g.num_nodes(ntype) for ntype in g.ntypes}
443 )
444 return neg_pair_graph
445
446 def assign_lazy_features(self, result):
447 """Assign lazy features for prefetching."""

Callers 1

sampleMethod · 0.95

Calls 7

context_ofFunction · 0.85
heterographFunction · 0.85
dtypeMethod · 0.45
valuesMethod · 0.45
getMethod · 0.45
copy_toMethod · 0.45
num_nodesMethod · 0.45

Tested by

no test coverage detected