@@ -165,7 +165,7 @@ function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys
165
165
if ! iscomplete (sys)
166
166
error (" A completed system is required. Call `complete` or `structural_simplify` on the system." )
167
167
end
168
- p = reorder_parameters (sys, ps )
168
+ p = reorder_parameters (sys, unwrap .(ps) )
169
169
isscalar = ! (exprs isa AbstractArray)
170
170
if wrap_code === nothing
171
171
wrap_code = isscalar ? identity : (identity, identity)
@@ -347,25 +347,23 @@ end
347
347
348
348
# Treat the result as a vector of symbols always
349
349
function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym)
350
- if unwrap (sym) isa Int # [x, 1] coerces 1 to a Num
351
- return unwrap (sym) in 1 : length (variable_symbols (sys))
350
+ sym = unwrap (sym)
351
+ if sym isa Int # [x, 1] coerces 1 to a Num
352
+ return sym in 1 : length (variable_symbols (sys))
352
353
end
353
- if has_index_cache (sys) && get_index_cache (sys) != = nothing
354
- ic = get_index_cache (sys)
355
- h = getsymbolhash (sym)
356
- return haskey (ic. unknown_idx, h) ||
357
- haskey (ic. unknown_idx, getsymbolhash (default_toterm (sym))) ||
358
- (istree (sym) && operation (sym) === getindex &&
359
- is_variable (sys, first (arguments (sym))))
360
- else
361
- return any (isequal (sym), variable_symbols (sys)) ||
362
- hasname (sym) && is_variable (sys, getname (sym))
354
+ if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
355
+ return is_variable (ic, sym) ||
356
+ istree (sym) && operation (sym) === getindex &&
357
+ is_variable (ic, first (arguments (sym)))
363
358
end
359
+ return any (isequal (sym), variable_symbols (sys)) ||
360
+ hasname (sym) && is_variable (sys, getname (sym))
364
361
end
365
362
366
363
function SymbolicIndexingInterface. is_variable (sys:: AbstractSystem , sym:: Symbol )
364
+ sym = unwrap (sym)
367
365
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
368
- return haskey (ic. unknown_idx, hash ( sym) )
366
+ return is_variable (ic, sym)
369
367
end
370
368
return any (isequal (sym), getname .(variable_symbols (sys))) ||
371
369
count (' ₊' , string (sym)) == 1 &&
@@ -374,21 +372,19 @@ function SymbolicIndexingInterface.is_variable(sys::AbstractSystem, sym::Symbol)
374
372
end
375
373
376
374
function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym)
377
- if unwrap (sym) isa Int
378
- return unwrap (sym)
375
+ sym = unwrap (sym)
376
+ if sym isa Int
377
+ return sym
379
378
end
380
- if has_index_cache (sys) && get_index_cache (sys) != = nothing
381
- ic = get_index_cache (sys)
382
- h = getsymbolhash (sym)
383
- haskey (ic. unknown_idx, h) && return ic. unknown_idx[h]
384
-
385
- h = getsymbolhash (default_toterm (sym))
386
- haskey (ic. unknown_idx, h) && return ic. unknown_idx[h]
387
- sym = unwrap (sym)
388
- istree (sym) && operation (sym) === getindex || return nothing
389
- idx = variable_index (sys, first (arguments (sym)))
390
- idx === nothing && return nothing
391
- return idx[arguments (sym)[(begin + 1 ): end ]. .. ]
379
+ if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
380
+ return if (idx = variable_index (ic, sym)) != = nothing
381
+ idx
382
+ elseif istree (sym) && operation (sym) === getindex &&
383
+ (idx = variable_index (ic, first (arguments (sym)))) != = nothing
384
+ idx[arguments (sym)[(begin + 1 ): end ]. .. ]
385
+ else
386
+ nothing
387
+ end
392
388
end
393
389
idx = findfirst (isequal (sym), variable_symbols (sys))
394
390
if idx === nothing && hasname (sym)
399
395
400
396
function SymbolicIndexingInterface. variable_index (sys:: AbstractSystem , sym:: Symbol )
401
397
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
402
- return get (ic. unknown_idx, h, nothing )
398
+ return variable_index (ic, sym )
403
399
end
404
400
idx = findfirst (isequal (sym), getname .(variable_symbols (sys)))
405
401
if idx != = nothing
@@ -418,30 +414,22 @@ function SymbolicIndexingInterface.variable_symbols(sys::AbstractSystem)
418
414
end
419
415
420
416
function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym)
417
+ sym = unwrap (sym)
418
+ if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
419
+ return is_parameter (ic, sym) ||
420
+ istree (sym) && operation (sym) === getindex &&
421
+ is_parameter (ic, first (arguments (sym)))
422
+ end
421
423
if unwrap (sym) isa Int
422
424
return unwrap (sym) in 1 : length (parameter_symbols (sys))
423
425
end
424
- if has_index_cache (sys) && get_index_cache (sys) != = nothing
425
- ic = get_index_cache (sys)
426
- h = getsymbolhash (sym)
427
- return if haskey (ic. param_idx, h) || haskey (ic. discrete_idx, h) ||
428
- haskey (ic. constant_idx, h) || haskey (ic. dependent_idx, h) ||
429
- haskey (ic. nonnumeric_idx, h)
430
- true
431
- else
432
- h = getsymbolhash (default_toterm (sym))
433
- haskey (ic. param_idx, h) || haskey (ic. discrete_idx, h) ||
434
- haskey (ic. constant_idx, h) || haskey (ic. dependent_idx, h) ||
435
- haskey (ic. nonnumeric_idx, h)
436
- end
437
- end
438
426
return any (isequal (sym), parameter_symbols (sys)) ||
439
427
hasname (sym) && is_parameter (sys, getname (sym))
440
428
end
441
429
442
430
function SymbolicIndexingInterface. is_parameter (sys:: AbstractSystem , sym:: Symbol )
443
431
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
444
- return ParameterIndex (ic, sym) != = nothing
432
+ return is_parameter (ic, sym)
445
433
end
446
434
return any (isequal (sym), getname .(parameter_symbols (sys))) ||
447
435
count (' ₊' , string (sym)) == 1 &&
@@ -450,20 +438,21 @@ function SymbolicIndexingInterface.is_parameter(sys::AbstractSystem, sym::Symbol
450
438
end
451
439
452
440
function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym)
453
- if unwrap (sym) isa Int
454
- return unwrap (sym)
455
- end
456
- if has_index_cache (sys) && get_index_cache (sys) != = nothing
457
- ic = get_index_cache (sys)
458
- return if (idx = ParameterIndex (ic, sym)) != = nothing
459
- idx
460
- elseif (idx = ParameterIndex (ic, default_toterm (sym))) != = nothing
441
+ sym = unwrap (sym)
442
+ if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
443
+ return if (idx = parameter_index (ic, sym)) != = nothing
461
444
idx
445
+ elseif istree (sym) && operation (sym) === getindex &&
446
+ (idx = parameter_index (ic, first (arguments (sym)))) != = nothing
447
+ ParameterIndex (idx. portion, (idx. idx... , arguments (sym)[(begin + 1 ): end ]. .. ))
462
448
else
463
449
nothing
464
450
end
465
451
end
466
452
453
+ if sym isa Int
454
+ return sym
455
+ end
467
456
idx = findfirst (isequal (sym), parameter_symbols (sys))
468
457
if idx === nothing && hasname (sym)
469
458
idx = parameter_index (sys, getname (sym))
473
462
474
463
function SymbolicIndexingInterface. parameter_index (sys:: AbstractSystem , sym:: Symbol )
475
464
if has_index_cache (sys) && (ic = get_index_cache (sys)) != = nothing
476
- return ParameterIndex (ic, sym)
465
+ return parameter_index (ic, sym)
477
466
end
478
467
idx = findfirst (isequal (sym), getname .(parameter_symbols (sys)))
479
468
if idx != = nothing
0 commit comments