Skip to content

Commit

Permalink
fix inplace division for python3 (pytorch#2063)
Browse files Browse the repository at this point in the history
  • Loading branch information
albanD authored and soumith committed Jul 12, 2017
1 parent 0d91048 commit a74fb22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,13 @@ def test_big_transpose(self):
t2 = torch.from_numpy(t.numpy().transpose())
self.assertEqual(t1, t2)

def test_inplace_division(self):
t = torch.rand(5, 5)
id_before = id(t)
t /= 2
id_after = id(t)
self.assertEqual(id_before, id_after)

# Functions to test negative dimension wrapping
METHOD = 1
INPLACE_METHOD = 2
Expand Down
1 change: 1 addition & 0 deletions torch/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def __rdiv__(self, other):

def __idiv__(self, other):
return self.div_(other)
__itruediv__ = __idiv__

def __mod__(self, other):
return self.remainder(other)
Expand Down

0 comments on commit a74fb22

Please sign in to comment.