|
1 | 1 | @testitem "Buffer creation and validation" begin |
2 | 2 | using DynamicExpressions |
| 3 | + using DynamicExpressions: ArrayBuffer |
3 | 4 |
|
4 | 5 | # Test data setup |
5 | 6 | X = rand(2, 10) # 2 features, 10 samples |
|
11 | 12 | # Basic buffer creation - buffer shape should match (num_leafs, num_samples) |
12 | 13 | buffer = zeros(5, size(X, 2)) # 5 leaves should be enough for our test tree |
13 | 14 | buffer_ref = Ref(0) |
14 | | - eval_options = EvalOptions(; buffer=buffer, buffer_ref=buffer_ref) |
| 15 | + eval_options = EvalOptions(; buffer=ArrayBuffer(buffer, buffer_ref)) |
15 | 16 | @test eval_options.buffer.array === buffer |
16 | 17 | @test eval_options.buffer.index === buffer_ref |
17 | 18 |
|
18 | 19 | # Test buffer is not allowed with bumper |
19 | 20 | @test_throws AssertionError EvalOptions(; |
20 | | - bumper=true, buffer=buffer, buffer_ref=buffer_ref |
| 21 | + bumper=true, buffer=ArrayBuffer(buffer, buffer_ref) |
21 | 22 | ) |
22 | 23 |
|
23 | 24 | # Basic evaluation should work |
|
28 | 29 |
|
29 | 30 | @testitem "Buffer correctness" begin |
30 | 31 | using DynamicExpressions |
| 32 | + using DynamicExpressions: ArrayBuffer |
31 | 33 |
|
32 | 34 | X = rand(2, 10) |
33 | 35 | operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin]) |
|
45 | 47 | # Evaluation with buffer |
46 | 48 | buffer = zeros(5, size(X, 2)) |
47 | 49 | buffer_ref = Ref(0) |
48 | | - eval_options = EvalOptions(; buffer=buffer, buffer_ref=buffer_ref) |
| 50 | + eval_options = EvalOptions(; buffer=ArrayBuffer(buffer, buffer_ref)) |
49 | 51 | result2, ok2 = eval_tree_array(tree, X, operators; eval_options) |
50 | 52 |
|
51 | 53 | # Results should be identical |
|
56 | 58 |
|
57 | 59 | @testitem "Buffer index management" begin |
58 | 60 | using DynamicExpressions |
59 | | - |
| 61 | + using DynamicExpressions: ArrayBuffer |
60 | 62 | X = rand(2, 10) |
61 | 63 | operators = OperatorEnum(; binary_operators=[+, *], unary_operators=[sin]) |
62 | 64 |
|
|
70 | 72 | # This tree needs more buffer space due to intermediate computations |
71 | 73 | buffer = zeros(10, size(X, 2)) |
72 | 74 | buffer_ref = Ref(0) |
73 | | - eval_options = EvalOptions(; buffer=buffer, buffer_ref=buffer_ref) |
| 75 | + eval_options = EvalOptions(; buffer=ArrayBuffer(buffer, buffer_ref)) |
74 | 76 |
|
75 | 77 | # Index should start at 1 |
76 | 78 | @test buffer_ref[] == 0 |
|
93 | 95 |
|
94 | 96 | @testitem "Buffer error handling" begin |
95 | 97 | using DynamicExpressions |
| 98 | + using DynamicExpressions: ArrayBuffer |
96 | 99 |
|
97 | 100 | X = rand(2, 10) |
98 | 101 | operators = OperatorEnum(; binary_operators=[+, /, *], unary_operators=[sin]) |
|
106 | 109 |
|
107 | 110 | buffer = zeros(5, size(X, 2)) |
108 | 111 | buffer_ref = Ref(0) |
109 | | - eval_options = EvalOptions(; buffer=buffer, buffer_ref=buffer_ref) |
| 112 | + eval_options = EvalOptions(; buffer=ArrayBuffer(buffer, buffer_ref)) |
110 | 113 |
|
111 | 114 | # Test with early_exit=true |
112 | 115 | result1, ok1 = eval_tree_array(tree, X, operators; eval_options) |
|
115 | 118 |
|
116 | 119 | @testitem "Random tree buffer evaluation" begin |
117 | 120 | using DynamicExpressions |
| 121 | + using DynamicExpressions: ArrayBuffer |
118 | 122 | using Random |
119 | 123 | using LoopVectorization |
120 | 124 | include("tree_gen_utils.jl") |
|
139 | 143 | # Buffer evaluation |
140 | 144 | buffer = Array{Float64}(undef, 2n_nodes, size(X, 2)) |
141 | 145 | buffer_ref = Ref(rand(1:10)) # Random starting index (will be reset) |
142 | | - eval_options = EvalOptions(; turbo, buffer, buffer_ref) |
| 146 | + eval_options = EvalOptions(; turbo, buffer=ArrayBuffer(buffer, buffer_ref)) |
143 | 147 | result2, ok2 = eval_tree_array(tree, X, operators; eval_options) |
144 | 148 |
|
145 | 149 | # Results should be identical |
|
0 commit comments