-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Labels
high prioritymodule: correctness (silent)issue that returns an incorrect result silentlyissue that returns an incorrect result silentlymodule: deprecationtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Description
🐛 Bug
PyTorch's floor_divide (//) operator doesn't match Python's behavior on negative numbers. Python floors (rounds down) while PyTorch truncates (rounds towards zero).
To Reproduce
Steps to reproduce the behavior:
import torch
import numpy as np
print("python -3//2 =", -3 // 2)
print("numpy -3//2 =", np.array((-3)) // 2)
print("pytorch -3//2 =", torch.tensor([-3]) // 2)
# output:
# python -3//2 = -2
# numpy -3//2 = -2
# pytorch -3//2 = tensor([-1])Expected behavior
Expect PyTorch's floor_divide to match Python // operator by flooring division results instead of truncating them.
Environment
- PyTorch Version (e.g., 1.0): master
- OS (e.g., Linux): Linux
- How you installed PyTorch (`conda`, `pip`, source): source
- Build command you used (if compiling from source):
- Python version: Python 3.7.5
- CUDA/cuDNN version: n/a
- GPU models and configuration: n/a
- Any other relevant information:
Metadata
Metadata
Assignees
Labels
high prioritymodule: correctness (silent)issue that returns an incorrect result silentlyissue that returns an incorrect result silentlymodule: deprecationtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module