Skip to content

Commit 3fc1e28

Browse files
committed
fix toexpr
1 parent 9b7c580 commit 3fc1e28

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/direct.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,22 +213,22 @@ function sparsehessian(O, vars::AbstractVector; simplify = true)
213213
return H
214214
end
215215

216-
function toexpr(O::Term)
217-
if isa(operation(O), Differential)
218-
return :(derivative($(toexpr(arguments(O)[1])),$(toexpr(operation(O).x))))
219-
elseif isa(operation(O), Sym)
220-
isempty(arguments(O)) && return operation(O).name
221-
return Expr(:call, toexpr(operation(O)), toexpr.(arguments(O))...)
222-
end
223-
if operation(O) === (^)
224-
if length(arguments(O)) > 1 && arguments(O)[2] isa Number && arguments(O)[2] < 0
225-
return Expr(:call, ^, Expr(:call, inv, toexpr(arguments(O)[1])), -(arguments(O)[2]))
226-
end
227-
end
228-
return Expr(:call, operation(O), toexpr.(arguments(O))...)
216+
function toexpr(O)
217+
!istree(O) && return s
218+
if isa(operation(O), Differential)
219+
return :(derivative($(toexpr(arguments(O)[1])),$(toexpr(operation(O).x))))
220+
elseif isa(operation(O), Sym)
221+
isempty(arguments(O)) && return operation(O).name
222+
return Expr(:call, toexpr(operation(O)), toexpr.(arguments(O))...)
223+
end
224+
if operation(O) === (^)
225+
if length(arguments(O)) > 1 && arguments(O)[2] isa Number && arguments(O)[2] < 0
226+
return Expr(:call, ^, Expr(:call, inv, toexpr(arguments(O)[1])), -(arguments(O)[2]))
227+
end
228+
end
229+
return Expr(:call, operation(O), toexpr.(arguments(O))...)
229230
end
230231
toexpr(s::Sym) = nameof(s)
231-
toexpr(s) = s
232232

233233
function toexpr(eq::Equation)
234234
Expr(:(=), toexpr(eq.lhs), toexpr(eq.rhs))

0 commit comments

Comments
 (0)