Skip to content

Commit

Permalink
fix: fix stack overflow for methods using symbolic_container to def…
Browse files Browse the repository at this point in the history
…ine a fallback
  • Loading branch information
AayushSabharwal committed Jul 24, 2024
1 parent c834a31 commit 94fba31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index_provider_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ parameter_index(indp, sym) = parameter_index(symbolic_container(indp), sym)
Check whether the given `sym` is a timeseries parameter in `indp`.
"""
function is_timeseries_parameter(indp, sym)
if hasmethod(symbolic_container, Tuple{typeof(indp)})
is_timeseries_parameter(symbolic_container(indp), sym)
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
is_timeseries_parameter(sc, sym)
else
return false
end
Expand Down Expand Up @@ -91,7 +91,7 @@ parameter in `indp`. Defaults to returning `nothing`. Respects the
[`symbolic_container`](@ref) fallback for `indp` if present.
"""
function timeseries_parameter_index(indp, sym)
if hasmethod(symbolic_container, Tuple{typeof(indp)})
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
timeseries_parameter_index(symbolic_container(indp), sym)
else
return nothing
Expand All @@ -111,7 +111,7 @@ By default, this function returns `nothing`, indicating that the index provider
support generating parameter observed functions.
"""
function parameter_observed(indp, sym)
if hasmethod(symbolic_container, Tuple{typeof(indp)})
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
return parameter_observed(symbolic_container(indp), sym)
else
return nothing
Expand Down Expand Up @@ -143,7 +143,7 @@ variable.
By default, this function returns `Set([ContinuousTimeseries()])`.
"""
function get_all_timeseries_indexes(indp, sym)
if hasmethod(symbolic_container, Tuple{typeof(indp)})
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
return get_all_timeseries_indexes(symbolic_container(indp), sym)
else
return Set([ContinuousTimeseries()])
Expand Down Expand Up @@ -240,7 +240,7 @@ Return a dictionary mapping symbols in the index provider to their default value
This includes parameter symbols. The dictionary must be mutable.
"""
function default_values(indp)
if hasmethod(symbolic_container, Tuple{typeof(indp)})
if hasmethod(symbolic_container, Tuple{typeof(indp)}) && (sc = symbolic_container(indp)) !== indp
default_values(symbolic_container(indp))
else
Dict()
Expand Down
2 changes: 2 additions & 0 deletions src/symbol_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function SymbolCache(vars = nothing, params = nothing, indepvars = nothing;
defaults)
end

symbolic_container(sc::SymbolCache) = sc

function is_variable(sc::SymbolCache, sym)
sc.variables === nothing && return false
if symbolic_type(sym) == NotSymbolic()
Expand Down

0 comments on commit 94fba31

Please sign in to comment.