Skip to content

Commit fc21d66

Browse files
Minor stylistic improvements
1 parent f168ee9 commit fc21d66

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/simplify.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function _simplify_constants(O, shorten_tree = true)
1515
# Tree shrinking
1616
if shorten_tree && O.op AC_OPERATORS
1717
# Flatten tree
18-
idxs = findall(x -> is_operation(x) && x.op == O.op, O.args)
18+
idxs = findall(x -> is_operation(x) && x.op === O.op, O.args)
1919
if !isempty(idxs)
2020
keep_idxs = eachindex(O.args) .∉ Ref(idxs)
2121
args = Vector{Expression}[O.args[i].args for i in idxs]
@@ -26,12 +26,12 @@ function _simplify_constants(O, shorten_tree = true)
2626
# Collapse constants
2727
idxs = findall(is_constant, O.args)
2828
if length(idxs) > 1
29-
other_idxs = eachindex(O.args) .∉ (idxs,)
30-
new_var = Constant(mapreduce(get, O.op, O.args[idxs]))
31-
new_args = O.args[other_idxs]
32-
push!(new_args,new_var)
29+
other_idxs = eachindex(O.args) .∉ Ref(idxs)
30+
new_const = Constant(mapreduce(get, O.op, O.args[idxs]))
31+
args = push!(O.args[other_idxs], new_const)
3332

34-
return length(new_args) > 1 ? Operation(O.op, new_args) : first(new_args)
33+
length(args) == 1 && return first(args)
34+
return Operation(O.op, args)
3535
end
3636
end
3737

@@ -67,7 +67,7 @@ function _simplify_constants(O, shorten_tree = true)
6767

6868
return O
6969
end
70-
simplify_constants(x::Variable,y=false) = x
71-
_simplify_constants(x::Variable,y=false) = x
70+
simplify_constants(x::Variable, y=false) = x
71+
_simplify_constants(x::Variable, y=false) = x
7272

7373
export simplify_constants

0 commit comments

Comments
 (0)