Skip to content

Commit 1d86cc2

Browse files
committed
fix: generalize combine_operators
1 parent db17350 commit 1d86cc2

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/ParametricExpression.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import ..NodeUtilsModule:
1515
get_constants,
1616
set_constants!
1717
import ..StringsModule: string_tree
18-
import ..SimplifyModule: combine_operators, simplify_tree!
1918
import ..EvaluateModule: eval_tree_array
2019
import ..EvaluateDerivativeModule: eval_grad_tree_array
2120
import ..EvaluationHelpersModule: _grad_evaluator

src/PatchMethods.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module PatchMethodsModule
22

3+
using DynamicExpressions: get_contents, with_contents
34
using ..OperatorEnumModule: AbstractOperatorEnum
45
using ..NodeModule: constructorof
56
using ..ExpressionModule: Expression, get_tree, get_operators
@@ -11,17 +12,15 @@ function combine_operators(
1112
ex::Union{Expression{T,N},ParametricExpression{T,N}},
1213
operators::Union{AbstractOperatorEnum,Nothing}=nothing,
1314
) where {T,N}
14-
return constructorof(typeof(ex))(
15-
combine_operators(get_tree(ex)::N, get_operators(ex, operators)), ex.metadata
15+
return with_contents(
16+
ex, combine_operators(get_contents(ex), get_operators(ex, operators))
1617
)
1718
end
1819
function simplify_tree!(
1920
ex::Union{Expression{T,N},ParametricExpression{T,N}},
2021
operators::Union{AbstractOperatorEnum,Nothing}=nothing,
2122
) where {T,N}
22-
return constructorof(typeof(ex))(
23-
simplify_tree!(get_tree(ex)::N, get_operators(ex, operators)), ex.metadata
24-
)
23+
return with_contents(ex, simplify_tree!(get_contents(ex), get_operators(ex, operators)))
2524
end
2625

2726
end

src/Simplify.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ is_commutative(_) = false
1515
is_subtraction(::typeof(-)) = true
1616
is_subtraction(_) = false
1717

18-
# This is only defined for `Node` as it is not possible for
18+
combine_operators(tree::AbstractExpressionNode, ::AbstractOperatorEnum) = tree
19+
# This is only defined for `Node` as it is not possible for, e.g.,
1920
# `GraphNode`.
2021
function combine_operators(tree::Node{T}, operators::AbstractOperatorEnum) where {T}
2122
# NOTE: (const (+*-) const) already accounted for. Call simplify_tree! before.

0 commit comments

Comments
 (0)