clamp periodic coordinate to prevent evaluation at rmax.#1101
Closed
Quntized wants to merge 1 commit intoCExA-project:mainfrom
Closed
clamp periodic coordinate to prevent evaluation at rmax.#1101Quntized wants to merge 1 commit intoCExA-project:mainfrom
Quntized wants to merge 1 commit intoCExA-project:mainfrom
Conversation
…wrapping formula in SplineEvaluator::eval() can produce
a coordinate exactly equal to rmax due to floating-point arithmetic.
For periodic splines, rmax is outside the valid evaluation range
[rmin, rmax) because rmax and rmin are the same physical point.
Example: coord = rmin - 1e-16
floor((-1e-16 - 0.0) / length) = -1
coord -= (-1) * length = length - 1e-16 ≈ rmax
At rmax, eval_basis cannot find a valid cell (cells are half-open
intervals [b_i, b_{i+1})), leading to incorrect B-spline evaluation.
Fix: after wrapping, if the result >= rmax, replace with rmin.
This is mathematically equivalent for periodic domains (same point)
but ensures eval_basis finds a valid cell.
Collaborator
|
Isn't t his case already handled by the tolerance in the eval_basis function? Do you have a MRE showing the problem you are fixing? |
Member
|
@Quntized I agree with @EmilyBourne, could you provide a problematic snippet of code that your patch solves ? |
Contributor
Author
|
Thank you both for pointing this out. I checked get_icell_and_offset and find_cell_start — both already handle x >= rmax() by clamping to the last valid cell. I should have checked these functions before opening the PR. Lesson learned — I'll verify the full call chain before proposing fixes in the future. Closing this. |
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.
The periodic wrapping formula in SplineEvaluator::eval() can produce
a coordinate exactly equal to rmax due to floating-point arithmetic. For periodic splines, rmax is outside the valid evaluation range [rmin, rmax) because rmax and rmin are the same physical point. Example: coord = rmin - 1e-16
floor((-1e-16 - 0.0) / length) = -1
coord -= (-1) * length = length - 1e-16 ≈ rmax
At rmax, eval_basis cannot find a valid cell , leading to incorrect B-spline evaluation.
Fix: after wrapping, if the result >= rmax, replace with rmin. This is mathematically equivalent for periodic domains (same point) but ensures eval_basis finds a valid cell.