Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphStore: Data, HeteroData respect is_sorted #4922

Merged
merged 7 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `time_attr` argument to `LinkNeighborLoader` ([#4877](https://github.com/pyg-team/pytorch_geometric/pull/4877), [#4908](https://github.com/pyg-team/pytorch_geometric/pull/4908))
- Added a `filter_per_worker` argument to data loaders to allow filtering of data within sub-processes ([#4873](https://github.com/pyg-team/pytorch_geometric/pull/4873))
- Added a `NeighborLoader` benchmark script ([#4815](https://github.com/pyg-team/pytorch_geometric/pull/4815))
- Added support for `FeatureStore` and `GraphStore` in `NeighborLoader` ([#4817](https://github.com/pyg-team/pytorch_geometric/pull/4817), [#4851](https://github.com/pyg-team/pytorch_geometric/pull/4851), [#4854](https://github.com/pyg-team/pytorch_geometric/pull/4854), [#4856](https://github.com/pyg-team/pytorch_geometric/pull/4856), [#4857](https://github.com/pyg-team/pytorch_geometric/pull/4857), [#4882](https://github.com/pyg-team/pytorch_geometric/pull/4882), [#4883](https://github.com/pyg-team/pytorch_geometric/pull/4883))
- Added support for `FeatureStore` and `GraphStore` in `NeighborLoader` ([#4817](https://github.com/pyg-team/pytorch_geometric/pull/4817), [#4851](https://github.com/pyg-team/pytorch_geometric/pull/4851), [#4854](https://github.com/pyg-team/pytorch_geometric/pull/4854), [#4856](https://github.com/pyg-team/pytorch_geometric/pull/4856), [#4857](https://github.com/pyg-team/pytorch_geometric/pull/4857), [#4882](https://github.com/pyg-team/pytorch_geometric/pull/4882), [#4883](https://github.com/pyg-team/pytorch_geometric/pull/4883), [#4992](https://github.com/pyg-team/pytorch_geometric/pull/4922))
- Added a `normalize` parameter to `dense_diff_pool` ([#4847](https://github.com/pyg-team/pytorch_geometric/pull/4847))
- Added `size=None` explanation to jittable `MessagePassing` modules in the documentation ([#4850](https://github.com/pyg-team/pytorch_geometric/pull/4850))
- Added documentation to the `DataLoaderIterator` class ([#4838](https://github.com/pyg-team/pytorch_geometric/pull/4838))
Expand Down
15 changes: 11 additions & 4 deletions torch_geometric/data/graph_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ def get_edge_index(self, *args, **kwargs) -> EdgeTensorType:
# Layout Conversion #######################################################

# TODO support `replace` to replace the existing edge index.
def _to_layout(self, layout: EdgeLayout,
store: bool = False) -> ConversionOutputType:
def _to_layout(
self,
layout: EdgeLayout,
store: bool = False,
is_sorted: bool = False,
) -> ConversionOutputType:
# Obtain all edge attributes, grouped by type:
edge_attrs = self.get_all_edge_attrs()
edge_type_to_attrs: Dict[Any, List[EdgeAttr]] = defaultdict(list)
Expand Down Expand Up @@ -200,6 +204,8 @@ def _to_layout(self, layout: EdgeLayout,
row, col, perm = to_csc(adj, from_attr_copy, device='cpu')

else:
# Respect is_sorted override (sorted by col):
from_attr.is_sorted = from_attr.is_sorted or is_sorted
adj = edge_tensor_type_to_adj_type(from_attr, from_tuple)

# Actually colptr, row, perm
Expand Down Expand Up @@ -242,10 +248,11 @@ def csr(self, store: bool = False) -> ConversionOutputType:
optionally storing the converted edge indices in the graph store."""
return self._to_layout(EdgeLayout.CSR, store)

def csc(self, store: bool = False) -> ConversionOutputType:
def csc(self, store: bool = False,
is_sorted: bool = False) -> ConversionOutputType:
r"""Converts the edge indices in the graph store to CSC format,
optionally storing the converted edge indices in the graph store."""
return self._to_layout(EdgeLayout.CSC, store)
return self._to_layout(EdgeLayout.CSC, store, is_sorted)

# Additional methods ######################################################

Expand Down
3 changes: 2 additions & 1 deletion torch_geometric/loader/neighbor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def __init__(
self.input_type = input_type

# Obtain CSC representations for in-memory sampling:
row_dict, colptr_dict, perm_dict = graph_store.csc()
row_dict, colptr_dict, perm_dict = graph_store.csc(
is_sorted=is_sorted)
self.row_dict = {
edge_type_to_str(k): v
for k, v in row_dict.items()
Expand Down