254254# # Bounds ======================================================================
255255struct  VariableBounds end 
256256Symbolics. option_to_metadata_type (:: Val{:bounds} ) =  VariableBounds
257- getbounds (x:: Num ) =  getbounds (Symbolics. unwrap (x))
258257
259258""" 
260259    getbounds(x) 
@@ -266,10 +265,35 @@ Create parameters with bounds like this
266265@parameters p [bounds=(-1, 1)] 
267266``` 
268267""" 
269- function  getbounds (x)
268+ function  getbounds (x:: Union{Num, Symbolics.Arr, SymbolicUtils.Symbolic} )
269+     x =  unwrap (x)
270270    p =  Symbolics. getparent (x, nothing )
271-     p ===  nothing  ||  (x =  p)
272-     Symbolics. getmetadata (x, VariableBounds, (- Inf , Inf ))
271+     if  p ===  nothing 
272+         bounds =  Symbolics. getmetadata (x, VariableBounds, (- Inf , Inf ))
273+         if  symbolic_type (x) ==  ArraySymbolic () &&  Symbolics. shape (x) !=  Symbolics. Unknown ()
274+             bounds =  map (bounds) do  b
275+                 b isa  AbstractArray &&  return  b
276+                 return  fill (b, size (x))
277+             end 
278+         end 
279+     else 
280+         #  if we reached here, `x` is the result of calling `getindex`
281+         bounds =  @something  Symbolics. getmetadata (x, VariableBounds, nothing ) getbounds (p)
282+         idxs =  arguments (x)[2 : end ]
283+         bounds =  map (bounds) do  b
284+             if  b isa  AbstractArray
285+                 if  Symbolics. shape (p) !=  Symbolics. Unknown () &&  size (p) !=  size (b)
286+                     throw (DimensionMismatch (" Expected array variable $p  with shape $(size (p))  to have bounds of identical size. Found $bounds  of size $(size (bounds)) ."  ))
287+                 end 
288+                 return  b[idxs... ]
289+             elseif  symbolic_type (x) ==  ArraySymbolic ()
290+                 return  fill (b, size (x))
291+             else 
292+                 return  b
293+             end 
294+         end 
295+     end 
296+     return  bounds
273297end 
274298
275299""" 
@@ -280,7 +304,7 @@ See also [`getbounds`](@ref).
280304""" 
281305function  hasbounds (x)
282306    b =  getbounds (x)
283-     isfinite (b[1 ]) ||  isfinite (b[2 ])
307+     any ( isfinite . (b[1 ]) . ||  isfinite . (b[2 ]) )
284308end 
285309
286310# # Disturbance =================================================================
0 commit comments