The function scatter can't operate on arange data

akari0216: <p>Hello i’m a beginner of pytorch,today i appeared a problem while learning the tutorial.I tested the code on jupyter notebook,but it break the error like this:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/6/86fbd19cc2fd93961651a6a135c7ff835d3af0ad.png" data-download-href="https://discuss.pytorch.org/uploads/default/86fbd19cc2fd93961651a6a135c7ff835d3af0ad" title="1599727491(1)"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/6/86fbd19cc2fd93961651a6a135c7ff835d3af0ad_2_690x362.png" alt="1599727491(1)" data-base62-sha1="jg7v1fYqhTIjQfYQBFfqRowSO5v" width="690" height="362" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/6/86fbd19cc2fd93961651a6a135c7ff835d3af0ad_2_690x362.png, https://discuss.pytorch.org/uploads/default/optimized/3X/8/6/86fbd19cc2fd93961651a6a135c7ff835d3af0ad_2_1035x543.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/8/6/86fbd19cc2fd93961651a6a135c7ff835d3af0ad_2_1380x724.png 2x" data-dominant-color="F8F9F9"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">1599727491(1)</span><span class="informations">1746×918 75.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
However,if i changed the type of the variable ‘a’,it works.<br>
Obviously it’s the problem about the dtype of the variable ‘a’,but i really don’t know how to fix this.The version of torch is 1.6(cpu++).<br>
Thanks for reading and replying my problem.</p>

ptrblck: <aside class="quote no-group" data-username="akari0216" data-post="1" data-topic="95769">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/6f9a4e/48.png" class="avatar"> akari0216:</div>
<blockquote>
<p>but i really don’t know how to fix this</p>
</blockquote>
</aside>
<p>I’m a bit confused as it seems you’ve already fixed it by changing the type of one variable?</p>
<aside class="quote no-group" data-username="akari0216" data-post="1" data-topic="95769">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/6f9a4e/48.png" class="avatar"> akari0216:</div>
<blockquote>
<p>However,if i changed the type of the variable ‘a’,it works.</p>
</blockquote>
</aside>

akari0216: <p>not yet,i mean that the variable ‘a’(exactly is a tensor) generate by the function ‘arange’, cannot work on the function ‘scatter’(or ‘scatter_’)</p>

kshitij: <p>The issue is that the output of <code>torch.arange</code> has dtype <code>torch.int64</code>, while <code>torch.randn</code> and <code>torch.zeros</code> give output of dtype <code>torch.float32</code> thus the scatter works.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/a/4ac124c0a111007bece59db9c3591bb2c3ea8489.png" data-download-href="https://discuss.pytorch.org/uploads/default/4ac124c0a111007bece59db9c3591bb2c3ea8489" title="Screenshot from 2020-09-12 20-37-01"><img src="https://discuss.pytorch.org/uploads/default/original/3X/4/a/4ac124c0a111007bece59db9c3591bb2c3ea8489.png" alt="Screenshot from 2020-09-12 20-37-01" data-base62-sha1="aFj8JYa8xuOgciXFDOtxBkUsWfv" width="690" height="189" data-dominant-color="515557"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2020-09-12 20-37-01</span><span class="informations">733×201 26.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

akari0216: <p>Gratefully thanks!After your hint,it really proves that the function scatter,needs every parameter as the same dtype.So just let the variable ‘a’ turns to the dtype torch.float32,exactly just add .float() at the end,and the code works.</p>