Skip to content

Commit 3993abd

Browse files
fix: fix add_fallbacks!
1 parent 40a85df commit 3993abd

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/systems/problem_utils.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ function symbols_to_symbolics!(sys::AbstractSystem, varmap::AbstractDict)
8888
end
8989
end
9090

91+
"""
92+
$(TYPEDSIGNATURES)
93+
94+
Utility function to get the value `val` corresponding to key `var` in `varmap`, and
95+
return `getindex(val, idx)` if it exists or `nothing` otherwise.
96+
"""
97+
function get_and_getindex(varmap, var, idx)
98+
val = get(varmap, var, nothing)
99+
val === nothing && return nothing
100+
return val[idx]
101+
end
102+
91103
"""
92104
$(TYPEDSIGNATURES)
93105
@@ -115,8 +127,9 @@ function add_fallbacks!(
115127
val = map(eachindex(var)) do idx
116128
# @something is lazy and saves from writing a massive if-elseif-else
117129
@something(get(varmap, var[idx], nothing),
118-
get(varmap, ttvar[idx], nothing), get(fallbacks, var, nothing)[idx],
119-
get(fallbacks, ttvar, nothing)[idx], get(fallbacks, var[idx], nothing),
130+
get(varmap, ttvar[idx], nothing), get_and_getindex(fallbacks, var, idx),
131+
get_and_getindex(fallbacks, ttvar, idx), get(
132+
fallbacks, var[idx], nothing),
120133
get(fallbacks, ttvar[idx], nothing), Some(nothing))
121134
end
122135
# only push the missing entries

0 commit comments

Comments
 (0)