Fix GPU S2N validation: shape mismatch crash and inverted threshold logic#32
Merged
Conversation
Agent-Logs-Url: https://github.com/OpenPIV/openpiv-python-gpu/sessions/fd3e43b8-3215-44e6-83fc-1b78b7dc77c7 Co-authored-by: alexlib <747110+alexlib@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix GPU S2N validation shape mismatch and logic errors
Fix GPU S2N validation: shape mismatch crash and inverted threshold logic
May 18, 2026
alexlib
approved these changes
May 18, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes GPU signal-to-noise validation by aligning the S2N array shape with velocity fields and correcting the threshold comparison so low-S2N vectors are marked invalid.
Changes:
- Reshapes GPU S2N ratios before validation in the PIV pipeline.
- Reverses S2N validation logic to flag values below the configured threshold.
- Updates the S2N validation unit test expectation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
openpiv/gpu/process.py |
Reshapes flattened correlation S2N output to match velocity field shape before validation. |
openpiv/gpu/validation.py |
Changes S2N validation to invalidate low-S2N vectors instead of high-S2N vectors. |
openpiv/test/gpu/test_validation.py |
Updates the S2N validation test to match the corrected threshold direction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tol = log10(validation.S2N_TOL) | ||
|
|
||
| val_locations = validation._local_validation(s2n_ratio / tol, 1).get() | ||
| val_locations = validation._local_validation(DTYPE_f(tol) - s2n_ratio, 0).get() |
| return u, v, val_locations | ||
| if "s2n" in self.validation_method: | ||
| s2n_ratio = self._corr_gpu.s2n_ratio | ||
| s2n_ratio = self._corr_gpu.s2n_ratio.reshape(u.shape) |
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.
gpu_piv(..., validation_method="s2n")crashes with a PyCUDA shape mismatch, and when it doesn't crash (combined validation), it invalidates the wrong vectors — high-S2N instead of low-S2N.Changes
process.py— reshapes2n_ratiotou.shapebefore passing to validation.self._corr_gpu.s2n_ratiois 1D (flattened); this causedval_locationsto be flat, mismatching the 2D velocity field inreplace_vectors().validation.py— fix inverted threshold in_s2n_validation. The old formulas2n_ratio / s2n_tol > 1flagged high-S2N vectors as invalid. Replaced withs2n_tol - s2n_ratio > 0, which correctly flags vectors wheres2n_ratio < s2n_tol, consistent with the CPU implementation.test_validation.py— updatetest_validation_s2n_validationto assert the corrected logic.