@@ -37,26 +37,6 @@ const AN = DynamicExpressions.ArenaNodeModule
3737 collected_idxs = map (n -> n. idx, collected)
3838 @test collected_idxs == seen
3939
40- # Postfix stack-based utilities (mirroring symbolic_regression.rs patterns):
41- @test AN. is_valid_postfix (atree)
42-
43- sizes = Int[]
44- size_stack = Int[]
45- AN. subtree_sizes_into! (atree, sizes, size_stack)
46- start, stop = AN. subtree_range (sizes, Int (atree. idx))
47- @test start == 1
48- @test stop == Int (atree. idx)
49-
50- depth_stack = Int[]
51- depth_postfix = AN. tree_mapreduce_postfix_with_stack (
52- atree,
53- _ -> 1 ,
54- _ -> 0 ,
55- (_, children) -> maximum (children) + 1 ,
56- depth_stack,
57- )
58- @test depth_postfix == count_depth (atree)
59-
6040 # Evaluation should match:
6141 X = randn (Float64, 1 , 50 )
6242 y_tree, ok_tree = eval_tree_array (tree, X, operators)
@@ -65,31 +45,6 @@ const AN = DynamicExpressions.ArenaNodeModule
6545 @test ok_atree
6646 @test y_tree ≈ y_atree
6747
68- # Postfix roundtrip sanity check (debug utility; not an execution strategy):
69- pf = AN. emit_postfix (atree)
70- atree_pf = AN. parse_postfix_to_arena (pf)
71- @test AN. is_valid_postfix (atree_pf)
72- @test count_nodes (atree_pf) == count_nodes (atree)
73- @test string_tree (atree_pf, operators) == string_tree (atree, operators)
74- y_pf, ok_pf = eval_tree_array (atree_pf, X, operators)
75- @test ok_pf
76- @test y_pf ≈ y_tree
77-
78- # Minimal rewrite prototype should preserve postfix validity:
79- tree_constleft = 3.2 * x1
80- atree_constleft = AN. arena_from_tree (tree_constleft)
81- @test AN. is_valid_postfix (atree_constleft)
82- y_before, ok_before = eval_tree_array (atree_constleft, X, operators)
83- @test ok_before
84- @test atree_constleft. l. constant
85- AN. rewrite_commutative_constants_right! (atree_constleft, operators)
86- @test AN. is_valid_postfix (atree_constleft)
87- @test ! atree_constleft. l. constant
88- @test atree_constleft. r. constant
89- y_after, ok_after = eval_tree_array (atree_constleft, X, operators)
90- @test ok_after
91- @test y_after ≈ y_before
92-
9348 # In-place set_node! should work even when the source tree is from a different arena.
9449 # (This is important for API-compat with algorithms that construct new subtrees.)
9550 atree_setnode = AN. arena_from_tree (tree)
@@ -132,4 +87,51 @@ const AN = DynamicExpressions.ArenaNodeModule
13287 y_tree2, ok_tree2 = eval_tree_array (tree2, X, operators)
13388 @test ok_tree2
13489 @test y_tree2 ≈ y_mut
90+
91+ @testset " Postfix / debug utilities (not an execution strategy)" begin
92+ # Postfix stack-based utilities (mirroring symbolic_regression.rs patterns):
93+ @test AN. is_valid_postfix (atree)
94+
95+ sizes = Int[]
96+ size_stack = Int[]
97+ AN. subtree_sizes_into! (atree, sizes, size_stack)
98+ start, stop = AN. subtree_range (sizes, Int (atree. idx))
99+ @test start == 1
100+ @test stop == Int (atree. idx)
101+
102+ depth_stack = Int[]
103+ depth_postfix = AN. tree_mapreduce_postfix_with_stack (
104+ atree,
105+ _ -> 1 ,
106+ _ -> 0 ,
107+ (_, children) -> maximum (children) + 1 ,
108+ depth_stack,
109+ )
110+ @test depth_postfix == count_depth (atree)
111+
112+ # Postfix roundtrip sanity check (debug utility; not an execution strategy):
113+ pf = AN. emit_postfix (atree)
114+ atree_pf = AN. parse_postfix_to_arena (pf)
115+ @test AN. is_valid_postfix (atree_pf)
116+ @test count_nodes (atree_pf) == count_nodes (atree)
117+ @test string_tree (atree_pf, operators) == string_tree (atree, operators)
118+ y_pf, ok_pf = eval_tree_array (atree_pf, X, operators)
119+ @test ok_pf
120+ @test y_pf ≈ y_tree
121+
122+ # Minimal rewrite prototype should preserve postfix validity:
123+ tree_constleft = 3.2 * x1
124+ atree_constleft = AN. arena_from_tree (tree_constleft)
125+ @test AN. is_valid_postfix (atree_constleft)
126+ y_before, ok_before = eval_tree_array (atree_constleft, X, operators)
127+ @test ok_before
128+ @test atree_constleft. l. constant
129+ AN. rewrite_commutative_constants_right! (atree_constleft, operators)
130+ @test AN. is_valid_postfix (atree_constleft)
131+ @test ! atree_constleft. l. constant
132+ @test atree_constleft. r. constant
133+ y_after, ok_after = eval_tree_array (atree_constleft, X, operators)
134+ @test ok_after
135+ @test y_after ≈ y_before
136+ end
135137end
0 commit comments