|
237 | 237 | end |
238 | 238 | end |
239 | 239 |
|
| 240 | +@testitem "No operators and variable names" begin |
| 241 | + using DynamicExpressions |
| 242 | + |
| 243 | + x1 = Node{Float64}(; feature=1) |
| 244 | + expr = Expression(x1; operators=nothing, variable_names=nothing) |
| 245 | + |
| 246 | + @test sprint(show, expr) == "x1" |
| 247 | + @test copy(expr) == expr |
| 248 | + @test hash(expr) == hash(copy(expr)) |
| 249 | + |
| 250 | + @test sprint(show, get_metadata(expr)) == |
| 251 | + "Metadata((operators = nothing, variable_names = nothing))" |
| 252 | + |
| 253 | + cos_x1 = Node{Float64}(; op=1, l=x1) |
| 254 | + expr = Expression(cos_x1; operators=nothing, variable_names=nothing) |
| 255 | + @test sprint(show, expr) == "unary_operator[1](x1)" |
| 256 | + @test copy(expr) == expr |
| 257 | + @test hash(expr) == hash(copy(expr)) |
| 258 | + |
| 259 | + @test sprint(show, get_metadata(expr)) == |
| 260 | + "Metadata((operators = nothing, variable_names = nothing))" |
| 261 | + |
| 262 | + @test_throws MethodError expr(rand(Float64, 2, 5)) |
| 263 | + |
| 264 | + # Now, with passing operators explicitly |
| 265 | + X = rand(Float64, 2, 5) |
| 266 | + operators = OperatorEnum(; unary_operators=[cos]) |
| 267 | + @test expr(X, operators) ≈ cos.(X[1, :]) |
| 268 | +end |
| 269 | + |
240 | 270 | @testitem "Miscellaneous expression calls" begin |
241 | 271 | using DynamicExpressions |
242 | 272 | using DynamicExpressions: get_tree, get_operators |
|
0 commit comments