ApproxFun.jl
ApproxFun.jl copied to clipboard
`append!` broken for Funs
I'm trying to construct an array of Funs, via eg:
f = Fun(x->x^2)
fs = []
append!(fs,f)
but I get an exception in append!
with the following stacktrace:
ERROR: MethodError: no method matching length(::Chebyshev{ChebyshevInterval{Float64},Float64})
Closest candidates are:
length(::Core.SimpleVector) at essentials.jl:561
length(::Base.MethodList) at reflection.jl:801
length(::Core.MethodTable) at reflection.jl:875
...
Stacktrace:
[1] length(::Fun{Chebyshev{ChebyshevInterval{Float64},Float64},Float64,Array{Float64,1}}) at ~/.julia/packages/ApproxFun/UU55f/src/Fun/Fun.jl:148
[2] _append!(::Array{Any,1}, ::Base.HasLength, ::Function) at ./array.jl:906
[3] append!(::Array{Any,1}, ::Function) at ./array.jl:900
[4] top-level scope at none:0
A work around is to wrap the Fun in an array, ie:
f = Fun(x->x^2)
fs = []
append!(fs,[f])
It seems the length
function for Funs is unused, so perhaps a simple fix is to remove it altogether.
Cheers.
To me it looks like the length function for a Fun is not defined and it needs to be to append a single element:
julia (v1.2)> using ApproxFun
julia (v1.2)> f = Fun(x -> x^2)
Fun(Chebyshev(),[0.5, 0.0, 0.5])
julia (v1.2)> Base.length(f::Fun) = 1
julia (v1.2)> fs = []
0-element Array{Any,1}
julia (v1.2)> append!(fs, f)
1-element Array{Any,1}:
Fun(Chebyshev(),[0.5, 0.0, 0.5])
'''
But I don't know if anything else would break if this function is defined. Also note that you can wrap the f in a Ref, ie Ref(f) as well as [f]
I realised I should actually be using push!
in this case, so the fault is partly mine.
There is still a bug is that length(f::Fun) = length(space(f))
but length(space(f))
is undefined.
Fun
s should behave like numbers or vectors depending on the space. So we need to add something like
length(::Space{<:Any,<:Number}) = 1