Repository: pyg-team/pytorch_geometric
Pull request #8026 (2023-09-13 19:29:47)

Changed `view` to `reshape` in `LCMAggregation`
`view` resulted in an error in some cases, so I changed it to `reshape`. I also modified the tests to reflect such a scenario.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8026?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#8026](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8026?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (6626335) into [master](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/3e6902237612150ed65db6bd60db2ac5c313b41e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (3e69022) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##           master    #8026   +/-   ##
=======================================
  Coverage   88.58%   88.58%           
=======================================
  Files         464      464           
  Lines       27453    27453           
=======================================
  Hits        24319    24319           
  Misses       3134     3134           
```


| [Files Changed](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8026?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/nn/aggr/lcm.py](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/8026?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL25uL2FnZ3IvbGNtLnB5) | `94.00% <100.00%> (ø)` | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?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 2821e10f4..feaa17524 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added `IBMBNodeLoader` and `IBMBBatchLoader` data loaders ([#6230](https://github.com/pyg-team/pytorch_geometric/pull/6230))
 - Added the `NeuralFingerprint` model for learning fingerprints of molecules ([#7919](https://github.com/pyg-team/pytorch_geometric/pull/7919))
 - Added `SparseTensor` support to `WLConvContinuous`, `GeneralConv`, `PDNConv` and `ARMAConv` ([#8013](https://github.com/pyg-team/pytorch_geometric/pull/8013))
-- Added `LCMAggregation`, an implementation of Learnable Communitive Monoids ([#7976](https://github.com/pyg-team/pytorch_geometric/pull/7976), [#8023](https://github.com/pyg-team/pytorch_geometric/pull/8023))
+- Added `LCMAggregation`, an implementation of Learnable Communitive Monoids ([#7976](https://github.com/pyg-team/pytorch_geometric/pull/7976), [#8023](https://github.com/pyg-team/pytorch_geometric/pull/8023), [#8026](https://github.com/pyg-team/pytorch_geometric/pull/8026))
 - Added a warning for isolated/non-existing node types in `HeteroData.validate()` ([#7995](https://github.com/pyg-team/pytorch_geometric/pull/7995))
 - Added `utils.cumsum` implementation ([#7994](https://github.com/pyg-team/pytorch_geometric/pull/7994))
 - Added the `BrcaTcga` dataset ([#7905](https://github.com/pyg-team/pytorch_geometric/pull/7905))
diff --git a/torch_geometric/nn/aggr/lcm.py b/torch_geometric/nn/aggr/lcm.py
index 741efe2a3..a237b8630 100644
--- a/torch_geometric/nn/aggr/lcm.py
+++ b/torch_geometric/nn/aggr/lcm.py
@@ -91,15 +91,15 @@ class LCMAggregation(Aggregation):
             if x.size(0) % 2 == 1:
                 # This level of the tree has an odd number of nodes, so the
                 # remaining unmatched node gets moved to the next level.
-                x, remainder = x[:-1].contiguous(), x[-1:]
+                x, remainder = x[:-1], x[-1:]
             else:
                 remainder = None
 
             left_right = x.view(-1, 2, num_nodes, num_features)
             right_left = left_right.flip(dims=[1])
 
-            left_right = left_right.view(-1, num_features)
-            right_left = right_left.view(-1, num_features)
+            left_right = left_right.reshape(-1, num_features)
+            right_left = right_left.reshape(-1, num_features)
 
             # Execute the GRUCell for all (left, right) pairs in the current
             # level of the tree in parallel:


Test patch:
diff --git a/test/nn/aggr/test_lcm.py b/test/nn/aggr/test_lcm.py
index 46db4c717..9664e2be8 100644
--- a/test/nn/aggr/test_lcm.py
+++ b/test/nn/aggr/test_lcm.py
@@ -19,8 +19,8 @@ def test_lcm_aggregation_with_project():
 
 
 def test_lcm_aggregation_without_project():
-    x = torch.randn(6, 16)
-    index = torch.tensor([0, 0, 1, 1, 1, 2])
+    x = torch.randn(5, 16)
+    index = torch.tensor([0, 1, 1, 2, 2])
 
     aggr = LCMAggregation(16, 16, project=False)
     assert str(aggr) == 'LCMAggregation(16, 16, project=False)'