Skip to content

Commit

Permalink
fix: fix fast_substitute folding array of symbolics
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jan 7, 2025
1 parent eb3b5f6 commit 4c06584
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ function fast_substitute(expr, subs; operator = Nothing)
args = let canfold = canfold
map(args) do x
x′ = fast_substitute(x, subs; operator)
canfold[] = canfold[] && !(x′ isa Symbolic)
canfold[] = canfold[] && (symbolic_type(x′) == NotSymbolic() && !is_array_of_symbolics(x′))
x′
end
end
Expand All @@ -633,7 +633,7 @@ function fast_substitute(expr, pair::Pair; operator = Nothing)
args = let canfold = canfold
map(args) do x
x′ = fast_substitute(x, pair; operator)
canfold[] = canfold[] && !(x′ isa Symbolic)
canfold[] = canfold[] && (symbolic_type(x′) == NotSymbolic() && !is_array_of_symbolics(x′))
x′
end
end
Expand All @@ -645,6 +645,13 @@ function fast_substitute(expr, pair::Pair; operator = Nothing)
metadata(expr))
end

function is_array_of_symbolics(x)
symbolic_type(x) == ArraySymbolic() && return true
symbolic_type(x) == ScalarSymbolic() && return false
x isa AbstractArray &&
any(y -> symbolic_type(y) != NotSymbolic() || is_array_of_symbolics(y), x)
end

function getparent(x, val=_fail)
maybe_parent = getmetadata(x, Symbolics.GetindexParent, nothing)
if maybe_parent !== nothing
Expand Down

0 comments on commit 4c06584

Please sign in to comment.