mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
update idiv doc and test cases (#8398)
test more cases when either numerator and denominator is negative and has remainder or not
This commit is contained in:
parent
a647f3dd2c
commit
de3705168e
3 changed files with 5 additions and 4 deletions
|
|
@ -537,7 +537,8 @@ class TestOps(unittest.TestCase):
|
|||
helper_test_op(None, lambda x,y: x//y, forward_only=True, vals=[[5, 6, 7],[1, 2, 3]])
|
||||
helper_test_op(None, lambda x: x/2, forward_only=True, vals=[[3, 4, 5]])
|
||||
helper_test_op(None, lambda x: x//2, forward_only=True, vals=[[3, 4, 5]])
|
||||
helper_test_op(None, functools.partial(torch.div, rounding_mode="trunc"), Tensor.idiv, forward_only=True, vals=[[5, -6, 7],[1, 2, 3]])
|
||||
helper_test_op(None, functools.partial(torch.div, rounding_mode="trunc"), Tensor.idiv, forward_only=True,
|
||||
vals=[[-4, 7, 5, 4, -7, 8], [2, -3, 8, -2, 3, 5]])
|
||||
if is_dtype_supported(dtypes.uint64):
|
||||
x = Tensor(2**64 - 1, dtype=dtypes.uint64).idiv(1)
|
||||
np.testing.assert_equal(x.numpy(), 2**64 - 1)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class SimpleMathTrait:
|
|||
def __sub__(self, x): return self.sub(x)
|
||||
def __mul__(self, x): return self.mul(x)
|
||||
def __truediv__(self, x): return self.div(x)
|
||||
def __floordiv__(self, x): return self.idiv(x)
|
||||
def __floordiv__(self, x): return self.idiv(x) # TODO: idiv is trunc div, not floordiv
|
||||
def __and__(self, x): return self.bitwise_and(x)
|
||||
def __or__(self, x): return self.bitwise_or(x)
|
||||
def __xor__(self, x): return self.xor(x)
|
||||
|
|
|
|||
|
|
@ -3100,10 +3100,10 @@ class Tensor(SimpleMathTrait):
|
|||
Divides `self` by `x`.
|
||||
Equivalent to `self // x`.
|
||||
Supports broadcasting to a common shape, type promotion, and integer inputs.
|
||||
`idiv` performs integer division.
|
||||
`idiv` performs integer division (truncate towards zero).
|
||||
|
||||
```python exec="true" source="above" session="tensor" result="python"
|
||||
print(Tensor([1, 4, 10]).idiv(Tensor([2, 3, 4])).numpy())
|
||||
print(Tensor([-4, 7, 5, 4, -7, 8]).idiv(Tensor([2, -3, 8, -2, 3, 5])).numpy())
|
||||
```
|
||||
"""
|
||||
return F.IDiv.apply(*self._broadcasted(x, reverse))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue