A question about " Tensor.sort() "

fan_zhimin: <p>I know the basic usage of sort, but now I have a question.</p>
<p>First, I got a tensor like this:<br>
a = torch.tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,<br>
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,<br>
1, 1, 1, 1, 1, 1, 1, 1, 1])</p>
<h1>torch.Size([57]), It is a one-dimensional tensor</h1>
<p>Then, The code operates as follows:<br>
a,idx = a.sort(0,True)</p>
<p>I got the following results<br>
a = tensor([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,<br>
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,<br>
1, 1, 1, 1, 1, 1, 1, 1, 1])<br>
idx = tensor([36, 35, 40, 39, 38, 37, 42, 44, 34, 33, 32, 31, 41, 29, 43, 51, 50, 55,<br>
54, 53, 52, 28, 45, 49, 48, 47, 46, 30,  0,  7,  6, 11, 10,  9,  8, 13,<br>
15,  5,  4,  3,  2, 12,  1, 14, 22, 21, 26, 25, 24, 23, 27, 16, 20, 19,<br>
18, 17, 56])</p>
<p>IDX is my question,  Variable a is a tensor with all 1, But given the meaning of IDX, the variable a is sorted. Why?  Thank you very much for your explanation ! ~</p>

InnovArul: <p>As of now, stable sort is not available in pytorch.<br>
</p><aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/pytorch/issues/28871" target="_blank" rel="noopener">github.com/pytorch/pytorch</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/pytorch/issues/28871" target="_blank" rel="noopener">Request to add stable sorting algorithm to PyTorch</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2019-10-30" data-time="11:49:10" data-timezone="UTC">11:49AM - 30 Oct 19 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/seva100" target="_blank" rel="noopener">
          <img alt="seva100" src="https://avatars1.githubusercontent.com/u/5861398?v=4" class="onebox-avatar-inline" width="20" height="20">
          seva100
        </a>
      </div>
    </div>
  </div>
</div>

<div class="github-row">
  <p class="github-content">🚀 Feature
My feature request is to add the algorithm of stable sorting to PyTorch. Stable sorting is a method of sorting...</p>
</div>

<div class="labels">
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">OSS contribution wanted</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">function request</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: numpy</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: sorting and selection</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">triaged</span>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>Try to use <code>numpy.sort()</code> if you require stable sort.<br>
</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <a href="https://numpy.org/doc/stable/reference/generated/numpy.sort.html" target="_blank" rel="noopener">numpy.org</a>
  </header>
  <article class="onebox-body">
    <img src="" class="thumbnail" width="20" height="20">

<h3><a href="https://numpy.org/doc/stable/reference/generated/numpy.sort.html" target="_blank" rel="noopener">numpy.sort — NumPy v1.19 Manual</a></h3>



  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


fan_zhimin: <p>okay, ~ This problem takes me a lot of time,  I’m dealing with some NLP tasks. This method causes an exception in my sequence, but I can’t find the reason. Thank you very much~</p>
<p>~~</p>
<p>In addition to the second floor engineer’s reply, what other people’s reference opinions can I learn from?</p>