MCPcopy Index your code
hub / github.com/dmlc/dgl / HeteroEdgeDataView

Class HeteroEdgeDataView

python/dgl/view.py:182–267  ·  view source on GitHub ↗

The data view class when G.edata[etype] is called.

Source from the content-addressed store, hash-verified

180
181
182class HeteroEdgeDataView(MutableMapping):
183 """The data view class when G.edata[etype] is called."""
184
185 __slots__ = ["_graph", "_etype", "_etid", "_edges"]
186
187 def __init__(self, graph, etype, edges):
188 self._graph = graph
189 self._etype = etype
190 self._etid = (
191 [self._graph.get_etype_id(t) for t in etype]
192 if isinstance(etype, list)
193 else self._graph.get_etype_id(etype)
194 )
195 self._edges = edges
196
197 def __getitem__(self, key):
198 if isinstance(self._etype, list):
199 ret = {}
200 for (i, etype) in enumerate(self._etype):
201 value = self._graph._get_e_repr(self._etid[i], self._edges).get(
202 key, None
203 )
204 if value is not None:
205 ret[etype] = value
206 return ret
207 else:
208 return self._graph._get_e_repr(self._etid, self._edges)[key]
209
210 def __setitem__(self, key, val):
211 if isinstance(val, LazyFeature):
212 self._graph._edge_frames[self._etid][key] = val
213 elif isinstance(self._etype, list):
214 assert isinstance(val, dict), (
215 "Current HeteroEdgeDataView has multiple edge types, "
216 "please pass the edge type and the corresponding data through a dict."
217 )
218
219 for (etype, data) in val.items():
220 etid = self._graph.get_etype_id(etype)
221 self._graph._set_e_repr(etid, self._edges, {key: data})
222 else:
223 assert isinstance(val, dict) is False, (
224 "The HeteroEdgeDataView has only one edge type. "
225 "please pass a tensor directly"
226 )
227 self._graph._set_e_repr(self._etid, self._edges, {key: val})
228
229 def __delitem__(self, key):
230 if isinstance(self._etype, list):
231 for etid in self._etid:
232 if self._graph._get_e_repr(etid, ALL).get(key, None) is None:
233 continue
234 self._graph._pop_e_repr(etid, key)
235 else:
236 self._graph._pop_e_repr(self._etid, key)
237
238 def _transpose(self, as_dict=False):
239 if isinstance(self._etype, list):

Callers 2

__getitem__Method · 0.85
edataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected