FIX: Correct axis parameters and remove duplicate coefficient scaling…#150
Merged
rcjackson merged 1 commit intoopenradar:mainfrom Feb 24, 2026
Merged
Conversation
… in smoothness functions
This commit fixes two critical issues in the smoothness cost and gradient functions:
1. **Fixed incorrect axis parameters in second derivative calculations**:
- In both JAX and NumPy implementations, the axis parameter was incorrectly
specified when computing second derivatives
- For x-direction terms (Cx), all second derivatives should use axis=2
- For y-direction terms (Cy), all second derivatives should use axis=1
- For z-direction terms (Cz), all second derivatives should use axis=0
- This ensures that second derivatives are taken in the correct spatial direction
2. **Removed duplicate Cx, Cy, Cz scaling in gradient functions**:
- Both JAX and NumPy gradient functions were incorrectly multiplying by
Cx, Cy, Cz coefficients twice
- The cost function already includes these coefficients, and the gradient
(via chain rule or autodiff) inherently includes them
- Removed the extra `* Cx * 2`, `* Cy * 2`, `* Cz * 2` scaling at the end
- Also removed the `/dx`, `/dy`, `/dz` operations that were incorrect in JAX
3. **Simplified JAX gradient function**:
- Removed manual gradient calculation code that duplicated the cost function logic
- Now relies entirely on JAX's automatic differentiation (vjp) which is more
accurate and maintainable
- Fixed the vjp call to pass Cx, Cy, Cz as positional arguments (not keyword args)
These fixes ensure that the JAX and NumPy/SciPy engines produce consistent results
when using smoothness constraints with non-zero Cx, Cy, Cz parameters.
Fixes: https://openradar.discourse.group/t/smoothness-costs-in-different-engines/666
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #150 +/- ##
==========================================
- Coverage 69.02% 68.85% -0.17%
==========================================
Files 32 32
Lines 5169 5141 -28
==========================================
- Hits 3568 3540 -28
Misses 1601 1601
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This commit fixes two critical issues in the smoothness cost and gradient functions:
Fixed incorrect axis parameters in second derivative calculations:
Removed duplicate Cx, Cy, Cz scaling in gradient functions:
* Cx * 2,* Cy * 2,* Cz * 2scaling at the end/dx,/dy,/dzoperations that were incorrect in JAXSimplified JAX gradient function:
These fixes ensure that the JAX and NumPy/SciPy engines produce consistent results when using smoothness constraints with non-zero Cx, Cy, Cz parameters.
Fixes: https://openradar.discourse.group/t/smoothness-costs-in-different-engines/666