<p dir="auto">Example below. While we don't support ops between different dtype tensors, we should consider changing this behavior. In numpy, this would return a floating tensor.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import torch
&gt;&gt;&gt; a = torch.tensor([1,2,3], dtype=torch.long)
&gt;&gt;&gt; b = torch.tensor([3,2,1], dtype=torch.long)
&gt;&gt;&gt; a/b

 0
 1
 3
[torch.LongTensor of size (3,)]"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import torch
&gt;&gt;&gt; a = torch.tensor([1,2,3], dtype=torch.long)
&gt;&gt;&gt; b = torch.tensor([3,2,1], dtype=torch.long)
&gt;&gt;&gt; a/b

 0
 1
 3
[torch.LongTensor of size (3,)]
</code></pre></div>
<ul dir="auto">
<li>PyTorch version: current master (10fd27)</li>
<li>How you installed PyTorch (conda, pip, source): from source</li>
<li>Python version: 3.6</li>
</ul>
<p dir="auto">When dividing two ints in pure Python, the result is always a float, e.g.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; x = 5 / 3
&gt;&gt;&gt; print(x)
1.6666666666666667
&gt;&gt;&gt; print(type(x))
&lt;class 'float'&gt;"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; x = 5 / 3
&gt;&gt;&gt; print(x)
1.6666666666666667
&gt;&gt;&gt; print(type(x))
&lt;class 'float'&gt;
</code></pre></div>
<p dir="auto">NumPy shares this behavior:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; x = np.array([5], dtype=np.int64) / np.array([3], dtype=np.int64)
&gt;&gt;&gt; print(x)
[1.66666667]
&gt;&gt;&gt; print(x.dtype)
float64"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; x = np.array([5], dtype=np.int64) / np.array([3], dtype=np.int64)
&gt;&gt;&gt; print(x)
[1.66666667]
&gt;&gt;&gt; print(x.dtype)
float64
</code></pre></div>
<p dir="auto">PyTorch uses floor division if both operands have integer types:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; from torch import LongTensor
&gt;&gt;&gt; x = torch.LongTensor([5]) / torch.LongTensor([3])
&gt;&gt;&gt; print(x)

1
[torch.LongTensor of size (1,)]
&gt;&gt;&gt; print(x.type())
torch.LongTensor"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; from torch import LongTensor
&gt;&gt;&gt; x = torch.LongTensor([5]) / torch.LongTensor([3])
&gt;&gt;&gt; print(x)

1
[torch.LongTensor of size (1,)]
&gt;&gt;&gt; print(x.type())
torch.LongTensor
</code></pre></div>
<p dir="auto">I find it confusing that PyTorch uses different division semantics than NumPy and Python. It is a potential source of bugs for users coming from a NumPy background and for users who want to port their code from NumPy to PyTorch.</p>
<p dir="auto">For floor division that keeps the integer type, Python already has the dedicated <code class="notranslate">//</code> operator (which is also understood by NumPy). I would propose that PyTorch changes its handling of division so that the <code class="notranslate">/</code> operator always performs true division and introduces the <code class="notranslate">//</code> operator that explicitly means floor division.</p>
<p dir="auto">I see two potential problems with changing PyTorch's division behavior like this:</p>
<ul dir="auto">
<li>This is quite a fundamental change that can break exisiting code.</li>
<li>There is still the open question on how to behave on Python 2 with/without <code class="notranslate">from __future__ import division</code>. NumPy also respects this future import, so depending on the future imports, Python 2 code can either cause the old floor-division behavior (where dividing two <code class="notranslate">np.*int*</code> types results in a floor division) or the new one (always perform true division). I don't know how hard it would be to mimic this behavior and if it's worth the effort.</li>
</ul>
<p dir="auto">Despite these problems, I still believe this change is important in the long run. What do you think?</p>