-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BoundsError when solving ODE wirh TaylorMethod #104
Comments
Thanks for reporting! There are two issues here: The error, which is due to this line (and maybe others). This is solved by #105. The second one, which is the one you are able to solve and in fact triggers the former error, is related to the declaration of |
The first issue is solved by #105; I'm tagging a new version. The other one needs a bit more time... |
TL;DR: Not using the macro still throws an error. I am reluctant to make the macro work in the case the original function does not work directly (which is equivalent to use the option First, let me explain the (second) problem. I begin stating that If you do that, you get the following error: julia> sol = solve(prob, TaylorMethod(10), abstol=1e-20, parse_eqs=false);
ERROR: BoundsError: attempt to access 1-element Array{Float64,1} at index [2]
Stacktrace:
[1] getindex at ./array.jl:788 [inlined]
[2] getindex at /Users/benet/.julia/packages/TaylorSeries/qn7NV/src/auxiliary.jl:80 [inlined]
[3] jetcoeffs!(::typeof(benchmark7!), ::Taylor1{Float64}, ::Array{Taylor1{Float64},1}, ::Array{Taylor1{Float64},1}, ::Array{Taylor1{Float64},1}, ::DiffEqBase.NullParameters) at /Users/benet/.julia/dev/TaylorIntegration/src/explicitode.jl:82
... That error is related to your actual function Your solution It is possible to make that the macro |
Thanks for the write-up! Even for |
In simpler terms, my mental model is (let alone changing Float -> Taylor1{T})): julia> x = [1.0, 2.0, 3.0]
julia> x[1] = 10 # implicit promotion
julia> x
3-element Array{Float64,1}:
10.0
2.0
3.0 |
I reopened the issue until thins is fully clarified I agree with your mental view @mforets , and to some extend, that actually happens. Internally (assume julia> t = Taylor1(5) # 5th order for illustration
1.0 t + 𝒪(t⁶)
julia> u = q0 .+ zero(t)
4-element Array{Taylor1{Float64},1}:
0.4 + 𝒪(t⁶)
0.5 + 𝒪(t⁶)
0.3 + 𝒪(t⁶)
0.0 + 𝒪(t⁶)
julia> du = similar(u);
julia> benchmark7!(du, u, nothing, t) # returns `nothing` but updates `du`.
julia> du
4-element Array{Taylor1{Float64},1}:
- 0.473 + 𝒪(t⁶)
0.3 + 𝒪(t⁶)
2.0 + 𝒪(t¹)
0.0 + 𝒪(t⁶) Note that julia> du[3][1]
ERROR: BoundsError: attempt to access 1-element Array{Float64,1} at index [2]
Stacktrace:
[1] getindex at ./array.jl:788 [inlined]
[2] getindex(::Taylor1{Float64}, ::Int64) at /Users/benet/.julia/packages/TaylorSeries/qn7NV/src/auxiliary.jl:80
[3] top-level scope at REPL[20]:1 While the conversion works ( |
Ok, it makes sense, thanks for the explanation.
True; i see that taylor series order is not known at compile time. Adding the order as a type parameter is possible, though perhaps not very convenient because you have to recompile a new type for each operations that produces a taylor series of different order. Otoh, one way out could be to define a new julia> t = Taylor1(5) # 5th order for illustration
1.0 t + 𝒪(t⁶)
julia> u = q0 .+ zero(t) |> Taylor1Vector
4-element Taylor1Vector{Taylor1{Float64}, Array{Taylor1{Float64},1}:
0.4 + 𝒪(t⁶)
0.5 + 𝒪(t⁶)
0.3 + 𝒪(t⁶)
0.0 + 𝒪(t⁶)
# the order of u is 5
julia> du = similar(u);
julia> benchmark7!(du, u, nothing, t) # returns `nothing` but updates `du`.
julia> du # if you update du[i] it will promote to the order of the Taylor1Vector
4-element Array{Taylor1{Float64},1}:
- 0.473 + 𝒪(t⁶)
0.3 + 𝒪(t⁶)
2.0 + 𝒪(t⁶)
0.0 + 𝒪(t⁶) |
i mean writing |
Looks like a slick solution! It'd be nice to try it! Should that be implemented here, or rather in TaylorSeries.jl? |
Maybe TaylorSeries is a better place... |
There is a workaround using
2.0+zero(u[1])
instead of only2
fordu[3]
The text was updated successfully, but these errors were encountered: