Repository: pyg-team/pytorch_geometric
Pull request #9290 (2024-05-04 18:18:07)

Add more `EdgeIndex` tests

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9290?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 87.92%. Comparing base [(`4839cb8`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/4839cb8b8991998f0bd379b6d710ef2cf13852f2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) to head [(`2aaf09d`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9290?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).
> Report is 2 commits behind head on master.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #9290      +/-   ##
==========================================
- Coverage   87.93%   87.92%   -0.02%     
==========================================
  Files         471      471              
  Lines       30537    30620      +83     
==========================================
+ Hits        26854    26922      +68     
- Misses       3683     3698      +15     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9290?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).


Patch:
diff --git a/torch_geometric/edge_index.py b/torch_geometric/edge_index.py
index 8b2363dd1..b849122df 100644
--- a/torch_geometric/edge_index.py
+++ b/torch_geometric/edge_index.py
@@ -1321,6 +1321,11 @@ def _to_copy(
     )
 
 
+@implements(aten.alias.default)
+def _alias(tensor: EdgeIndex) -> EdgeIndex:
+    return tensor._shallow_copy()
+
+
 @implements(aten.cat.default)
 def _cat(
     tensors: List[Union[EdgeIndex, Tensor]],


Test patch:
diff --git a/test/test_edge_index.py b/test/test_edge_index.py
index 82433750d..9b6358508 100644
--- a/test/test_edge_index.py
+++ b/test/test_edge_index.py
@@ -137,6 +137,8 @@ def test_set_tuple_item():
 
 
 def test_validate():
+    with pytest.raises(TypeError, match="tensors of a single element"):
+        EdgeIndex([torch.tensor([0, 1]), torch.tensor([1, 0])])
     with pytest.raises(ValueError, match="unsupported data type"):
         EdgeIndex([[0.0, 1.0], [1.0, 0.0]])
     with pytest.raises(ValueError, match="needs to be two-dimensional"):
@@ -527,6 +529,20 @@ def test_getitem(dtype, device, is_undirected):
     assert out.is_sorted_by_row
     assert not out.is_undirected
 
+    out = adj[...]
+    assert isinstance(out, EdgeIndex)
+    assert out.equal(tensor([[0, 1, 1, 2], [1, 0, 2, 1]], device=device))
+    assert out.is_sorted_by_row
+    assert out.is_undirected == is_undirected
+
+    out = adj[None]
+    assert not isinstance(out, EdgeIndex)
+    assert out.equal(tensor([[[0, 1, 1, 2], [1, 0, 2, 1]]], device=device))
+
+    out = adj[0, 0]
+    assert not isinstance(out, EdgeIndex)
+    assert out.equal(tensor(0, device=device))
+
     out = adj[:, 0]
     assert not isinstance(out, EdgeIndex)