abs dunder function added for values

This commit is contained in:
Nicolas Kruse 2025-12-19 16:07:49 +01:00
parent 369c279a68
commit c2e10ec0cb
1 changed files with 3 additions and 0 deletions

View File

@ -220,6 +220,9 @@ class value(Generic[TNum], Net):
def __rfloordiv__(self, other: NumLike) -> Any:
return add_op('floordiv', [other, self])
def __abs__(self: TCPNum) -> TCPNum:
return cp.abs(self) # type: ignore
def __neg__(self: TCPNum) -> TCPNum:
if self.dtype == 'float':
return cast(TCPNum, add_op('sub', [value(0.0, volatile=False), self]))