|
287 | 287 | ex = Expression(Node{Float64}(; feature=1))
|
288 | 288 | @test_throws ArgumentError ex(randn(1, 5), OperatorEnum(); bad_arg=1)
|
289 | 289 | end
|
| 290 | + |
| 291 | +@testitem "Test Inf val" begin |
| 292 | + using DynamicExpressions |
| 293 | + |
| 294 | + include("tree_gen_utils.jl") |
| 295 | + |
| 296 | + # Even if the `.val` is `Inf`, we should |
| 297 | + # be able to safely evaluate the expression. |
| 298 | + some_unsafe_operators = OperatorEnum(; |
| 299 | + binary_operators=[+, -, *, /], unary_operators=[sin, cos] |
| 300 | + ) |
| 301 | + |
| 302 | + function fill_vals!(tree, val) |
| 303 | + foreach(tree) do node |
| 304 | + if node.degree == 0 && node.constant |
| 305 | + node.val = val |
| 306 | + end |
| 307 | + end |
| 308 | + end |
| 309 | + |
| 310 | + # We want to compare them: |
| 311 | + num_tests = 100 |
| 312 | + n_features = 3 |
| 313 | + for _ in 1:num_tests |
| 314 | + let tree, X, eval |
| 315 | + tree = gen_random_tree_fixed_size( |
| 316 | + 20, some_unsafe_operators, n_features, Float64 |
| 317 | + ) |
| 318 | + # Now, we set all the constant values to Inf: |
| 319 | + X = zeros(Float64, n_features, 10) |
| 320 | + # Smoke test – we just want to make sure we can evaluate the expression! |
| 321 | + eval_tree_array(tree, X, some_unsafe_operators) |
| 322 | + fill_vals!(tree, Inf) |
| 323 | + eval_tree_array(tree, X, some_unsafe_operators) |
| 324 | + fill_vals!(tree, NaN) |
| 325 | + end |
| 326 | + end |
| 327 | +end |
0 commit comments