@@ -17,7 +17,8 @@ struct ParameterIndex{P, I}
1717end
1818
1919const ParamIndexMap = Dict{Union{Symbol, BasicSymbolic}, Tuple{Int, Int}}
20- const UnknownIndexMap = Dict{Union{Symbol, BasicSymbolic}, Union{Int, UnitRange{Int}}}
20+ const UnknownIndexMap = Dict{
21+ Union{Symbol, BasicSymbolic}, Union{Int, UnitRange{Int}, AbstractArray{Int}}}
2122
2223struct IndexCache
2324 unknown_idx:: UnknownIndexMap
@@ -40,17 +41,32 @@ function IndexCache(sys::AbstractSystem)
4041 for sym in unks
4142 usym = unwrap (sym)
4243 sym_idx = if Symbolics. isarraysymbolic (sym)
43- idx: (idx + length (sym) - 1 )
44+ reshape ( idx: (idx + length (sym) - 1 ), size (sym) )
4445 else
4546 idx
4647 end
4748 unk_idxs[usym] = sym_idx
4849
49- if hasname (sym)
50+ if hasname (sym) && ( ! istree (sym) || operation (sym) != = getindex)
5051 unk_idxs[getname (usym)] = sym_idx
5152 end
5253 idx += length (sym)
5354 end
55+ for sym in unks
56+ usym = unwrap (sym)
57+ istree (sym) && operation (sym) === getindex || continue
58+ arrsym = arguments (sym)[1 ]
59+ all (haskey (unk_idxs, arrsym[i]) for i in eachindex (arrsym)) || continue
60+
61+ idxs = [unk_idxs[arrsym[i]] for i in eachindex (arrsym)]
62+ if idxs == idxs[begin ]: idxs[end ]
63+ idxs = reshape (idxs[begin ]: idxs[end ], size (idxs))
64+ end
65+ unk_idxs[arrsym] = idxs
66+ if hasname (arrsym)
67+ unk_idxs[getname (arrsym)] = idxs
68+ end
69+ end
5470 end
5571
5672 disc_buffers = Dict {Any, Set{BasicSymbolic}} ()
@@ -124,7 +140,7 @@ function IndexCache(sys::AbstractSystem)
124140 for (j, p) in enumerate (buf)
125141 idxs[p] = (i, j)
126142 idxs[default_toterm (p)] = (i, j)
127- if hasname (p)
143+ if hasname (p) && ( ! istree (p) || operation (p) != = getindex)
128144 idxs[getname (p)] = (i, j)
129145 idxs[getname (default_toterm (p))] = (i, j)
130146 end
0 commit comments