There’s a block of code example that I’m trying to understand here:
using DiffEqGPU, OrdinaryDiffEq
du = p*(u-u)
du = u*(p-u) - u
du = u*u - p*u
u0 = Float32[1.0;0.0;0.0]
tspan = (0.0f0,100.0f0)
p = [10.0f0,28.0f0,8/3f0]
prob = ODEProblem(lorenz,u0,tspan,p)
prob_func = (prob,i,repeat) -> remake(prob,p=rand(Float32,3).*p)
I’m having trouble interpreting the syntax for prob_func. I think its an anonymous function that is feeding (prob, i, repeat) into ODEproblem. But i is undefined and repeat is a function in julia – how are these being used by remake?
Yes, the syntax
(prob,i,repeat) -> remake(prob,p=rand(Float32,3).*p) defines an anonymous function which takes three parameters,
repeat and uses only the first one of the three. The anonymous function is then bound to the name
prob_func and you may as well have defined it directly as
prob_func(prob,i,repeat) = remake(prob,p=rand(Float32,3).*p).
i is a parameter to the function, so it doesn’t have to be already defined - just like
lorenz function’s definition don’t have to already exist. They get assigned values when they’re called.
repeat, within the context of this function, it gets defined to be the argument value instead. Globally,
repeat still refers to the function
Base.repeat, but in this local scope,
repeat instead refers only to the argument that was passed in.