Skip to content

Commit 26c6c6f

Browse files
authored
Merge pull request #133 from SymbolicML/fix-default-node-type
fix: `default_node_type` should not prescribe degree
2 parents e4fbc02 + 679bb40 commit 26c6c6f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/Expression.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function max_degree(::Union{E,Type{E}}) where {E<:AbstractExpression}
107107
return has_node_type(E) ? max_degree(node_type(E)) : max_degree(Node)
108108
end
109109
@unstable default_node_type(_) = Node
110-
default_node_type(::Type{N}) where {T,N<:AbstractExpression{T}} = Node{T,max_degree(N)}
110+
@unstable default_node_type(::Type{N}) where {T,N<:AbstractExpression{T}} = Node{T}
111111

112112
########################################################
113113
# Abstract interface ###################################

src/Interfaces.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using ..NodeModule:
1515
with_type_parameters,
1616
with_max_degree,
1717
max_degree,
18+
has_max_degree,
1819
unsafe_get_children,
1920
get_children,
2021
leaf_copy,
@@ -144,7 +145,8 @@ function _check_default_node(ex::AbstractExpression{T}) where {T}
144145
ET = typeof(ex)
145146
E = Base.typename(ET).wrapper
146147
return default_node_type(E) <: AbstractExpressionNode &&
147-
default_node_type(ET) <: AbstractExpressionNode{T}
148+
default_node_type(ET) <: AbstractExpressionNode{T} &&
149+
!has_max_degree(default_node_type(ET))
148150
end
149151
function _check_constructorof(ex::AbstractExpression)
150152
return constructorof(typeof(ex)) isa Base.Callable

src/ParametricExpression.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,9 @@ end
119119
# Abstract expression node interface ##########################################
120120
###############################################################################
121121
@unstable constructorof(::Type{<:ParametricExpression}) = ParametricExpression
122-
@unstable function default_node_type(::Type{<:ParametricExpression})
123-
return with_default_max_degree(ParametricNode)
124-
end
125-
function default_node_type(::Type{N}) where {T,N<:ParametricExpression{T}}
126-
return ParametricNode{T,max_degree(N)}
127-
end
122+
@unstable default_node_type(::Type{<:ParametricExpression}) = ParametricNode
123+
@unstable default_node_type(::Type{N}) where {T,N<:ParametricExpression{T}} =
124+
ParametricNode{T}
128125
preserve_sharing(::Union{Type{<:ParametricNode},ParametricNode}) = false # COV_EXCL_LINE
129126
function leaf_copy(t::ParametricNode{T}) where {T}
130127
if t.constant

0 commit comments

Comments
 (0)