Skip to content

Commit 7d195ad

Browse files
authored
Merge pull request #696 from JuliaSymbolics/s/ref-broadcast
RefValue handling in symtype inference
2 parents da72404 + 49ec0be commit 7d195ad

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/array-lib.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@ function Broadcast.materialize(bc::Broadcast.Broadcasted{SymBroadcast})
159159
subs = map(i-> extruded[i] && isonedim(x, i) ?
160160
1 : subscripts[i], 1:ndims(x))
161161
x[subs...]
162+
elseif x isa Base.RefValue
163+
x[]
162164
else
163165
x
164166
end
165167
end
166-
167168
expr = term(bc.f, expr_args′...) # Imagine x .=> y -- if you don't have a term
168169
# then you get pairs, and index matcher cannot
169170
# recurse into pairs

src/arrays.jl

-15
Original file line numberDiff line numberDiff line change
@@ -558,21 +558,6 @@ function replace_by_scalarizing(ex, dict)
558558
scalarize(~x, (map(j->substitute(j, dict), ~~i)...,)))
559559

560560
simterm = (x, f, args; kws...) -> begin
561-
if f === Base.literal_pow && length(args) == 3
562-
#=
563-
julia> @variables u[1:3]
564-
1-element Vector{Symbolics.Arr{Num, 1}}:
565-
u[1:3]
566-
567-
julia> u.^1
568-
(broadcast(literal_pow, Base.RefValue{typeof(^)}(^), u, Base.RefValue{Val{1}}(Val{1}())))[1:3]
569-
=#
570-
base = args[2]
571-
exp = val2num(only(args[3]))
572-
f = only(args[1])
573-
args = [base, exp]
574-
end
575-
576561
if metadata(x) !== nothing
577562
similarterm(x, f, args; metadata=metadata(x))
578563
else

test/arrays.jl

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ getdef(v) = getmetadata(v, Symbolics.VariableDefaultValue)
113113

114114
##653
115115
Symbolics.scalarize(inv(A)[1,1])
116+
117+
# ModelingToolkit.jl#1736
118+
#
119+
@variables t F(t)[1:1]
120+
121+
@test isequal(collect(F ./ t), [F[1] / t])
116122
end
117123

118124
n = 2

0 commit comments

Comments
 (0)