Closed
Description
solve
with nested form of a static LabelledArray yields the StackOverflowError
.
Here is the example:
- code
using Aerobatics
using OrdinaryDiffEq
using Plots
using LabelledArrays
function report()
x0 = SLVector(x1=2, x2=3)
∫r0 = 0.0
X0 = SLVector(x=x0, ∫r=∫r0)
tspan = (0.0, 1.0)
f = function (X, p, t)
x, ∫r = X.x, X.∫r
x1, x2 = x.x1, x.x2
u = -x2
dx1 = -(1/2)*x1^3 - x1 - 2*x2
dx2 = (1/8)*x2^3 - x2 + (1/2)*u^3
dx = SLVector(x1=dx1, x2=dx2)
r = x1^4 + 2*(x1+x2)^2 + (3/4)*u^4
SLVector(x=dx, ∫r=r)
end
prob = ODEProblem(f, X0, tspan)
sol = solve(prob, Tsit5())
end
function test()
report()
end
Run by test()
.
- Result
ERROR: StackOverflowError:
Stacktrace:
[1] recursive_unitless_bottom_eltype(a::Type{Any}) (repeats 79984 times)
@ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/K3lTR/src/utils.jl:86
However, another similar example seems work as follows:
- code
function test2()
_myvec = @SLVector (:a, :b)
myvec = @SLVector (:x, :y)
dynamics = function (X, p, t)
dx = -X.x
dy = -X.y
myvec(dx, dy)
end
tspan = (0.0, 1.0)
x = _myvec(1.0, 2.0)
y = _myvec(1.0, 2.0)
X = myvec(x, y)
prob = ODEProblem(dynamics, X, tspan)
sol = @time solve(prob, Tsit5())
end
- result
5.121596 seconds (14.80 M allocations: 978.407 MiB, 3.39% gc time)
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 5-element Vector{Float64}:
0.0
0.10001264591185442
0.34206322751658697
0.655359775820945
1.0
u: 5-element Vector{SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)}}:
2-element SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)} with indices SOneTo(2):
:x => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 1.0
:b => 2.0
:y => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 1.0
:b => 2.0
2-element SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)} with indices SOneTo(2):
:x => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.9048259756770471
:b => 1.8096519513540943
:y => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.9048259756770471
:b => 1.8096519513540943
2-element SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)} with indices SOneTo(2):
:x => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.7103033089908293
:b => 1.4206066179816585
:y => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.7103033089908293
:b => 1.4206066179816585
2-element SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)} with indices SOneTo(2):
:x => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.5192552947803908
:b => 1.0385105895607816
:y => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.5192552947803908
:b => 1.0385105895607816
2-element SLArray{Tuple{2}, SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)}, 1, 2, (:x, :y)} with indices SOneTo(2):
:x => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.3678795934784995
:b => 0.735759186956999
:y => 2-element SLArray{Tuple{2}, Float64, 1, 2, (:a, :b)} with indices SOneTo(2):
:a => 0.3678795934784995
:b => 0.735759186956999
Metadata
Metadata
Assignees
Labels
No labels