generated from njzjz/python-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple frame for edge_index OP (#26)
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
- Loading branch information
Showing
2 changed files
with
151 additions
and
34 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,93 @@ | ||
"""Test custom operations.""" | ||
|
||
import torch | ||
|
||
import deepmd_gnn.op # noqa: F401 | ||
|
||
|
||
def test_one_frame() -> None: | ||
"""Test one frame.""" | ||
nlist_ff = torch.tensor( | ||
[ | ||
[1, 2, -1, -1], | ||
[2, 0, -1, -1], | ||
[0, 1, -1, -1], | ||
], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
extended_atype_ff = torch.tensor( | ||
[0, 1, 2], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
mm_types = [1, 2] | ||
expected_edge_index = torch.tensor( | ||
[ | ||
[1, 0], | ||
[2, 0], | ||
[0, 1], | ||
[0, 2], | ||
], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
|
||
edge_index = torch.ops.deepmd_gnn.edge_index( | ||
nlist_ff, | ||
extended_atype_ff, | ||
torch.tensor(mm_types, dtype=torch.int64, device="cpu"), | ||
) | ||
|
||
assert torch.equal(edge_index, expected_edge_index) | ||
|
||
|
||
def test_two_frame() -> None: | ||
"""Test one frame.""" | ||
nlist = torch.tensor( | ||
[ | ||
[ | ||
[1, 2, -1, -1], | ||
[2, 0, -1, -1], | ||
[0, 1, -1, -1], | ||
], | ||
[ | ||
[1, 2, -1, -1], | ||
[2, 0, -1, -1], | ||
[0, 1, -1, -1], | ||
], | ||
], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
extended_atype = torch.tensor( | ||
[ | ||
[0, 1, 2], | ||
[0, 1, 2], | ||
], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
mm_types = [1, 2] | ||
expected_edge_index = torch.tensor( | ||
[ | ||
[1, 0], | ||
[2, 0], | ||
[0, 1], | ||
[0, 2], | ||
[4, 3], | ||
[5, 3], | ||
[3, 4], | ||
[3, 5], | ||
], | ||
dtype=torch.int64, | ||
device="cpu", | ||
) | ||
|
||
edge_index = torch.ops.deepmd_gnn.edge_index( | ||
nlist, | ||
extended_atype, | ||
torch.tensor(mm_types, dtype=torch.int64, device="cpu"), | ||
) | ||
|
||
assert torch.equal(edge_index, expected_edge_index) |