Skip to content

Commit 1581a51

Browse files
committed
Include test for unary operator
1 parent 0de6c6a commit 1581a51

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/test_tensor_operators.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ tree = Node(1, c1, x2)
2121
tree = Node(1, x1, c1)
2222
@test repr(tree) == "vec_add(x1, [1.0, 2.0, 3.0])"
2323
@test tree(X) == [3.0, 4.0, 5.0]
24+
25+
# Also test unary operators:
26+
function vec_square(x)
27+
return x .* x
28+
end
29+
30+
operators = GenericOperatorEnum(; binary_operators=[vec_add], unary_operators=[vec_square], extend_user_operators=true)
31+
tree = Node(1, c1)
32+
@test repr(tree) == "vec_square([1.0, 2.0, 3.0])"
33+
@test tree(X) == [1.0, 4.0, 9.0]
34+
tree = Node(1, Node(1, c1), x1)
35+
@test repr(tree) == "vec_add(vec_square([1.0, 2.0, 3.0]), x1)"
36+
@test tree(X) == [3.0, 6.0, 11.0]

0 commit comments

Comments
 (0)