Skip to content

Commit

Permalink
Fix nested diff2term edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Jun 9, 2024
1 parent df25344 commit a660080
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,20 @@ function diff2term(O, O_metadata::Union{Dict, Nothing, Base.ImmutableDict}=nothi
ds = nothing
end
d_separator = 'ˍ'
local opname

if ds === nothing
return maketerm(typeof(O), head(O), map(diff2term, children(O)),
symtype(O), O_metadata isa Nothing ?
metadata(O) : Base.ImmutableDict(metadata(O)..., O_metadata...))
else
oldop = operation(O)
if issym(oldop)
opname = string(nameof(oldop))
opname = if issym(oldop)
string(nameof(oldop))
elseif oldop isa Function
@show "here?"
return nothing
elseif iscall(oldop) && operation(oldop) === getindex
opname = string(nameof(arguments(oldop)[1]))
args = arguments(O)
string(nameof(arguments(oldop)[1]))
elseif oldop == getindex
args = arguments(O)
opname = string(tosymbol(args[1]), "[", map(tosymbol, args[2:end])..., "]")
Expand Down
6 changes: 6 additions & 0 deletions test/downstream/modeling_toolkit_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ D = Differential(t)
)
)
)

@variables x y t
D = Differential(t)
Symbolics.diff2term(D(x))
Symbolics.diff2term(D(sqrt(sqrt(sqrt(+(x,y))))))
Symbolics.diff2term(D(x+y))

0 comments on commit a660080

Please sign in to comment.