MCPcopy
hub / github.com/tinygrad/tinygrad / abs

Method abs

tinygrad/mixin/elementwise.py:887–895  ·  view source on GitHub ↗

Computes the absolute value of the tensor element-wise. ```python exec="true" source="above" session="tensor" result="python" print(Tensor([-3., -2., -1., 0., 1., 2., 3.]).abs().numpy()) ```

(self)

Source from the content-addressed store, hash-verified

885 return self.ne(0).where((self < 0).where(self.const_like(-1), self.const_like(1)), self.const_like(0))
886
887 def abs(self) -> Self:
888 """
889 Computes the absolute value of the tensor element-wise.
890
891 ```python exec="true" source="above" session="tensor" result="python"
892 print(Tensor([-3., -2., -1., 0., 1., 2., 3.]).abs().numpy())
893 ```
894 """
895 return self * self.sign()
896
897 def tan(self) -> Self:
898 """

Callers 15

asinMethod · 0.95
erfMethod · 0.95
softsignMethod · 0.95
ReduceL1Function · 0.80
LpNormalizationFunction · 0.80
normalizeMethod · 0.80
one_round_jacobiMethod · 0.80
copysignMethod · 0.80
iscloseMethod · 0.80
intersectRectFunction · 0.80
setFocusFunction · 0.80
btFunction · 0.80

Calls 1

signMethod · 0.95

Tested by 9

test_matmulFunction · 0.64
_test_castFunction · 0.64
test_abs_diffMethod · 0.64
test_fuzz_allreduceMethod · 0.64
test_apply_ropeMethod · 0.64
_softplus_npMethod · 0.64
_assert_closeMethod · 0.64
test_forward_matchMethod · 0.64