Skip to content

Commit c13c00f

Browse files
authored
Add doc-string to EdgeIndex (pyg-team#8469)
1 parent db55d62 commit c13c00f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

torch_geometric/data/edge_index.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ def assert_two_dimensional(tensor: Tensor):
5050

5151

5252
class EdgeIndex(Tensor):
53+
r"""An advanced :obj:`edge_index` representation with additional (meta)data
54+
attached.
55+
56+
:class:`EdgeIndex` is a :pytorch:`PyTorch` tensor, that holds an
57+
:obj:`edge_index` representation of shape :obj:`[2, num_edges]`.
58+
Edges are given as pairwise source and destination node indices in sparse
59+
COO format.
60+
61+
While :class:`EdgeIndex` sub-classes a general :pytorch:`PyTorch` tensor,
62+
it can hold additional (meta)data, *i.e.*:
63+
64+
* :obj:`sparse_size`: The underlying sparse matrix size
65+
* :obj:`sort_order`: The sort order (if present), either by row or column.
66+
67+
Additionally, :class:`EdgeIndex` caches data for fast CSR or CSC conversion
68+
in case its representation is sorted, such as its :obj:`rowptr` or
69+
:obj:`colptr`, or the permutation vectors for fast conversion from CSR to
70+
CSC and vice versa.
71+
Caches are filled based on demand (*e.g.*, when calling
72+
:meth:`EdgeIndex.sort_by`), or when explicitly requested via
73+
:meth:`EdgeIndex.fill_cache`, and are maintained and adjusted over its
74+
lifespan (*e.g.*, when calling :meth:`EdgeIndex.flip`).
75+
76+
This representation ensures for optimal computation in GNN message passing
77+
schemes, while preserving the ease-of-use of regular COO-based :pyg:`PyG`
78+
workflows.
79+
"""
5380
# See "https://pytorch.org/docs/stable/notes/extending.html"
5481
# for a basic tutorial on how to subclass `torch.Tensor`.
5582

@@ -133,6 +160,9 @@ def validate(self) -> 'EdgeIndex':
133160
return self
134161

135162
def fill_cache(self) -> 'EdgeIndex':
163+
r"""Fills the cache with (meta)data information.
164+
No-op in case :class:`EdgeIndex` is not sorted.
165+
"""
136166
if self._sort_order == SortOrder.ROW and self._rowptr is None:
137167
if self.num_rows is None:
138168
self._sparse_size = (

0 commit comments

Comments
 (0)