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

Method clone

python/dgl/heterograph.py:5899–5941  ·  view source on GitHub ↗

Return a heterograph object that is a clone of current graph. Returns ------- DGLGraph The graph object that is a clone of current graph.

(self)

Source from the content-addressed store, hash-verified

5897 return self
5898
5899 def clone(self):
5900 """Return a heterograph object that is a clone of current graph.
5901
5902 Returns
5903 -------
5904 DGLGraph
5905 The graph object that is a clone of current graph.
5906 """
5907 # XXX(minjie): Do a shallow copy first to clone some internal metagraph information.
5908 # Not a beautiful solution though.
5909 ret = copy.copy(self)
5910
5911 # Clone the graph structure
5912 meta_edges = []
5913 for s_ntype, _, d_ntype in self.canonical_etypes:
5914 meta_edges.append(
5915 (self.get_ntype_id(s_ntype), self.get_ntype_id(d_ntype))
5916 )
5917
5918 metagraph = graph_index.from_edge_list(meta_edges, True)
5919 # rebuild graph idx
5920 num_nodes_per_type = [
5921 self.num_nodes(c_ntype) for c_ntype in self.ntypes
5922 ]
5923 relation_graphs = [
5924 self._graph.get_relation_graph(self.get_etype_id(c_etype))
5925 for c_etype in self.canonical_etypes
5926 ]
5927 ret._graph = heterograph_index.create_heterograph_from_relations(
5928 metagraph,
5929 relation_graphs,
5930 utils.toindex(num_nodes_per_type, "int64"),
5931 )
5932
5933 # Clone the frames
5934 ret._node_frames = [fr.clone() for fr in self._node_frames]
5935 ret._edge_frames = [fr.clone() for fr in self._edge_frames]
5936
5937 # Copy the batch information
5938 ret._batch_num_nodes = copy.copy(self._batch_num_nodes)
5939 ret._batch_num_edges = copy.copy(self._batch_num_edges)
5940
5941 return ret
5942
5943 def local_var(self):
5944 """Return a graph object for usage in a local function scope.

Callers 2

local_varMethod · 0.45
local_scopeMethod · 0.45

Calls 5

get_ntype_idMethod · 0.95
num_nodesMethod · 0.95
get_etype_idMethod · 0.95
appendMethod · 0.80
get_relation_graphMethod · 0.80

Tested by

no test coverage detected