Skip to content

Conversation

@apaszke
Copy link
Contributor

@apaszke apaszke commented May 3, 2018

This commit adds support for __floordiv__ to all tensors. I checked that it behaves similarly to what NumPy does, i.e. always returns a result of the same type. On the other hand, NumPy seems to follow the Python rules for rounding, while I used the C rules, to make it conform with how our integral division behaves in general.

This also adds support for __rdiv__ with integral tensors. Previously it raised an error saying that reciprocal isn't implemented for them. Ideally we would just have a kernel for this, but I didn't want to make this patch too large, as it's mostly meant to unblock my other work.

if self.dtype.is_floating_point:
return self.reciprocal() * other
else:
return (self.double().reciprocal() * other).type_as(self)

This comment was marked as off-topic.

This comment was marked as off-topic.

@apaszke apaszke merged commit 8091388 into master May 3, 2018
@apaszke apaszke deleted the floordiv branch May 3, 2018 21:35
Jorghi12 pushed a commit to wsttiger/pytorch that referenced this pull request May 10, 2018
weiyangfb pushed a commit to weiyangfb/pytorch that referenced this pull request Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants