Skip to content

Commit 1d3cf4e

Browse files
Update README.md
1 parent c7f0aa5 commit 1d3cf4e

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

README.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,53 @@ generated code via:
5454

5555
```julia
5656
using MacroTools
57-
MacroTools.striplines(generate_function(de, [x,y,z], [σ,ρ,β])[2]) # second one is the in-place function
57+
myode_oop = generate_function(de, [x,y,z], [σ,ρ,β])[2] # first one is the out-of-place function
58+
MacroTools.striplines(myode_oop) # print without line numbers
5859

59-
60-
## Which returns:
61-
:((##363, u, p, t)->begin
62-
let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
63-
##363[1] = σ * (y - x)
64-
##363[2] = x * (ρ - z) - y
65-
##363[3] = x * y - β * z
66-
end
60+
#=
61+
:((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
69+
T = promote_type(map(typeof, X)...)
70+
convert.(T, X)
71+
construct = if u isa ModelingToolkit.StaticArrays.StaticArray
72+
ModelingToolkit.StaticArrays.similar_type(typeof(u), eltype(X))
73+
else
74+
x->begin
75+
du = similar(u, T, 3)
76+
vec(du) .= x
77+
du
78+
end
79+
end
80+
construct(X)
6781
end)
82+
=#
83+
84+
myode_iip = generate_function(de, [x,y,z], [σ,ρ,β])[2] # second one is the in-place function
85+
MacroTools.striplines(myode_iip) # print without line numbers
86+
87+
#=
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
100+
=#
68101
```
69102

70-
and get the generated function via:
103+
or directly get the generated ODE function via:
71104

72105
```julia
73106
f = ODEFunction(de, [x,y,z], [σ,ρ,β])

0 commit comments

Comments
 (0)