@@ -97,8 +97,8 @@ function IndexCache(sys::AbstractSystem)
97
97
end
98
98
end
99
99
100
- tunable_buffers = Dict {Any, Set{ BasicSymbolic}} ()
101
- initial_param_buffers = Dict {Any, Set{ BasicSymbolic}} ()
100
+ tunable_pars = BasicSymbolic[]
101
+ initial_pars = BasicSymbolic[]
102
102
constant_buffers = Dict {Any, Set{BasicSymbolic}} ()
103
103
nonnumeric_buffers = Dict {Any, Set{SymbolicParam}} ()
104
104
@@ -107,6 +107,10 @@ function IndexCache(sys::AbstractSystem)
107
107
buf = get! (buffers, ctype, S ())
108
108
push! (buf, sym)
109
109
end
110
+ function insert_by_type! (buffers:: Vector{BasicSymbolic} , sym, ctype)
111
+ sym = unwrap (sym)
112
+ push! (buffers, sym)
113
+ end
110
114
111
115
disc_param_callbacks = Dict {SymbolicParam, Set{Int}} ()
112
116
events = vcat (continuous_events (sys), discrete_events (sys))
@@ -210,9 +214,9 @@ function IndexCache(sys::AbstractSystem)
210
214
ctype <: AbstractArray{Real} ||
211
215
ctype <: AbstractArray{<:AbstractFloat} )
212
216
if iscall (p) && operation (p) isa Initial
213
- initial_param_buffers
217
+ initial_pars
214
218
else
215
- tunable_buffers
219
+ tunable_pars
216
220
end
217
221
else
218
222
constant_buffers
@@ -255,47 +259,41 @@ function IndexCache(sys::AbstractSystem)
255
259
256
260
tunable_idxs = TunableIndexMap ()
257
261
tunable_buffer_size = 0
258
- bufferlist = is_initializesystem (sys) ? (tunable_buffers, initial_param_buffers) :
259
- (tunable_buffers,)
260
- for buffers in bufferlist
261
- for (i, (_, buf)) in enumerate (buffers)
262
- for (j, p) in enumerate (buf)
263
- idx = if size (p) == ()
264
- tunable_buffer_size + 1
265
- else
266
- reshape (
267
- (tunable_buffer_size + 1 ): (tunable_buffer_size + length (p)), size (p))
268
- end
269
- tunable_buffer_size += length (p)
270
- tunable_idxs[p] = idx
271
- tunable_idxs[default_toterm (p)] = idx
272
- if hasname (p) && (! iscall (p) || operation (p) != = getindex)
273
- symbol_to_variable[getname (p)] = p
274
- symbol_to_variable[getname (default_toterm (p))] = p
275
- end
276
- end
262
+ if is_initializesystem (sys)
263
+ append! (tunable_pars, initial_pars)
264
+ empty! (initial_pars)
265
+ end
266
+ for p in tunable_pars
267
+ idx = if size (p) == ()
268
+ tunable_buffer_size + 1
269
+ else
270
+ reshape (
271
+ (tunable_buffer_size + 1 ): (tunable_buffer_size + length (p)), size (p))
272
+ end
273
+ tunable_buffer_size += length (p)
274
+ tunable_idxs[p] = idx
275
+ tunable_idxs[default_toterm (p)] = idx
276
+ if hasname (p) && (! iscall (p) || operation (p) != = getindex)
277
+ symbol_to_variable[getname (p)] = p
278
+ symbol_to_variable[getname (default_toterm (p))] = p
277
279
end
278
280
end
279
281
280
282
initials_idxs = TunableIndexMap ()
281
283
initials_buffer_size = 0
282
- if ! is_initializesystem (sys)
283
- for (i, (_, buf)) in enumerate (initial_param_buffers)
284
- for (j, p) in enumerate (buf)
285
- idx = if size (p) == ()
286
- initials_buffer_size + 1
287
- else
288
- reshape (
289
- (initials_buffer_size + 1 ): (initials_buffer_size + length (p)), size (p))
290
- end
291
- initials_buffer_size += length (p)
292
- initials_idxs[p] = idx
293
- initials_idxs[default_toterm (p)] = idx
294
- if hasname (p) && (! iscall (p) || operation (p) != = getindex)
295
- symbol_to_variable[getname (p)] = p
296
- symbol_to_variable[getname (default_toterm (p))] = p
297
- end
298
- end
284
+ for p in initial_pars
285
+ idx = if size (p) == ()
286
+ initials_buffer_size + 1
287
+ else
288
+ reshape (
289
+ (initials_buffer_size + 1 ): (initials_buffer_size + length (p)), size (p))
290
+ end
291
+ initials_buffer_size += length (p)
292
+ initials_idxs[p] = idx
293
+ initials_idxs[default_toterm (p)] = idx
294
+ if hasname (p) && (! iscall (p) || operation (p) != = getindex)
295
+ symbol_to_variable[getname (p)] = p
296
+ symbol_to_variable[getname (default_toterm (p))] = p
299
297
end
300
298
end
301
299
0 commit comments