<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import torch

torch.autograd.Variable(torch.LongTensor([18])) / 0.0625
# Floating point exception (core dumped)

torch.LongTensor([18]) / 0.0625
#Traceback (most recent call last):
#  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
#  File &quot;.../lib/python2.7/site-packages/torch/tensor.py&quot;, line 294, in __div__
#    return self.div(other)
#TypeError: div received an invalid combination of arguments - got (float), but expected one of:
# * (int value)
#      didn't match because some of the arguments have invalid types: (float)
# * (torch.LongTensor other)
#      didn't match because some of the arguments have invalid types: (float)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">torch</span>

<span class="pl-s1">torch</span>.<span class="pl-s1">autograd</span>.<span class="pl-v">Variable</span>(<span class="pl-s1">torch</span>.<span class="pl-v">LongTensor</span>([<span class="pl-c1">18</span>])) <span class="pl-c1">/</span> <span class="pl-c1">0.0625</span>
<span class="pl-c"># Floating point exception (core dumped)</span>

<span class="pl-s1">torch</span>.<span class="pl-v">LongTensor</span>([<span class="pl-c1">18</span>]) <span class="pl-c1">/</span> <span class="pl-c1">0.0625</span>
<span class="pl-c">#Traceback (most recent call last):</span>
<span class="pl-c">#  File "&lt;stdin&gt;", line 1, in &lt;module&gt;</span>
<span class="pl-c">#  File ".../lib/python2.7/site-packages/torch/tensor.py", line 294, in __div__</span>
<span class="pl-c">#    return self.div(other)</span>
<span class="pl-c">#TypeError: div received an invalid combination of arguments - got (float), but expected one of:</span>
<span class="pl-c"># * (int value)</span>
<span class="pl-c">#      didn't match because some of the arguments have invalid types: (float)</span>
<span class="pl-c"># * (torch.LongTensor other)</span>
<span class="pl-c">#      didn't match because some of the arguments have invalid types: (float)</span></pre></div>
<p dir="auto">at <code class="notranslate">0.4.0a0+b608ea9</code>;  related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="196296717" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/327" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/327/hovercard" href="https://github.com/pytorch/pytorch/issues/327">#327</a> and maybe <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="300316501" data-permission-text="Title is private" data-url="https://github.com/pytorch/pytorch/issues/5411" data-hovercard-type="issue" data-hovercard-url="/pytorch/pytorch/issues/5411/hovercard" href="https://github.com/pytorch/pytorch/issues/5411">#5411</a></p>
<p dir="auto">Probably the cause is that in the variable case, it casts the divisor as Long and it triggers integer division by zero. But why only in the variable case?</p>
<p dir="auto">Didn't test it after the tensor+variable merge, since don't want to migrate to vNext before ECCV deadline :)</p>
<p dir="auto">Example below. We should probably return a floating tensor like numpy does.</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; a + 0.5

 1
 2
 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; a + 0.5

 1
 2
 3
[torch.LongTensor of size (3,)]
</code></pre></div>