Skip to content

Fix MessagePassing output shape for isolated target cells - #375

Merged
ffl096 merged 1 commit into
mainfrom
frantzen/fix-message-passing-output-shape
Aug 24, 2026
Merged

Fix MessagePassing output shape for isolated target cells#375
ffl096 merged 1 commit into
mainfrom
frantzen/fix-message-passing-output-shape

Conversation

@ffl096

@ffl096 ffl096 commented Aug 24, 2026

Copy link
Copy Markdown
Member

The scatter aggregation inferred the output size from the largest message index, silently dropping target cells without incoming messages and contradicting the documented output shape.

Pass the number of target cells from the neighborhood matrix as dim_size so that every target cell receives an output row, zero-filled when its neighborhood is empty.

Fixes #136

Also resolves the reported Conv scenario of #228, where an isolated last cell previously led to a wrong output shape.

The scatter aggregation inferred the output size from the largest
message index, silently dropping target cells without incoming
messages and contradicting the documented output shape.

Pass the number of target cells from the neighborhood matrix as
dim_size so that every target cell receives an output row, zero-filled
when its neighborhood is empty.

Fixes #136

Also resolves the reported Conv scenario of #228, where an isolated
last cell previously led to a wrong output shape.
@ffl096 ffl096 added this to the 0.1.0 milestone Aug 24, 2026
@ffl096
ffl096 requested a lite review from Copilot August 24, 2026 11:59
@ffl096 ffl096 self-assigned this Aug 24, 2026
@ffl096 ffl096 added the bug Something isn't working label Aug 24, 2026
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.44%. Comparing base (aed06d6) to head (fd3a832).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #375   +/-   ##
=======================================
  Coverage   96.43%   96.44%           
=======================================
  Files          58       58           
  Lines        2078     2079    +1     
=======================================
+ Hits         2004     2005    +1     
  Misses         74       74           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates MessagePassing aggregation to preserve the documented output shape (..., n_target_cells, out_channels) by ensuring scatter aggregation uses the neighborhood matrix’s target dimension as dim_size, so isolated target cells still produce an output row (zero-filled).

Changes:

  • Pass dim_size into the scatter aggregation so output includes all target cells, including those with empty neighborhoods.
  • Record n_target_cells from neighborhood.shape[0] during forward() for use during aggregation.
  • Add a regression test covering an isolated target cell output shape.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
topomodelx/base/message_passing.py Forces scatter output to include all target cells by supplying dim_size based on neighborhood shape.
test/base/test_message_passing.py Adds a regression test for correct output shape when a target cell is isolated.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 191 to +197
aggr = scatter(self.aggr_func)
return aggr(x_message, self.target_index_i, 0)
return aggr(
x_message,
self.target_index_i,
0,
dim_size=getattr(self, "n_target_cells", None),
)
Comment on lines +125 to +126
result = self.mp.forward(x_source, neighborhood)
assert result.shape == (2, 10)
@ffl096
ffl096 merged commit 40b74f9 into main Aug 24, 2026
39 checks passed
@ffl096
ffl096 deleted the frantzen/fix-message-passing-output-shape branch August 24, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A small discrepancy between MessagePassing::forward return value and its docstring

2 participants