Skip to content

Commit 90fe177

Browse files
committed
fix: fix degree in NodeIndex
1 parent d5a69b7 commit 90fe177

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

src/NodeUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ mutable struct NodeIndex{T,D} <: AbstractNode{D}
158158
node = NodeIndex(_T, Val(_D))
159159
poison = get_poison(node)
160160
children = (child, childs...)
161+
node.degree = _D2 + 1
161162
node.children = ntuple(i -> i <= _D2 + 1 ? children[i] : poison, Val(_D))
162163
return node
163164
end

test/test_n_arity_nodes.jl

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ end
453453
tree_ro_ter = Node{Float64,3}(; op=1, children=(x1_ro, x2_ro, x3_ro))
454454

455455
expr_ro = Expression(tree_ro_ter; operators=operators_ro)
456-
readonly_tree = DynamicExpressions.get_tree(expr_ro)
456+
readonly_tree = DynamicExpressions.ReadOnlyNode(DynamicExpressions.get_tree(expr_ro))
457457

458458
@test readonly_tree isa DynamicExpressions.ReadOnlyNodeModule.AbstractReadOnlyNode
459459
inner_node_ro = DynamicExpressions.ReadOnlyNodeModule.inner(readonly_tree)
@@ -472,49 +472,6 @@ end
472472
@test readonly_tree.r.feature == 2
473473
end
474474

475-
@testitem "Expression.jl default_node_type for N-ary" tags = [:narity] begin
476-
using DynamicExpressions
477-
using Test
478-
479-
DefaultNodeForExprT = DynamicExpressions.ExpressionModule.default_node_type(
480-
Expression{Float64}
481-
)
482-
@test DefaultNodeForExprT == Node{Float64,2}
483-
484-
dt_expr_node3 = DynamicExpressions.ExpressionModule.default_node_type(
485-
Expression{Float64,Node{Float64,3}}
486-
)
487-
@test dt_expr_node3 == Node{Float64,3}
488-
489-
abstract type AbstractMyCustomExpr{T,N<:AbstractExpressionNode{T}} <:
490-
AbstractExpression{T,N} end
491-
struct MyCustomExprWithArity{T,N_NODE<:AbstractExpressionNode{T,NODE_D},EXPR_ARITY} <:
492-
AbstractMyCustomExpr{T,N_NODE} where {NODE_D}
493-
tree::N_NODE
494-
end
495-
DynamicExpressions.ExpressionModule.has_node_type(::Type{<:MyCustomExprWithArity}) =
496-
true
497-
DynamicExpressions.ExpressionModule.node_type(
498-
::Type{<:MyCustomExprWithArity{T,N_NODE,EXPR_ARITY}}
499-
) where {T,N_NODE,EXPR_ARITY} = N_NODE
500-
DynamicExpressions.NodeModule.max_degree(
501-
::Type{<:MyCustomExprWithArity{T,N_NODE,EXPR_ARITY}}
502-
) where {T,N_NODE,EXPR_ARITY} = EXPR_ARITY
503-
504-
dt_custom_overall_arity = DynamicExpressions.ExpressionModule.default_node_type(
505-
MyCustomExprWithArity{Float32,Node{Float32,2},4}
506-
)
507-
@test dt_custom_overall_arity == Node{Float32,4}
508-
509-
struct MySimpleExprNoNodeParam{T} <: AbstractExpression{T,Nothing} end
510-
DynamicExpressions.ExpressionModule.has_node_type(::Type{<:MySimpleExprNoNodeParam}) =
511-
false
512-
dt_my_simple_expr = DynamicExpressions.ExpressionModule.default_node_type(
513-
MySimpleExprNoNodeParam{Float64}
514-
)
515-
@test dt_my_simple_expr == Node{Float64,2}
516-
end
517-
518475
@testitem "NodeUtils.jl NodeIndex for N-ary" tags = [:narity] begin
519476
using DynamicExpressions
520477
using Test
@@ -534,6 +491,7 @@ end
534491

535492
@test idx_tree isa NodeIndex{UInt16,3}
536493
@test DynamicExpressions.NodeModule.max_degree(typeof(idx_tree)) == 3
494+
@test tree_idx.degree == 3
537495
@test idx_tree.degree == 3
538496
@test idx_tree.children[1].degree == 0 && idx_tree.children[1].val == UInt16(1)
539497
@test idx_tree.children[2].degree == 0 && idx_tree.children[2].val == UInt16(0)

0 commit comments

Comments
 (0)