Skip to content

Fix Mesh.face_to_vertex_overlay for single-frame overlays - #89

Merged
jnolan14 merged 1 commit into
freesurfer:masterfrom
inhuszar:fix/face-to-vertex-single-frame
Nov 12, 2026
Merged

jnolan14 merged 1 commit into
freesurfer:masterfrom
inhuszar:fix/face-to-vertex-single-frame

Conversation

@inhuszar

Copy link
Copy Markdown
Contributor

Scalar overlays are stored with shape (nfaces,), while the accumulation buffer has an explicit frame axis, (nvertices, nframes). With a single-frame overlay the indexed reductions (np.add.at, np.maximum.at, np.minimum.at) cannot broadcast (nfaces,) values onto the (nfaces, 1) selection and raise "array is not broadcastable to correct shape", so face_to_vertex_overlay() failed for every method on 1-D overlays.

Reshape the overlay values to (nfaces, nframes) before the reductions. Multi-frame behaviour is unchanged.

Adds test/test_mesh_overlay.py, which compares all four reduction methods against a loop-based reference for 1- and 2-frame overlays.

Scalar overlays are stored with shape (nfaces,), while the accumulation
buffer has an explicit frame axis, (nvertices, nframes). With a
single-frame overlay the indexed reductions (np.add.at, np.maximum.at,
np.minimum.at) cannot broadcast (nfaces,) values onto the (nfaces, 1)
selection and raise "array is not broadcastable to correct shape", so
face_to_vertex_overlay() failed for every method on 1-D overlays.

Reshape the overlay values to (nfaces, nframes) before the reductions.
Multi-frame behaviour is unchanged.

Adds test/test_mesh_overlay.py, which compares all four reduction
methods against a loop-based reference for 1- and 2-frame overlays.

Originally committed in the inhuszar/surfa fork as part of 8ef40a9
("Bugfix: thread limit, overlay accumulation"); supersedes the earlier
local workaround 0ba0004 ("NumPy 2.0 bugfix").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e0951dc)
@jnolan14
jnolan14 merged commit a81bb43 into freesurfer:master Nov 12, 2026
12 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants