@@ -35,10 +35,15 @@ set_parameter!(sys, val, idx) = set_parameter!(parameter_values(sys), val, idx)
35
35
"""
36
36
getp(sys, p)
37
37
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
39
39
or solution of `sys`, and returns the value of the parameter `p`. Note that `p` can be a
40
40
direct index or a symbolic value, or an array/tuple of the aforementioned.
41
41
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
+
42
47
Requires that the integrator or solution implement [`parameter_values`](@ref). This function
43
48
typically does not need to be implemented, and has a default implementation relying on
44
49
[`parameter_values`](@ref).
57
62
58
63
function _getp (sys, :: ScalarSymbolic , :: SymbolicTypeTrait , p)
59
64
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
62
69
end
63
70
end
64
71
@@ -70,8 +77,16 @@ for (t1, t2) in [
70
77
@eval function _getp (sys, :: NotSymbolic , :: $t1 , p:: $t2 )
71
78
getters = getp .((sys,), p)
72
79
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
75
90
end
76
91
end
77
92
end
0 commit comments