Skip to content

Commit 3fa958b

Browse files
authored
Short-circuit coefficient conversion for an empty vector (#90)
* fix conversion for empty coefficients * Add test
1 parent b8f7753 commit 3fa958b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Fun.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ hasnumargs(f::Fun,k) = k == 1 || domaindimension(f) == k # all funs take a sing
4343

4444
function coefficients(f::Fun,msp::Space)
4545
#zero can always be converted
46-
if ncoefficients(f)==1 && f.coefficients[1]==0
46+
if ncoefficients(f) == 0 || (ncoefficients(f) == 1 && f.coefficients[1] == 0)
4747
f.coefficients
4848
else
49-
coefficients(f.coefficients,space(f),msp)
49+
coefficients(f.coefficients, space(f), msp)
5050
end
5151
end
5252
coefficients(f::Fun,::Type{T}) where {T<:Space} = coefficients(f,T(domain(f)))

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ end
7070
@test count(i -> i == 0.1, r)/length(r) 0.3/(3.3) atol=0.01
7171
end
7272

73-
@time include("ETDRK4Test.jl")
73+
@testset "empty coefficients" begin
74+
v = Float64[]
75+
f = Fun(PointSpace(), v)
76+
# empty coefficients should short-circuit
77+
@test ApproxFunBase.coefficients(f) === v
78+
end
79+
80+
@time include("ETDRK4Test.jl")

0 commit comments

Comments
 (0)