Skip to content

Fix evaluate for a piecewise linear SplineSpace - #689

Merged
jishnub merged 2 commits into
masterfrom
jishnub/splinespace_evaluate
Aug 24, 2026
Merged

Fix evaluate for a piecewise linear SplineSpace#689
jishnub merged 2 commits into
masterfrom
jishnub/splinespace_evaluate

Conversation

@jishnub

@jishnub jishnub commented Aug 22, 2026

Copy link
Copy Markdown
Member

evaluate for a SplineSpace{1} referred to an undefined f in its body
instead of its arguments:

function evaluate(c::AbstractVector{T}, s::SplineSpace{1,<:Real}, x::Real) where T
    p = domain(f).points
    c = f.coefficients
    ...

so evaluating such a Fun threw an UndefVarError. This isn't a dead code
path — integrate of a Fun in a HeavisideSpace returns a Fun in a
SplineSpace{1}:

julia> g = integrate(Fun(HeavisideSpace([-1.0,0.0,1.0]), [1.0,2.0]));

julia> g(0.5)
ERROR: UndefVarError: `f` not defined in `ApproxFunBase`

The loop bound is now set by the number of coefficients as well. A Fun may
have 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 a HeavisideSpace,
which evaluates to zero beyond the coefficients that are available.

The interpolation itself was correct, and is unchanged.

Tests check that the piecewise linear Fun interpolates its coefficients at
the nodes, that values(g) == g.(points(g)), that it evaluates to zero
outside the domain, that differentiate inverts the integrate above, and
that a truncated coefficient vector is handled.

Independent of #688.

🤖 Generated with Claude Code

`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>
@jishnub
jishnub merged commit d463d76 into master Aug 24, 2026
20 checks passed
@jishnub
jishnub deleted the jishnub/splinespace_evaluate branch August 24, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant