Add to_batch_edge_index
utility function
#10485
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Implements
to_batch_edge_index
as the inverse operation ofunbatch_edge_index
. This function merges a list ofedge_index
tensors into a single batchededge_index
tensor and returns the corresponding batch vector.Closes #6099
Motivation
Currently, PyG provides
unbatch_edge_index
to split a batched edge_index into individual graphs, but lacks the inverse operation to merge multiple edge_index tensors into a batch. This function completes the API by providing the batching counterpart, enabling users to:Changes
Core Implementation
to_batch_edge_index()
function intorch_geometric/utils/_unbatch.py
API Updates
to_batch_edge_index
intorch_geometric/utils/__init__.py
Testing
test/utils/test_unbatch.py
:unbatch_edge_index
)Usage Example
Testing
All tests pass:
pytest test/utils/test_unbatch.py -v # 8 passed in 0.04s
Pre-commit hooks pass:
pre-commit run --all-files # All checks passed
Checklist
Related Issues
Closes #6099