Return the permutation for a single link step.
541854
@Nullable
  final Permutation calculatePermutation( @Nonnull final TreeLogger logger,
                                          @Nonnull final LinkerContext context,
                                          @Nonnull final ArtifactSet artifacts )
    throws UnableToCompleteException
  {
    Permutation permutation = null;

    for ( final SelectionInformation result : artifacts.find( SelectionInformation.class ) )
    {
      final String strongName = result.getStrongName();
      if ( null != permutation && !permutation.getPermutationName().equals( strongName ) )
      {
        throw new UnableToCompleteException();
      }
      if ( null == permutation )
      {
        permutation = new Permutation( strongName );
        final Set<String> artifactsForCompilation = getArtifactsForCompilation( context, artifacts );
        permutation.getPermutationFiles().addAll( artifactsForCompilation );
      }
      final List<BindingProperty> list = new ArrayList<>();
      for ( final SelectionProperty property : context.getProperties() )
      {
        if ( !property.isDerived() )
        {
          final String name = property.getName();
          final String value = result.getPropMap().get( name );
          if ( null != value )
          {
            list.add( new BindingProperty( name, value ) );
          }
        }
      }
      final SelectionDescriptor selection = new SelectionDescriptor( strongName, list );
      final List<SelectionDescriptor> selectors = permutation.getSelectors();
      if ( !selectors.contains( selection ) )
      {
        selectors.add( selection );
      }
    }
    if ( null != permutation )
    {
      logger.log( Type.DEBUG, "Calculated Permutation: " + permutation.getPermutationName() +
                              " Selectors: " + permutation.getSelectors() );
    }
    return permutation;
  }
613459
private int permutationParity(int[] vs) {
        int n = 0;
        for (int i = 0; i < vs.length; i++)
            for (int j = i + 1; j < vs.length; j++)
                if (vs[i] > vs[j]) n++;
        return (n & 0x1) == 1 ? -1 : 1;
    }
671095
def permute_pathways_across_features(self):
        
        side_labels = self.feature_pathway_df.side.unique()
        pathway_features = {}
        for side in side_labels:
            pathway_features[side] = []

        feature_grouping = self.feature_pathway_df.groupby(
            ["side", "feature"])

        for (side, feature), group in feature_grouping:
            pathways = group["pathway"].tolist()
            for pathway in pathways:
                pathway_features[side].append((pathway, feature))

        permuted_network = {}
        for side in side_labels:
            pathway_side_permutation = _pathway_feature_permutation(
                pathway_features[side], self.permutation_max_iters)
            while pathway_side_permutation is None:
                pathway_side_permutation = _pathway_feature_permutation(
                    pathway_features[side], self.permutation_max_iters)
            assert _permutation_correctness(
                pathway_side_permutation, pathway_features[side]), \
                ("Permutation on side {0} did not preserve the "
                 "expected invariants").format(side)
            permuted_network[side] = pathway_side_permutation
        return CoNetwork(self.n_features,
                         significant_pathways=permuted_network)
629605
def permute(self, idx):
        

        # Check that input is a true permutation
        if set(idx) != set(range(self.rank)):
            raise ValueError('Invalid permutation specified.')

        # Update factors
        self.factors = [f[:, idx] for f in self.factors]
        return self.factors
1236558
def __get_cycle(graph, ordering, parent_lookup):
    """"""
    root_node = ordering[0]
    for i in range(2, len(ordering)):
        current_node = ordering[i]
        if graph.adjacent(current_node, root_node):
            path = []
            while current_node != root_node:
                path.append(current_node)
                current_node = parent_lookup[current_node]
            path.append(root_node)
            path.reverse()
            return path
241575
def _compute_permutation_c(positions_a,  # scaled positions
                           positions_b,
                           lattice,  # column vectors
                           symprec):
    

    permutation = np.zeros(shape=(len(positions_a),), dtype='intc')

    def permutation_error():
        raise ValueError("Input forces are not enough to calculate force constants, "
                         "or something wrong (e.g. crystal structure does not match).")

    try:
        import phonopy._phonopy as phonoc
        is_found = phonoc.compute_permutation(permutation,
                                              lattice,
                                              positions_a,
                                              positions_b,
                                              symprec)

        if not is_found:
            permutation_error()

    except ImportError:
        for i, pos_b in enumerate(positions_b):
            diffs = positions_a - pos_b
            diffs -= np.rint(diffs)
            diffs = np.dot(diffs, lattice.T)

            possible_j = np.nonzero(
                np.sqrt(np.sum(diffs**2, axis=1)) < symprec)[0]
            if len(possible_j) != 1:
                permutation_error()

            permutation[i] = possible_j[0]

        if -1 in permutation:
            permutation_error()

    return permutation
1107683
private String getHalfMatrixString(Permutation permutation) {
        StringBuilder builder = new StringBuilder(permutation.size());
        int size = permutation.size();
        for (int indexI = 0; indexI < size - 1; indexI++) {
            for (int indexJ = indexI + 1; indexJ < size; indexJ++) {
                builder.append(getConnectivity(permutation.get(indexI), permutation.get(indexJ)));
            }
        }
        return builder.toString();
    }
580979
def linkage(self):
        """"""
        if not hasattr(self, '_linkage'):
            self._linkage = conf.lib.clang_getCursorLinkage(self)

        return LinkageKind.from_id(self._linkage)
250634
def _permutation_correctness(pathway_feature_tuples, original):
    
    if pathway_feature_tuples:
        if set(pathway_feature_tuples) == set(original):
            return False
        pathways_in_feature = {}
        for (pathway, feature) in pathway_feature_tuples:
            if feature not in pathways_in_feature:
                pathways_in_feature[feature] = set()
            if pathway in pathways_in_feature[feature]:
                return False
            else:
                pathways_in_feature[feature].add(pathway)
    return True
1051522
function(permalink) {
    permalink = permalink || '';
    if (permalink.slice(0, 1) !== PATH_SEP) {
      permalink = PATH_SEP + permalink;
    }
    permalink = permalink.replace(INDEX_RE, PATH_SEP);
    return permalink;
  }
465793
def _permute(self, ordering: np.ndarray) -> None:
		
		for key in self.keys():
			self[key] = self[key][ordering]
93348
def next_permutation(tab):
    
    n = len(tab)
    pivot = None                         # find pivot
    for i in range(n - 1):
        if tab[i] < tab[i + 1]:
            pivot = i
    if pivot is None:                    # tab is already the last perm.
        return False
    for i in range(pivot + 1, n):        # find the element to swap
        if tab[i] > tab[pivot]:
            swap = i
    tab[swap], tab[pivot] = tab[pivot], tab[swap]
    i = pivot + 1
    j = n - 1                            # invert suffix
    while i < j:
        tab[i], tab[j] = tab[j], tab[i]
        i += 1
        j -= 1
    return True
789326
public Integer[] nextPermutation() {
                if (permLeft.equals(permTotal)) {
                        permLeft = permLeft.subtract(BigInteger.ONE);
                        return position;
                }

                // Find largest index j with a[j] < a[j+1]
                int j = position.length - 2;
                while (position[j] > position[j + 1]) {
                        j--;
                }

                // Find index k such that a[k] is smallest integer
                // greater than a[j] to the right of a[j]
                int k = position.length - 1;
                while (position[j] > position[k]) {
                        k--;
                }

                // Interchange a[j] and a[k]
                int temp;
                temp = position[k];
                position[k] = position[j];
                position[j] = temp;

                // Put tail end of permutation after j-th position in increasing order
                int r = position.length - 1;
                int s = j + 1;
                while (r > s) {
                        temp = position[s];
                        position[s] = position[r];
                        position[r] = temp;
                        r--;
                        s++;
                }

                permLeft = permLeft.subtract(BigInteger.ONE);
                return position;
        }
510491
def url_permutations(url):
        
        def url_host_permutations(host):
            if re.match(r'\d+\.\d+\.\d+\.\d+', host):
                yield host
                return
            parts = host.split('.')
            l = min(len(parts), 5)
            if l > 4:
                yield host
            for i in range(l - 1):
                yield '.'.join(parts[i - l:])

        def url_path_permutations(path):
            yield path
            query = None
            if '?' in path:
                path, query = path.split('?', 1)
            if query is not None:
                yield path
            path_parts = path.split('/')[0:-1]
            curr_path = ''
            for i in range(min(4, len(path_parts))):
                curr_path = curr_path + path_parts[i] + '/'
                yield curr_path

        protocol, address_str = urllib.splittype(url)
        host, path = urllib.splithost(address_str)
        user, host = urllib.splituser(host)
        host, port = urllib.splitport(host)
        host = host.strip('/')
        seen_permutations = set()
        for h in url_host_permutations(host):
            for p in url_path_permutations(path):
                u = '{}{}'.format(h, p)
                if u not in seen_permutations:
                    yield u
                    seen_permutations.add(u)
480899
def get_single_item(d):
    """"""
    assert len(d) == 1, 'Single-item dict must have just one item, not %d.' % len(d)
    return next(six.iteritems(d))
934703
def permlink(self, identifier):
        ''' 
        '''
        temp = identifier.split("@")
        temp2 = temp[1].split("/")
        return [temp2[0], temp2[1]]
1083085
private int rankPermutationLexicographically(int[] permutation) {
        int rank = 0;
        int n = permutation.length;
        int[] counter = new int[n + 1];
        for (int i = 1; i < permutation.length; i++) {
            counter[i] = permutation[i - 1] + 1;
        }
        for (int j = 1; j <= n; j++) {
            rank += (counter[j] - 1) * factorial(n - j);
            for (int i = j + 1; i <= n; i++) {
                if (counter[i] > counter[j]) {
                    counter[i]--;
                }
            }
        }
        return rank + 1;
    }