@@ -44,7 +44,7 @@ Each operation builds an `Operation` type, and thus `eqs` is an array of
4444analyzed by other programs. We can turn this into a ` ODESystem ` via:
4545
4646``` julia
47- de = ODESystem (eqs)
47+ de = ODESystem (eqs, t, [x,y,z], [σ,ρ,β] )
4848```
4949
5050where we tell it the variable types and ordering in the first version, or let it
@@ -54,49 +54,53 @@ generated code via:
5454
5555``` julia
5656using MacroTools
57- myode_oop = generate_function (de, [x,y,z], [σ,ρ,β] )[1 ] # first one is the out-of-place function
57+ myode_oop = generate_function (de)[1 ] # first one is the out-of-place function
5858MacroTools. striplines (myode_oop) # print without line numbers
5959
6060#=
6161:((u, p, t)->begin
62- @inbounds begin
63- X = @inbounds(begin
64- let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
65- (σ * (y - x), x * (ρ - z) - y, x * y - β * z)
66- end
67- end)
68- end
62+ if u isa Array
63+ return @inbounds(begin
64+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
65+ [σ * (y - x), x * (ρ - z) - y, x * y - β * z]
66+ end
67+ end)
68+ else
69+ X = @inbounds(begin
70+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
71+ (σ * (y - x), x * (ρ - z) - y, x * y - β * z)
72+ end
73+ end)
74+ end
6975 T = promote_type(map(typeof, X)...)
70- convert. (T, X)
76+ map (T, X)
7177 construct = if u isa ModelingToolkit.StaticArrays.StaticArray
7278 ModelingToolkit.StaticArrays.similar_type(typeof(u), eltype(X))
7379 else
7480 x->begin
75- du = similar(u, T, 3)
76- vec(du) .= x
77- du
81+ convert(typeof(u), x)
7882 end
7983 end
8084 construct(X)
8185 end)
8286=#
8387
84- myode_iip = generate_function (de, [x,y,z], [σ,ρ,β] )[2 ] # second one is the in-place function
88+ myode_iip = generate_function (de)[2 ] # second one is the in-place function
8589MacroTools. striplines (myode_iip) # print without line numbers
8690
8791#=
88- ( var"##MTIIPVar#409 ", u, p, t)->begin
89- @inbounds begin
90- @inbounds begin
91- let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
92- var"##MTIIPVar#409 "[1] = σ * (y - x)
93- var"##MTIIPVar#409 "[2] = x * (ρ - z) - y
94- var"##MTIIPVar#409 "[3] = x * y - β * z
95- end
96- end
97- end
98- nothing
99- end
92+ :(( var"##MTIIPVar#793 ", u, p, t)->begin
93+ @inbounds begin
94+ @inbounds begin
95+ let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
96+ var"##MTIIPVar#793 "[1] = σ * (y - x)
97+ var"##MTIIPVar#793 "[2] = x * (ρ - z) - y
98+ var"##MTIIPVar#793 "[3] = x * y - β * z
99+ end
100+ end
101+ end
102+ nothing
103+ end)
100104=#
101105```
102106
0 commit comments