Repository navigation
Mesh.with_cells: keep effective measures of cells whose vertices are only reordered - #2266
Merged
peterdsharpe merged 4 commits intoNov 13, 2026
Merged
Conversation
A row that only reorders its own vertices, such as a winding flip, is the same simplex: it now keeps its effective measure, cached area, and cached centroid bitwise, instead of being rescaled by float32 roundoff in the area ratio or raising on a zero-area cell with a nonzero measure. Rows whose vertex set changes keep the area-ratio transfer. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com>
Contributor
CODEOWNERS review mapCurrent for commit ⏳ @peterdsharpe — 5 file(s)
No CODEOWNER
Comment |
peterdsharpe
marked this pull request as ready for review
November 13, 2026 17:14
Contributor
|
[Medium impact] The change affects mesh connectivity replacement and orientation repair. Fix the unsigned-index comparison before merging. Findings
SummaryThis PR preserves effective measures when a cell’s vertices are reordered, including zero-area cells.
Reviews (1) · Last reviewed commit: "Keep measures of reordered cells in Mesh..." · Reviewed by Greptile |
The reordered-row check compared the raw replacement with the mesh's int64 cells, and PyTorch cannot promote uint16, uint32 or uint64 with int64. Compare result.cells, which the constructor has normalized. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com>
Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com>
mnabian
approved these changes
Nov 13, 2026
mnabian
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Left a few minor comments.
Returns and Notes now say which caches the result holds without keep,
and that they are computed eagerly for all cells. _transfer_cell_measures
documents how unchanged indexes rows when parents is given, and says why
it caches the old area bits. New tests cover a compiled flip, an empty
mesh, keep=("cell", "areas"), and CUDA for the measure tests; the
centroid tests use a sentinel and the sliver test checks the cached area,
so each fails if its value is recomputed.
Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com>
Collaborator
Author
|
/ok to test 2f72cd5 |
peterdsharpe
enabled auto-merge
November 13, 2026 18:15
4 of 6 tasks
peterdsharpe
added a commit
that referenced
this pull request
Nov 13, 2026
) * Mesh.with_cells: keep effective measures of cells whose vertices are only reordered (#2266) * Keep measures of reordered cells in Mesh.with_cells A row that only reorders its own vertices, such as a winding flip, is the same simplex: it now keeps its effective measure, cached area, and cached centroid bitwise, instead of being rescaled by float32 roundoff in the area ratio or raising on a zero-area cell with a nonzero measure. Rows whose vertex set changes keep the area-ratio transfer. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> * Accept unsigned replacement cells in Mesh.with_cells The reordered-row check compared the raw replacement with the mesh's int64 cells, and PyTorch cannot promote uint16, uint32 or uint64 with int64. Compare result.cells, which the constructor has normalized. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> * Make the dtype comment in Mesh.with_cells exact Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> * Document the caches Mesh.with_cells keeps, and widen its tests Returns and Notes now say which caches the result holds without keep, and that they are computed eagerly for all cells. _transfer_cell_measures documents how unchanged indexes rows when parents is given, and says why it caches the old area bits. New tests cover a compiled flip, an empty mesh, keep=("cell", "areas"), and CUDA for the measure tests; the centroid tests use a sentinel and the sliver test checks the cached area, so each fails if its value is recomputed. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> --------- Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> * FlipBoundaryOrientation: reverse the winding with Mesh.with_cells Since #2266, Mesh.with_cells keeps the effective measure of each cell whose vertices are only reordered, with the area it came from, so the transform uses it instead of building a new Mesh. A flipped mesh with effective measures now also keeps each cell's cached area bit for bit, where recomputed float32 areas differ between the two vertex orders. Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com> --------- Signed-off-by: Peter Sharpe <peterdsharpe@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mesh.with_cellsrescales each effective measure by the new cell area over the old one. When a row only reorders its own vertices, as in a winding flip, the cell is the same simplex. Its measure should not change, but float32 areas differ between vertex orders.A winding flip, with each measure set to twice its cell's area (1.5 for the zero-area cell):
mainValueErrorfix_orientationflips cells throughwith_cells, so it raised on such a cell too.with_cellsnow marks each row whose sorted vertex indices equal the old row's. Those rows keep their effective measure and cached cell area bitwise, so a later transform's area ratio starts from the same pair. They also keep a cached centroid. Rows whose vertices change keep the area-ratio transfer and its error. The selection usestorch.where, adds no host sync, and writes no cache while tracing or when points require gradients.New tests cover flips of subsampled meshes and slivers, flips and cyclic shifts of a zero-area cell, changed rows, cached centroids, unsigned and empty replacements,
keep, gradients,torch.compileandfix_orientation.Checklist
Dependencies
None.
Review Process
All PRs are reviewed by the PhysicsNeMo team before merging.
Depending on which files are changed, GitHub may automatically assign a maintainer for review.
We are also testing AI-based code review tools (e.g., Greptile), which may add automated comments with a confidence score.
This score reflects the AI’s assessment of merge readiness and is not a qualitative judgment of your work, nor is
it an indication that the PR will be accepted / rejected.
AI-generated feedback should be reviewed critically for usefulness.
You are not required to respond to every AI comment, but they are intended to help both authors and reviewers.
Please react to Greptile comments with 👍 or 👎 to provide feedback on their accuracy.