Return the top n (default 10) highest entities by Karmic value.
	Use negative numbers for the bottom N.
4170
def top10(rest):
	
	if rest:
		topn = int(rest)
	else:
		topn = 10
	selection = Karma.store.list(topn)
	res = ' '.join('(%s: %s)' % (', '.join(n), k) for n, k in selection)
	return res
311498
def getTauLeibniz(n):
    
    myTau = tauGenLeibniz()
    result = []
    if n > 0:
        result += [next(myTau) for i in range(n)]
    myTau.close()
    return result
1318269
def top_k_logits(logits, k):
    
    if k == 0:
        return logits
    else:
        values = torch.topk(logits, k)[0]
        batch_mins = values[:, -1].view(-1, 1).expand_as(logits)
        return torch.where(logits < batch_mins, torch.ones_like(logits) * -1e10, logits)
1142082
def toPandas(self):
        
        assert pd is not None
        nindices = self.getNumIndices()
        headers = self.getHeaders()
        columns = {
            header: list(self.getColumn(header))
            for header in headers[nindices:]
        }
        index = zip(*[
            list(self.getColumn(header))
            for header in headers[:nindices]
        ])
        index = [key if len(key) > 1 else key[0] for key in index]
        if index == []:
            return pd.DataFrame(columns, index=None)
        else:
            return pd.DataFrame(columns, index=index)
966992
private int binaryGreaterSearch() {

        int low     = 0;
        int high    = count;
        int mid     = 0;
        int compare = 0;

        while (low < high) {
            mid     = (low + high) / 2;
            compare = compare(mid);

            if (compare < 0) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        return low == count ? -1
                            : low;
    }
517737
def remove_by_rank(self, low, high=None):
        
        if high is None:
            high = low
        return self.database.zremrangebyrank(self.key, low, high)
728147
public static double[] toPreds(double in[], float[] out, double[] preds,
                          int nclasses, double[] priorClassDistrib, double defaultThreshold) {
    if (nclasses > 2) {
      for (int i = 0; i < out.length; ++i)
        preds[1 + i] = out[i];
      preds[0] = GenModel.getPrediction(preds, priorClassDistrib, in, defaultThreshold);
    } else if (nclasses==2){
      preds[1] = 1f - out[0];
      preds[2] = out[0];
      preds[0] = GenModel.getPrediction(preds, priorClassDistrib, in, defaultThreshold);
    } else {
      preds[0] = out[0];
    }
    return preds;
  }
537756
def natural_sort(item):
    
    if item is None:
        return 0

    def try_int(s):
        try:
            return int(s)
        except ValueError:
            return s
    return tuple(map(try_int, re.findall(r'(\d+|\D+)', item)))
434231
def top_level(self):
        
        top = list(self.cell_dict.values())
        for cell in self.cell_dict.values():
            for dependency in cell.get_dependencies():
                if dependency in top:
                    top.remove(dependency)
        return top
564378
def top_losses(self, k:int=None, largest=True):
        ""
        return self.losses.topk(ifnone(k, len(self.losses)), largest=largest)
966812
private double[] findMinMax(double[] lows, double[] highs) {

    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;

    for (int i = 0; i < highs.length; i++) {

      if (!Double.isNaN(highs[i]) && highs[i] > max) {
        max = highs[i];
      }
      if (!Double.isNaN(lows[i]) && lows[i] < min) {
        min = lows[i];
      }
    }

    return new double[] {min, max};
  }
346292
def _mm_rankings(n_items, data, params):
    """"""
    weights = exp_transform(params)
    wins = np.zeros(n_items, dtype=float)
    denoms = np.zeros(n_items, dtype=float)
    for ranking in data:
        sum_ = weights.take(ranking).sum()
        for i, winner in enumerate(ranking[:-1]):
            wins[winner] += 1
            val = 1.0 / sum_
            for item in ranking[i:]:
                denoms[item] += val
            sum_ -= weights[winner]
    return wins, denoms
203680
def rank(self, value):
        """"""
        i = 0
        n = len(self._tree)
        rank = 0
        count = 0
        while i < n:
            cur = self._tree[i]
            if value < cur:
                i = 2 * i + 1
                continue
            elif value > cur:
                rank += self._counts[i]
                # subtract off the right tree if exists
                nexti = 2 * i + 2
                if nexti < n:
                    rank -= self._counts[nexti]
                    i = nexti
                    continue
                else:
                    return (rank, count)
            else:  # value == cur
                count = self._counts[i]
                lefti = 2 * i + 1
                if lefti < n:
                    nleft = self._counts[lefti]
                    count -= nleft
                    rank += nleft
                    righti = lefti + 1
                    if righti < n:
                        count -= self._counts[righti]
                return (rank, count)
        return (rank, count)
64078
def most_common(self, n=None):
        '''

        '''
        # Emulate Bag.sortedByCount from Smalltalk
        if n is None:
            return sorted(self.items(), key=_itemgetter(1), reverse=True)
        return _heapq.nlargest(n, self.items(), key=_itemgetter(1))
1242359
def _highest_perm_from_iter(self, perm_iter):
        """"""
        perm_set = set(perm_iter)
        for perm_str in reversed(ORDERED_PERM_LIST):
            if perm_str in perm_set:
                return perm_str
193482
def max_order(self):
        
        # TODO: cache value
        combo = int(0)
        for iv in self._interval_set._intervals:
            combo |= iv[0] | iv[1]

        ret = AbstractMOC.HPY_MAX_NORDER - (utils.number_trailing_zeros(combo) // 2)
        if ret < 0:
            ret = 0

        return ret
254864
def get_highest_numeric_score(self):
        
        if self.is_based_on_grades():
            raise errors.IllegalState('This GradeSystem is based on grades')
        if self._my_map['highestNumericScore'] is None:
            return None
        else:
            return Decimal(str(self._my_map['highestNumericScore']))