Returns the indexes in descending order of the top k score
        or all scores if k is None
498380
def _argsort(y_score, k=None):
    
    ranks = y_score.argsort()
    argsort = ranks[::-1]
    if k is not None:
        argsort = argsort[0:k]

    return argsort
117281
def compute_rewards(self, scores):
        """"""
        for i in range(len(scores)):
            if i >= self.k:
                scores[i] = 0.
        return scores
857124
def get_top_n_meanings(strings, n):
    
    scored_strings = [(s, score_meaning(s)) for s in strings]
    scored_strings.sort(key=lambda tup: -tup[1])
    return scored_strings[:n]
380058
def min_max_indexes(seq):
    
    l = sorted(enumerate(seq), key=lambda s: s[1])
    return l[0][0], l[-1][0]
1225118
def _get_best_indexes(logits, n_best_size):
    """"""
    index_and_score = sorted(enumerate(logits), key=lambda x: x[1], reverse=True)

    best_indexes = []
    for i in range(len(index_and_score)):
        if i >= n_best_size:
            break
        best_indexes.append(index_and_score[i][0])
    return best_indexes
382914
def most_common(self, n=None):
        '''

        '''
        if n is None:
            return sorted(iteritems(self), key=itemgetter(1), reverse=True)
        return nlargest(n, iteritems(self), key=itemgetter(1))
1051205
def argsort_k_smallest(x, k):
    
    if k == 0:
        return np.array([], dtype=np.intp)
    if k is None or k >= len(x):
        return np.argsort(x)
    indices = np.argpartition(x, k)[:k]
    values = x[indices]
    return indices[np.argsort(values)]
617795
async def get_final_ranking(self) -> OrderedDict:
        
        if self._state != TournamentState.complete.value:
            return None

        ranking = {}
        for p in self.participants:
            if p.final_rank in ranking:
                ranking[p.final_rank].append(p)
            else:
                ranking[p.final_rank] = [p]

        return OrderedDict(sorted(ranking.items(), key=lambda t: t[0]))
30438
def _argtop(y_score, k=None):
    
    # avoid sorting when just want the top all
    if k is None:
        return slice(0, len(y_score))
    else:
        return _argsort(y_score, k)
1261359
def ranks(self) -> List[str]:
        """"""
        return list(OrderedDict.fromkeys((m.rank for m in self.members)))
426761
function findAllIndices() {
  var needle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mandatory();
  var haystack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mandatory();

  var indices = [];
  for (var i = 0; i < haystack.length; i++) {
    if (haystack.substr(i, needle.length) === needle) {
      indices.push(i);
    }
  }

  if (indices.length) {
    return indices;
  } else {
    return -1;
  }
}
972232
def _get_entry_scores(self):
        """"""
        if self.get_gradebook_column().get_grade_system().is_based_on_grades():
            return [e.get_grade().get_output_score() for e in self._entries if e.is_graded()]
        else:
            return [e.get_score() for e in self._entries if e.is_graded()]
212699
def sort_idx(m, reverse=False):
    """"""
    return sorted(range(len(m)), key=lambda k: m[k], reverse=reverse)
1342428
def get_indexes_from_base(self):
        
        if self.is_indexed:
            return np.copy(self.order[i])
        if self.data.base is None:
            i = 0
        else:
            i = self.get_raw_index(0)
        return np.arange(i, i + len(self), dtype=np.uint32)
305025
def ranker(self, X, meta):
        
        # total score is just a sum of each row
        total_score = X.sum(axis=1).transpose()
        total_score = np.squeeze(np.asarray(total_score))  # matrix to array
        ranks = total_score.argsort()
        ranks = ranks[::-1]
        # sort the list of dicts according to ranks
        sorted_meta = [meta[r] for r in ranks]
        sorted_X = X[ranks]
        return (sorted_X, sorted_meta)
95471
def kth_smallest(self, root, k):
        
        count = []
        self.helper(root, count)
        return count[k-1]
839936
def sort_index(self):
        
        sort = sorted_list_indexes(self._index)
        # sort index
        self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
        # each column
        for c in range(len(self._data)):
            self._data[c] = blist([self._data[c][i] for i in sort]) if self._blist else [self._data[c][i] for i in sort]