MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / _fetch_H_of_group

Method _fetch_H_of_group

easygraph/classes/base.py:237–264  ·  view source on GitHub ↗

r"""Fetch the H matrix of the specified hyperedge group with ``torch.sparse_coo_tensor`` format. Args: ``direction`` (``str``): The direction of hyperedges can be either ``'v2e'`` or ``'e2v'``. ``group_name`` (``str``): The name of the group.

(self, direction: str, group_name: str)

Source from the content-addressed store, hash-verified

235 return e_list, w_list
236
237 def _fetch_H_of_group(self, direction: str, group_name: str):
238 r"""Fetch the H matrix of the specified hyperedge group with ``torch.sparse_coo_tensor`` format.
239
240 Args:
241 ``direction`` (``str``): The direction of hyperedges can be either ``'v2e'`` or ``'e2v'``.
242 ``group_name`` (``str``): The name of the group.
243 """
244 assert (
245 group_name in self.group_names
246 ), f"The specified {group_name} is not in existing hyperedge groups."
247 assert direction in ["v2e", "e2v"], "direction must be one of ['v2e', 'e2v']"
248 if direction == "v2e":
249 select_idx = 0
250 else:
251 select_idx = 1
252 num_e = len(self._raw_groups[group_name])
253 e_idx, v_idx = [], []
254 for _e_idx, e in enumerate(self._raw_groups[group_name].keys()):
255 sub_e = e[select_idx]
256 v_idx.extend(sub_e)
257 e_idx.extend([_e_idx] * len(sub_e))
258 H = torch.sparse_coo_tensor(
259 torch.tensor([v_idx, e_idx], dtype=torch.long),
260 torch.ones(len(v_idx)),
261 torch.Size([self.num_v, num_e]),
262 device=self.device,
263 ).coalesce()
264 return H
265
266 def _fetch_R_of_group(self, direction: str, group_name: str):
267 r"""Fetch the R matrix of the specified hyperedge group with ``torch.sparse_coo_tensor`` format.

Callers 2

H_v2e_of_groupMethod · 0.95
H_e2v_of_groupMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected