Skip to content

Commit

Permalink
Update python_builtins.py
Browse files Browse the repository at this point in the history
bit more explicit...
  • Loading branch information
tias authored Oct 3, 2024
1 parent 8d299ab commit dc3ba37
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cpmpy/expressions/python_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@ def abs(element):
if the element given is not a CPMpy expression, the built-in is called
else an Absolute functional global constraint is constructed.
"""
if is_any_list(element):
if is_any_list(element): # compat: not allowed by builtins.abs(), but allowed by numpy.abs()
return cpm_array([abs(elem) for elem in element])

if not isinstance(element, Expression):
return builtins.abs(element)
if isinstance(element, Expression):
# create global
return Abs(element)

return builtins.abs(element)

return Abs(element)

0 comments on commit dc3ba37

Please sign in to comment.