@@ -35,10 +35,15 @@ set_parameter!(sys, val, idx) = set_parameter!(parameter_values(sys), val, idx)
3535"""
3636 getp(sys, p)
3737
38- Return a function that takes an array representing the parameter vector or an integrator
38+ Return a function that takes an array representing the parameter object or an integrator
3939or solution of `sys`, and returns the value of the parameter `p`. Note that `p` can be a
4040direct index or a symbolic value, or an array/tuple of the aforementioned.
4141
42+ If `p` is an array/tuple of parameters, then the returned function can also be used
43+ as an in-place getter function. The first argument is the buffer to which the parameter
44+ values should be written, and the second argument is the parameter object/integrator/
45+ solution from which the values are obtained.
46+
4247Requires that the integrator or solution implement [`parameter_values`](@ref). This function
4348typically does not need to be implemented, and has a default implementation relying on
4449[`parameter_values`](@ref).
5762
5863function _getp (sys, :: ScalarSymbolic , :: SymbolicTypeTrait , p)
5964 idx = parameter_index (sys, p)
60- return function getter (sol)
61- return parameter_values (sol, idx)
65+ return let idx = idx
66+ function getter (sol)
67+ return parameter_values (sol, idx)
68+ end
6269 end
6370end
6471
@@ -70,8 +77,16 @@ for (t1, t2) in [
7077 @eval function _getp (sys, :: NotSymbolic , :: $t1 , p:: $t2 )
7178 getters = getp .((sys,), p)
7279
73- return function getter (sol)
74- map (g -> g (sol), getters)
80+ return let getters = getters
81+ function getter (sol)
82+ map (g -> g (sol), getters)
83+ end
84+ function getter (buffer, sol)
85+ for (i, g) in zip (eachindex (buffer), getters)
86+ buffer[i] = g (sol)
87+ end
88+ buffer
89+ end
7590 end
7691 end
7792end
0 commit comments