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

Function extract_edge_subframes

python/dgl/utils/internal.py:920–958  ·  view source on GitHub ↗

Extract edge features of the given edges from :attr:`graph` and return them in frames. Note that this function does not perform actual tensor memory copy but using `Frame.subframe` to get the features. If :attr:`edges` is None, it performs a shallow copy of the original edge frames

(graph, edges_or_device, store_ids=True)

Source from the content-addressed store, hash-verified

918
919
920def extract_edge_subframes(graph, edges_or_device, store_ids=True):
921 """Extract edge features of the given edges from :attr:`graph`
922 and return them in frames.
923
924 Note that this function does not perform actual tensor memory copy but using `Frame.subframe`
925 to get the features. If :attr:`edges` is None, it performs a shallow copy of the
926 original edge frames that only copies the dictionary structure but not the tensor
927 contents.
928
929 Parameters
930 ----------
931 graph : DGLGraph
932 The graph to extract features from.
933 edges_or_device : list[Tensor] or device or None
934 Edge IDs.
935 If a list, the list length must be equal to the number of edge types
936 in the graph.
937 If None, the whole frame is shallow-copied.
938 store_ids : bool
939 If True, the returned frames will store :attr:`edges` in the ``dgl.EID`` field
940 unless it is None.
941
942 Returns
943 -------
944 list[Frame]
945 Extracted edge frames.
946 """
947 if edges_or_device is None:
948 edge_frames = [nf.clone() for nf in graph._edge_frames]
949 elif is_listlike(edges_or_device):
950 edge_frames = []
951 for i, ind_edges in enumerate(edges_or_device):
952 subf = graph._edge_frames[i].subframe(ind_edges)
953 if store_ids:
954 subf[EID] = ind_edges
955 edge_frames.append(subf)
956 else: # device object
957 edge_frames = [nf.to(edges_or_device) for nf in graph._edge_frames]
958 return edge_frames
959
960
961def set_new_frames(graph, *, node_frames=None, edge_frames=None):

Callers

nothing calls this directly

Calls 5

subframeMethod · 0.80
appendMethod · 0.80
is_listlikeFunction · 0.70
cloneMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected