Skip to content

Fix additional ambiguous methods for Expression interface #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicExpressions"
uuid = "a40a106e-89c9-4ca8-8020-a735e8728b6b"
authors = ["MilesCranmer <[email protected]>"]
version = "0.18.1"
version = "0.18.2"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
5 changes: 5 additions & 0 deletions src/Interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using ..NodeModule:
filter_map!
using ..NodeUtilsModule:
NodeIndex,
is_node_constant,
count_constants,
count_depth,
index_constants,
Expand Down Expand Up @@ -273,6 +274,9 @@ end
function _check_count_depth(tree::AbstractExpressionNode)
return count_depth(tree) isa Int64
end
function _check_is_node_constant(tree::AbstractExpressionNode)
return is_node_constant(tree) isa Bool
end
function _check_count_constants(tree::AbstractExpressionNode)
return count_constants(tree) isa Int64
end
Expand Down Expand Up @@ -324,6 +328,7 @@ ni_components = (
branch_hash = "computes the hash of a branch node" => _check_branch_hash,
branch_equal = "checks equality of two branch nodes" => _check_branch_equal,
count_depth = "calculates the depth of the tree" => _check_count_depth,
is_node_constant = "checks if the node is a constant" => _check_is_node_constant,
count_constants = "counts the number of constants" => _check_count_constants,
filter_map = "applies a filter and map function to the tree" => _check_filter_map,
has_constants = "checks if the tree has constants" => _check_has_constants,
Expand Down
1 change: 0 additions & 1 deletion src/ParametricExpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ..NodeUtilsModule:
get_constants,
set_constants!
import ..StringsModule: string_tree
import ..SimplifyModule: combine_operators, simplify_tree!
import ..EvaluateModule: eval_tree_array
import ..EvaluateDerivativeModule: eval_grad_tree_array
import ..EvaluationHelpersModule: _grad_evaluator
Expand Down
9 changes: 4 additions & 5 deletions src/PatchMethods.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module PatchMethodsModule

using DynamicExpressions: get_contents, with_contents
using ..OperatorEnumModule: AbstractOperatorEnum
using ..NodeModule: constructorof
using ..ExpressionModule: Expression, get_tree, get_operators
Expand All @@ -11,17 +12,15 @@ function combine_operators(
ex::Union{Expression{T,N},ParametricExpression{T,N}},
operators::Union{AbstractOperatorEnum,Nothing}=nothing,
) where {T,N}
return constructorof(typeof(ex))(
combine_operators(get_tree(ex)::N, get_operators(ex, operators)), ex.metadata
return with_contents(
ex, combine_operators(get_contents(ex), get_operators(ex, operators))
)
end
function simplify_tree!(
ex::Union{Expression{T,N},ParametricExpression{T,N}},
operators::Union{AbstractOperatorEnum,Nothing}=nothing,
) where {T,N}
return constructorof(typeof(ex))(
simplify_tree!(get_tree(ex)::N, get_operators(ex, operators)), ex.metadata
)
return with_contents(ex, simplify_tree!(get_contents(ex), get_operators(ex, operators)))
end

end
3 changes: 2 additions & 1 deletion src/Simplify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ is_commutative(_) = false
is_subtraction(::typeof(-)) = true
is_subtraction(_) = false

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