-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved handling of
NumNeighbors
serialization (#6646)
Introduces an `EdgeTypeStr` object that is used for serializing `NumNeighbors` instances.
- Loading branch information
Showing
5 changed files
with
135 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
from torch_geometric.typing import EdgeTypeStr | ||
|
||
|
||
def test_edge_type_str(): | ||
edge_type_str = EdgeTypeStr('a__links__b') | ||
assert isinstance(edge_type_str, str) | ||
assert edge_type_str == 'a__links__b' | ||
assert edge_type_str.to_tuple() == ('a', 'links', 'b') | ||
|
||
edge_type_str = EdgeTypeStr('a', 'b') | ||
assert isinstance(edge_type_str, str) | ||
assert edge_type_str == 'a__to__b' | ||
assert edge_type_str.to_tuple() == ('a', 'to', 'b') | ||
|
||
edge_type_str = EdgeTypeStr(('a', 'b')) | ||
assert isinstance(edge_type_str, str) | ||
assert edge_type_str == 'a__to__b' | ||
assert edge_type_str.to_tuple() == ('a', 'to', 'b') | ||
|
||
edge_type_str = EdgeTypeStr('a', 'links', 'b') | ||
assert isinstance(edge_type_str, str) | ||
assert edge_type_str == 'a__links__b' | ||
assert edge_type_str.to_tuple() == ('a', 'links', 'b') | ||
|
||
edge_type_str = EdgeTypeStr(('a', 'links', 'b')) | ||
assert isinstance(edge_type_str, str) | ||
assert edge_type_str == 'a__links__b' | ||
assert edge_type_str.to_tuple() == ('a', 'links', 'b') | ||
|
||
with pytest.raises(ValueError, match="invalid edge type"): | ||
EdgeTypeStr('a', 'b', 'c', 'd') | ||
|
||
with pytest.raises(ValueError, match="Cannot convert the edge type"): | ||
EdgeTypeStr('a__b__c__d').to_tuple() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters