Repository: pyg-team/pytorch_geometric
Pull request #8993 (2024-02-29 12:47:41)

Fix `EdgeIndex.resize_` linting issues

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8993?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 89.27%. Comparing base [(`a8671b1`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/a8671b1266f2a58ea39cfadd353612fc0aba0c74?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) to head [(`0676e5c`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8993?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).
> Report is 1 commits behind head on master.


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


```diff
@@            Coverage Diff             @@
##           master    #8993      +/-   ##
==========================================
- Coverage   89.89%   89.27%   -0.62%     
==========================================
  Files         468      468              
  Lines       30025    30020       -5     
==========================================
- Hits        26990    26800     -190     
- Misses       3035     3220     +185     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8993?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/CHANGELOG.md b/CHANGELOG.md
index 5ca936641..f5ca82c25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Added
 
-- Added `EdgeIndex.resize_` functionality ([#8983](https://github.com/pyg-team/pytorch_geometric/pull/8983))
+- Added `EdgeIndex.sparse_resize_` functionality ([#8983](https://github.com/pyg-team/pytorch_geometric/pull/8983))
 - Added approximate `faiss`-based KNN-search ([#8952](https://github.com/pyg-team/pytorch_geometric/pull/8952))
 
 ### Changed
diff --git a/torch_geometric/edge_index.py b/torch_geometric/edge_index.py
index 7a39708a6..5b71e207f 100644
--- a/torch_geometric/edge_index.py
+++ b/torch_geometric/edge_index.py
@@ -516,7 +516,10 @@ class EdgeIndex(Tensor):
 
         return torch.Size((self.get_sparse_size(0), self.get_sparse_size(1)))
 
-    def resize_(self, sparse_size: Tuple[int, int]) -> 'EdgeIndex':
+    def sparse_resize_(  # type: ignore
+            self,
+            sparse_size: Tuple[int, int],
+    ) -> 'EdgeIndex':
         r"""Assigns or re-assigns the size of the underlying sparse matrix.
 
         Args:
@@ -538,8 +541,11 @@ class EdgeIndex(Tensor):
             if ptr.numel() - 1 > size:
                 return None
 
-            val = ptr.new_full((size - ptr.numel() + 1, ), fill_value=ptr[-1])
-            return torch.cat([ptr, val], dim=0)
+            fill_value = ptr.new_full(
+                (size - ptr.numel() + 1, ),
+                fill_value=ptr[-1],  # type: ignore
+            )
+            return torch.cat([ptr, fill_value], dim=0)
 
         if self.is_sorted_by_row:
             self._indptr = _modify_ptr(self._indptr, num_rows)


Test patch:
diff --git a/test/test_edge_index.py b/test/test_edge_index.py
index a70d1ab43..1023474a0 100644
--- a/test/test_edge_index.py
+++ b/test/test_edge_index.py
@@ -1024,18 +1024,18 @@ def test_sparse_narrow(device):
 
 
 @withCUDA
-def test_resize(device):
+def test_sparse_resize(device):
     adj = EdgeIndex([[0, 1, 1, 2], [1, 0, 2, 1]], device=device)
 
     out = adj.sort_by('row')[0].fill_cache_()
     assert out.sparse_size() == (3, 3)
     assert out._indptr.equal(tensor([0, 1, 3, 4], device=device))
     assert out._T_indptr.equal(tensor([0, 1, 3, 4], device=device))
-    out = out.resize_((4, 5))
+    out = out.sparse_resize_((4, 5))
     assert out.sparse_size() == (4, 5)
     assert out._indptr.equal(tensor([0, 1, 3, 4, 4], device=device))
     assert out._T_indptr.equal(tensor([0, 1, 3, 4, 4, 4], device=device))
-    out = out.resize_((3, 3))
+    out = out.sparse_resize_((3, 3))
     assert out.sparse_size() == (3, 3)
     assert out._indptr is None
     assert out._T_indptr is None
@@ -1044,11 +1044,11 @@ def test_resize(device):
     assert out.sparse_size() == (3, 3)
     assert out._indptr.equal(tensor([0, 1, 3, 4], device=device))
     assert out._T_indptr.equal(tensor([0, 1, 3, 4], device=device))
-    out = out.resize_((4, 5))
+    out = out.sparse_resize_((4, 5))
     assert out.sparse_size() == (4, 5)
     assert out._indptr.equal(tensor([0, 1, 3, 4, 4, 4], device=device))
     assert out._T_indptr.equal(tensor([0, 1, 3, 4, 4], device=device))
-    out = out.resize_((3, 3))
+    out = out.sparse_resize_((3, 3))
     assert out.sparse_size() == (3, 3)
     assert out._indptr is None
     assert out._T_indptr is None