Fix evaluate for a piecewise linear SplineSpace - #689
Merged
Conversation
`evaluate` for a `SplineSpace{1}` referred to an undefined `f` instead of
its arguments, so evaluating such a `Fun` threw an `UndefVarError`. These
arise in practice, as `integrate` of a `Fun` in a `HeavisideSpace` returns
one.
The loop bound is set by the number of coefficients as well now, as a `Fun`
may have fewer coefficients than the dimension of the space, in which case
the interpolation would read past the end of the coefficient vector. This
matches the corresponding method for a `HeavisideSpace`, which evaluates to
zero beyond the coefficients that are available.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Unlike a Fun, the coefficient vector passed to evaluate is not checked against the dimension of the space, so the loops that index p[k+1] may read past the end of the breakpoints. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.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.
evaluatefor aSplineSpace{1}referred to an undefinedfin its bodyinstead of its arguments:
so evaluating such a
Funthrew anUndefVarError. This isn't a dead codepath —
integrateof aFunin aHeavisideSpacereturns aFunin aSplineSpace{1}:The loop bound is now set by the number of coefficients as well. A
Funmayhave fewer coefficients than the dimension of its space, in which case the
interpolation would read past the end of the coefficient vector and throw a
BoundsError. This matches the corresponding method for aHeavisideSpace,which evaluates to zero beyond the coefficients that are available.
The interpolation itself was correct, and is unchanged.
Tests check that the piecewise linear
Funinterpolates its coefficients atthe nodes, that
values(g) == g.(points(g)), that it evaluates to zerooutside the domain, that
differentiateinverts theintegrateabove, andthat a truncated coefficient vector is handled.
Independent of #688.
🤖 Generated with Claude Code