Skip to content

Commit

Permalink
Add != operator to live calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
apontzen committed Jun 16, 2024
1 parent 3d888c4 commit d78deca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tangos/live_calculation/builtin_functions/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def less(halos, vals1, vals2):
def equal(halos, vals1, vals2):
return arithmetic_binary_op(vals1, vals2, np.equal)

@BuiltinFunction.register
def not_equal(halos, vals1, vals2):
return arithmetic_binary_op(vals1, vals2, np.not_equal)

@BuiltinFunction.register
def greater_equal(halos, vals1, vals2):
return arithmetic_binary_op(vals1, vals2, np.greater_equal)
Expand Down
1 change: 1 addition & 0 deletions tangos/live_calculation/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def pack_args(for_function):
("|", "logical_or"),
("&", "logical_and"),
("==", "equal"),
("!=", "not_equal"),
(">=", "greater_equal"),
("<=", "less_equal")]

Expand Down
4 changes: 4 additions & 0 deletions tests/test_live_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def test_comparison():
assert h.calculate("1.0>=1.0")
assert h.calculate("1.0<=1.0")
assert h.calculate("1.0>=0.5")
assert h.calculate("1==1")
assert h.calculate("finder_id()==1")
assert h.calculate("1!=2")
assert h.calculate("finder_id()!=2")
assert not h.calculate("1.0<=0.5")


Expand Down

0 comments on commit d78deca

Please sign in to comment.