Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/Spaces/HeavisideSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ spacescompatible(a::SplineSpace{λ},b::SplineSpace{λ}) where {λ} = domainscomp


function evaluate(c::AbstractVector{T}, s::HeavisideSpace{<:Real}, x::Real) where T
# the loop below indexes p[k+1] for k up to length(c)
@assert length(c) ≤ dimension(s)
p = domain(s).points
for k=1:length(c)
if p[k] ≤ x ≤ p[k+1]
Expand All @@ -34,9 +36,10 @@ end


function evaluate(c::AbstractVector{T}, s::SplineSpace{1,<:Real}, x::Real) where T
p = domain(f).points
c = f.coefficients
for k=1:length(p)-1
# the loop below indexes p[k+1] for k up to length(c)-1
@assert length(c) ≤ dimension(s)
p = domain(s).points
for k=1:length(c)-1
if p[k] ≤ x ≤ p[k+1]
return (x-p[k])*c[k+1]/(p[k+1]-p[k]) + (p[k+1]-x)*c[k]/(p[k+1]-p[k])
end
Expand Down
24 changes: 24 additions & 0 deletions test/SpacesTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,30 @@ using Test
@test @inferred(points(a)) == 0.125:0.25:0.875
end

@testset "piecewise linear SplineSpace" begin
f = Fun(HeavisideSpace([-1.0, 0.0, 1.0]), [1.0, 2.0])
g = integrate(f)
@test space(g) isa ApproxFunBase.SplineSpace{1}
# g is piecewise linear, and interpolates the coefficients at the nodes
@test values(g) == coefficients(g)
@test g.(points(g)) == values(g)
@test g(-0.5) == 0.5
@test g(0.5) == 2.0
@test g(1.0) == sum(f)
# outside the domain
@test g(2.0) == 0
@test coefficients(differentiate(g)) == coefficients(f)

# fewer coefficients than the dimension of the space
h = Fun(space(g), [0.0, 1.0])
@test h(-0.5) == 0.5
@test h(0.5) == 0

# evaluate is not restricted to coefficients that come from a Fun
@test_throws AssertionError ApproxFunBase.evaluate(zeros(4), space(g), 0.0)
@test_throws AssertionError ApproxFunBase.evaluate(zeros(3), space(f), 0.0)
end

@testset "DiracDelta integration and differentiation" begin
δ = DiracDelta()
h = integrate(δ)
Expand Down
Loading