Returns a dictionary that associates each position in the ranking with a list of integer 
        representations of the candidates ranked at that position.
962496
def getReverseRankMap(self):
        
        
        # We sort the candidates based on the number of incoming edges they have in the graph. If 
        # two candidates have the same number, we assume that they are tied.
        incEdgesMap = self.getIncEdgesMap()
        sortedKeys = sorted(incEdgesMap.keys(), reverse = True)
        reverseRankMap = dict()
        pos = 1
        for key in sortedKeys:
            cands = incEdgesMap[key]
            reverseRankMap[pos] = cands
            pos += 1
        return reverseRankMap
270164
def _build_mat(self, ranks, n_candidates, prefcounts):
        

        mat = zeros((n_candidates, n_candidates))
        for i, j in itertools.combinations(range(n_candidates), 2):
            preference = ranks[:, i] - ranks[:, j]
            h_ij = dot((preference < 0), prefcounts)  # prefers i to j
            h_ji = dot((preference > 0), prefcounts)  # prefers j to i
            mat[i, j] = h_ij - h_ji
            mat[j, i] = h_ji - h_ij
        return mat
1110515
def _advanced_indexer_subspaces(key):
    
    if not isinstance(key, tuple):
        key = (key,)
    advanced_index_positions = [i for i, k in enumerate(key)
                                if not isinstance(k, slice)]

    if (not advanced_index_positions or
            not _is_contiguous(advanced_index_positions)):
        # Nothing to reorder: dimensions on the indexing result are already
        # ordered like vindex. See NumPy's rule for "Combining advanced and
        # basic indexing":
        # https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing
        return (), ()

    non_slices = [k for k in key if not isinstance(k, slice)]
    ndim = len(np.broadcast(*non_slices).shape)
    mixed_positions = advanced_index_positions[0] + np.arange(ndim)
    vindex_positions = np.arange(ndim)
    return mixed_positions, vindex_positions
213899
def ranks(self, key, value):
    """"""
    return [normalize_rank(el) for el in force_list(value.get('a'))]
672801
def _candidates_from_grid(self, n=1000):
        """"""
        used_vectors = set(tuple(v) for v in self.X)

        # if every point has been used before, gridding is done.
        grid_size = self.grid_width ** len(self.tunables)
        if len(used_vectors) == grid_size:
            return None

        all_vectors = set(itertools.product(*self._grid_axes))
        remaining_vectors = all_vectors - used_vectors
        candidates = np.array(list(map(np.array, remaining_vectors)))

        np.random.shuffle(candidates)
        return candidates[0:n]
1210374
def p_integernamelist(self, p):
        ''
        p[0] = p[1] + (p[3],)
        p.set_lineno(0, p.lineno(1))
602274
def ranked_attributes(self):
        
        matrix = javabridge.call(self.jobject, "rankedAttributes", "()[[D")
        if matrix is None:
            return None
        else:
            return typeconv.double_matrix_to_ndarray(matrix)
855478
def getCandScoresMap(self, profile):
        

        # Currently, we expect the profile to contain complete ordering over candidates. Ties are
        # allowed however.
        elecType = profile.getElecType()
        if elecType != "soc" and elecType != "toc":
            print("ERROR: unsupported election type")
            exit()

        # Initialize each Copeland score as 0.0.
        copelandScores = dict()
        for cand in profile.candMap.keys():
            copelandScores[cand] = 0.0

        preferenceCounts = profile.getPreferenceCounts()

        # For each pair of candidates, calculate the number of votes in which one beat the other.
        wmgMap = profile.getWmg()
        for cand1, cand2 in itertools.combinations(wmgMap.keys(), 2):
            if cand2 in wmgMap[cand1].keys():
                if wmgMap[cand1][cand2] > 0:
                    copelandScores[cand1] += 1.0
                elif wmgMap[cand1][cand2] < 0:
                    copelandScores[cand2] += 1.0

                # If a pair of candidates is tied, we add alpha to their score for each vote.
                else:
                    copelandScores[cand1] += self.alpha
                    copelandScores[cand2] += self.alpha

        return copelandScores
648727
public int getIndexForPosition(int position) {
        int nSections = 0;

        Set<Entry<String, Integer>> entrySet = mSections.entrySet();
        for(Entry<String, Integer> entry : entrySet) {
            if(entry.getValue() < position) {
                nSections++;
            }
        }

        return position - nSections;
    }
143513
private int[] buildIndex(final int[] counts, int[] positions, int minsupp) {
    // Count the number of frequent items:
    int numfreq = 0;
    for(int i = 0; i < counts.length; i++) {
      if(counts[i] >= minsupp) {
        ++numfreq;
      }
    }
    // Build the index table
    int[] idx = new int[numfreq];
    for(int i = 0, j = 0; i < counts.length; i++) {
      if(counts[i] >= minsupp) {
        idx[j++] = i;
      }
    }
    IntegerArrayQuickSort.sort(idx, (x, y) -> Integer.compare(counts[y], counts[x]));
    Arrays.fill(positions, -1);
    for(int i = 0; i < idx.length; i++) {
      positions[idx[i]] = i;
    }
    return idx;
  }
1335420
def getTopologicalOrderingOfJobs(self):
        
        ordering = []
        visited = set()
        def getRunOrder(job):
            #Do not add the job to the ordering until all its predecessors have been
            #added to the ordering
            for p in job._directPredecessors:
                if p not in visited:
                    return
            if job not in visited:
                visited.add(job)
                ordering.append(job)
                list(map(getRunOrder, job._children + job._followOns))
        getRunOrder(self)
        return ordering
80084
def keys(self):
        
        keys = []
        for key, value in self._values.items():
            if isinstance(value, (FlatDict, dict)):
                nested = [self._delimiter.join([key, k]) for k in value.keys()]
                keys += nested if nested else [key]
            else:
                keys.append(key)
        return sorted(keys)
1029276
def suggestion_list(inp, options):
    
    options_by_distance = OrderedDict()
    input_threshold = len(inp) / 2

    for option in options:
        distance = lexical_distance(inp, option)
        threshold = max(input_threshold, len(option) / 2, 1)
        if distance <= threshold:
            options_by_distance[option] = distance

    return sorted(
        list(options_by_distance.keys()), key=lambda k: options_by_distance[k]
    )
1121149
def PositionalEncoding(x, params, **unused_kwargs):
  """"""
  if not isinstance(x, (list, tuple)):  # non-chunked inputs
    symbol_size = np.shape(x)[1]
    return x + params[:, :symbol_size, :]
  # Chunked case: apply to all chunks selecting as much as needed.
  offset = 0
  results = []
  for chunk in x:
    symbol_size = np.shape(chunk)[1]
    results.append(chunk + params[:, offset:offset + symbol_size, :])
    offset += symbol_size
  return results
126224
def find_quality(positions):
    
    for q, p in QUALITY_DICT.items():
        if positions == list(p):
            return q
    return None
899650
def labelset_heads(self, label):
        
        _eps = self._eps
        _vars = self._vars
        _hcons = self._hcons
        nodeids = {nodeid: _eps[nodeid][3].get(IVARG_ROLE, None)
                for nodeid in _vars[label]['refs']['LBL']}
        if len(nodeids) <= 1:
            return list(nodeids)

        scope_sets = {}
        for nid in nodeids:
            scope_sets[nid] = _ivs_in_scope(nid, _eps, _vars, _hcons)

        out = {}
        for n in nodeids:
            out[n] = 0
            for role, val in _eps[n][3].items():
                if role == IVARG_ROLE or role == CONSTARG_ROLE:
                    continue
                elif any(val in s for n2, s in scope_sets.items() if n2 != n):
                    out[n] += 1

        candidates = [n for n, out_deg in out.items() if out_deg == 0]
        rank = {}
        for n in candidates:
            iv = nodeids[n]
            pred = _eps[n][1]
            if iv in _vars and self.nodeid(iv, quantifier=True) is not None:
                rank[n] = 0
            elif pred.is_quantifier():
                rank[n] = 0
            elif pred.type == Pred.ABSTRACT:
                rank[n] = 2
            else:
                rank[n] = 1

        return sorted(candidates, key=lambda n: rank[n])
1012329
def process(self, candidates):
        
        return sorted(candidates, key=attrgetter('score'), reverse=self.reverse)