IndexError: tensors used as indices must be long, byte or bool tensors

username: _joker
cooked: <p>I am getting this error only during the testing phase, but I do not face any problem in the training and validation phase.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/5/15d00567ff9f7c867cb66a6ae631b90db478ff37.png" data-download-href="https://discuss.pytorch.org/uploads/default/15d00567ff9f7c867cb66a6ae631b90db478ff37" title="Screen Shot 2020-03-25 at 7.50.29 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/15d00567ff9f7c867cb66a6ae631b90db478ff37_2_690x110.png" alt="Screen Shot 2020-03-25 at 7.50.29 PM" data-base62-sha1="36XI1vsGVr7MG3MzJf8KqO68aDZ" width="690" height="110" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/15d00567ff9f7c867cb66a6ae631b90db478ff37_2_690x110.png, https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/15d00567ff9f7c867cb66a6ae631b90db478ff37_2_1035x165.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/1/5/15d00567ff9f7c867cb66a6ae631b90db478ff37_2_1380x220.png 2x" data-dominant-color="404040"><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">Screen Shot 2020-03-25 at 7.50.29 PM</span><span class="informations">1818×292 45.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></p>
<p>The code snippet looks like the one below,</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/3/43624326033dcd720235552b2a63e5016b044f82.png" data-download-href="https://discuss.pytorch.org/uploads/default/43624326033dcd720235552b2a63e5016b044f82" title="GI6p9"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/3/43624326033dcd720235552b2a63e5016b044f82_2_690x164.png" alt="GI6p9" data-base62-sha1="9C6w1wckusLGIMdQr03HBlcxaam" width="690" height="164" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/3/43624326033dcd720235552b2a63e5016b044f82_2_690x164.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/3/43624326033dcd720235552b2a63e5016b044f82_2_1035x246.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/3/43624326033dcd720235552b2a63e5016b044f82_2_1380x328.png 2x" data-dominant-color="353530"><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">GI6p9</span><span class="informations">1560×372 54.7 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>
<p>The “lab” is a tensor value and prints out the range in such a way,</p>
<pre><code class="lang-auto">tensor([6, 7, 8])
tensor([ 9, 10, 11])
tensor([21, 22, 23])
</code></pre>
<p>(Note*: the length of this lab tensor can be of length ‘n’ based on the value of ElementsPerClass)</p>

username: ptrblck
cooked: <p>Could you check, if <code>lab</code> is an empty tensor at one point?<br>
This would yield the same error message and since it’s calculated by <code>torch.arange</code> this might happen, if <code>start</code> and <code>end</code> have equal values.</p>

username: _joker
cooked: <p>I am testing for <strong>NumRows = 10</strong> that is, <strong>ElementsPerClass = 1</strong><br>
This gives <strong>lab</strong> as single value tensors on every iteration like,</p>
<pre><code class="lang-auto">tensor([1])
tensor([4])
tensor([7])
</code></pre>
<p>as I want a single tile of masking for <strong>self.mem_dim = 10</strong></p>