Fix empty collection checks in interpolation methods. Realy an edge c… - #323
Open
novitk wants to merge 4 commits into
Open
Fix empty collection checks in interpolation methods. Realy an edge c…#323novitk wants to merge 4 commits into
novitk wants to merge 4 commits into
Conversation
…ondition, but allows the MixedInterp to work with just left interpolator.
There was a problem hiding this comment.
Pull request overview
This PR updates MixedInterpolationImpl to safely handle the edge case where the second interpolation range (xBegin2_) is empty, preventing InvalidOperationException from calling .First() on an empty list during interpolation queries.
Changes:
- Guard
value,primitive,derivative, andsecondDerivativeagainstxBegin2_being empty by checkingxBegin2_.Count == 0before callingxBegin2_.First(). - Minor condition formatting adjustments (one remaining spacing inconsistency noted in review).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
84
to
89
| public override double value(double x) | ||
| { | ||
| if (x<(xBegin2_.First())) | ||
| if (xBegin2_.Count == 0 || x < (xBegin2_.First())) | ||
| return interpolation1_.value(x, true); | ||
| return interpolation2_.value(x, true); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
84
to
88
| public override double value(double x) | ||
| { | ||
| if (x<(xBegin2_.First())) | ||
| if (xBegin2_.Count == 0 || x < (xBegin2_.First())) | ||
| return interpolation1_.value(x, true); | ||
| return interpolation2_.value(x, true); |
added 2 commits
July 9, 2026 13:48
Updated `QL_REQUIRE` to validate against `xBegin.Count` instead of `size_`. Added handling for cases where `size_ <= n_` in `SplitRanges` behavior, ensuring both interpolations use the full range when necessary. Retained original logic for cases where `size_ > n_`.
Comment on lines
56
to
60
| xBegin2_ = xBegin.GetRange(n_, xBegin.Count - n_); | ||
| yBegin2_ = yBegin.GetRange(n_, yBegin.Count - n_); | ||
|
|
||
| Utils.QL_REQUIRE(xBegin2_.Count < size_, () => "too large n (" + n + ") for " + size_ + "-element x sequence"); | ||
| Utils.QL_REQUIRE(xBegin2_.Count < xBegin.Count, () => "too large n (" + n + ") for " + size_ + "-element x sequence"); | ||
|
|
Comment on lines
+68
to
+72
| if (size_ <= n_) | ||
| { | ||
| interpolation1_ = factory1.interpolate(xBegin_, size_, yBegin_); | ||
| interpolation2_ = interpolation1_; | ||
| } |
Comment on lines
+68
to
+72
| if (size_ <= n_) | ||
| { | ||
| interpolation1_ = factory1.interpolate(xBegin_, size_, yBegin_); | ||
| interpolation2_ = interpolation1_; | ||
| } |
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.
…ondition, but allows the MixedInterp to work with just left interpolator.
QLNet
Thank you for contributing! Take a moment to review our contributing guidelines
to make the process easy and effective for everyone involved.
You must open an issue before embarking on any significant pull request, especially those that
add a new code or change existing tests, otherwise you risk spending a lot of time working
on something that might not end up being merged into the project.
IMPORTANT: By submitting a patch via a Pull Request, you agree to allow the project
owners to license your work under the terms of the BSD3 License.
PR Type
What kind of change does this PR introduce?
Description