Skip to content

Commit 4c06584

Browse files
fix: fix fast_substitute folding array of symbolics
1 parent eb3b5f6 commit 4c06584

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/variable.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ function fast_substitute(expr, subs; operator = Nothing)
606606
args = let canfold = canfold
607607
map(args) do x
608608
x′ = fast_substitute(x, subs; operator)
609-
canfold[] = canfold[] && !(x′ isa Symbolic)
609+
canfold[] = canfold[] && (symbolic_type(x′) == NotSymbolic() && !is_array_of_symbolics(x′))
610610
x′
611611
end
612612
end
@@ -633,7 +633,7 @@ function fast_substitute(expr, pair::Pair; operator = Nothing)
633633
args = let canfold = canfold
634634
map(args) do x
635635
x′ = fast_substitute(x, pair; operator)
636-
canfold[] = canfold[] && !(x′ isa Symbolic)
636+
canfold[] = canfold[] && (symbolic_type(x′) == NotSymbolic() && !is_array_of_symbolics(x′))
637637
x′
638638
end
639639
end
@@ -645,6 +645,13 @@ function fast_substitute(expr, pair::Pair; operator = Nothing)
645645
metadata(expr))
646646
end
647647

648+
function is_array_of_symbolics(x)
649+
symbolic_type(x) == ArraySymbolic() && return true
650+
symbolic_type(x) == ScalarSymbolic() && return false
651+
x isa AbstractArray &&
652+
any(y -> symbolic_type(y) != NotSymbolic() || is_array_of_symbolics(y), x)
653+
end
654+
648655
function getparent(x, val=_fail)
649656
maybe_parent = getmetadata(x, Symbolics.GetindexParent, nothing)
650657
if maybe_parent !== nothing

0 commit comments

Comments
 (0)