Sort equations by dependence
489107
def blt(f: List[SYM], x: List[SYM]) -> Dict[str, Any]:
    
    J = ca.jacobian(f, x)
    nblock, rowperm, colperm, rowblock, colblock, coarserow, coarsecol = J.sparsity().btf()
    return {
        'J': J,
        'nblock': nblock,
        'rowperm': rowperm,
        'colperm': colperm,
        'rowblock': rowblock,
        'colblock': colblock,
        'coarserow': coarserow,
        'coarsecol': coarsecol
    }
779651
def sort_by_successors(l, succsOf):
    
    rlut = dict()
    nret = 0
    todo = list()
    for i in l:
        rlut[i] = set()
    for i in l:
        for j in succsOf(i):
            rlut[j].add(i)
    for i in l:
        if len(rlut[i]) == 0:
            todo.append(i)
    while len(todo) > 0:
        i = todo.pop()
        nret += 1
        yield i
        for j in succsOf(i):
            rlut[j].remove(i)
            if len(rlut[j]) == 0:
                todo.append(j)
    if nret != len(l):
        raise ValueError("Cycle detected")
56823
def topological_sort(dependency_pairs):
    ""
    num_heads = defaultdict(int)  # num arrows pointing in
    tails = defaultdict(list)  # list of arrows going out
    heads = []  # unique list of heads in order first seen
    for h, t in dependency_pairs:
        num_heads[t] += 1
        if h in tails:
            tails[h].append(t)
        else:
            tails[h] = [t]
            heads.append(h)

    ordered = [h for h in heads if h not in num_heads]
    for h in ordered:
        for t in tails[h]:
            num_heads[t] -= 1
            if not num_heads[t]:
                ordered.append(t)
    cyclic = [n for n, heads in num_heads.items() if heads]
    return Results(ordered, cyclic)
608796
public function sortByDependencies() : self
    {
        /** @var $packages Package[] */
        $packages = $this->packages;
        $sortedPackages = [];

        while (!empty($packages)) {
            foreach ($packages as $packageName => $package) {
                $dependentPackages = $package->getDependencies()->toArray();
                if (empty(array_diff_key($dependentPackages, $sortedPackages))) {
                    // all of this packages dependencies are already in the sorted array, so it can be appended
                    $sortedPackages[$packageName] = $package;
                    unset($packages[$packageName]);
                    continue(2);
                }
            }
            throw new \LogicException('Packages have circular dependencies');
        }

        return new static($sortedPackages);
    }
687213
def topological_sort(dependencies, start_nodes):
    
    retval = []
    def edges(node): return dependencies[node][1]
    def in_degree(node): return dependencies[node][0]
    def remove_incoming(node): dependencies[node][0] = in_degree(node) - 1
    while start_nodes:
        node = start_nodes.pop()
        retval.append(node)
        for child in edges(node):
            remove_incoming(child)
            if not in_degree(child):
                start_nodes.append(child)
    leftover_nodes = [node for node in list(dependencies.keys())
                      if in_degree(node) > 0]
    if leftover_nodes:
        raise CyclicDependency(leftover_nodes)
    else:
        return retval
865013
def higher_order_diff(eqs, syms, order=2):
    ''''''

    import numpy

    eqs = list([sympy.sympify(eq) for eq in eqs])
    syms = list([sympy.sympify(s) for s in syms])

    neq = len(eqs)
    p = len(syms)

    D = [numpy.array(eqs)]
    orders = []

    for i in range(1,order+1):

        par = D[i-1]
        mat = numpy.empty([neq] + [p]*i, dtype=object)   #.append( numpy.zeros(orders))
        for ind in non_decreasing_series(p,i):

            ind_parent = ind[:-1]
            k = ind[-1]

            for line in range(neq):

                ii = [line] + ind
                iid = [line] + ind_parent
                eeq = par[ tuple(iid) ]
                mat[tuple(ii)] = eeq.diff(syms[k])

        D.append(mat)

    return D
504803
def order_by(self, order_by: Union[set, str]):
        """"""
        clone = self._clone()
        if isinstance(order_by, str):
            order_by = {order_by}

        clone._order_by = clone._order_by.union(order_by)

        return clone
545242
def _sort(self):
        """"""
        self.__dict__['_z_ordered_sprites'] = sorted(self.sprites, key=lambda sprite:sprite.z_order)
491764
def order_expressions
      @order_expressions ||=
      [filter_parameters[:order]].flatten.map do |order_predicate|
        next if order_predicate.blank?
        expr = order_expr order_predicate
        [expr.expression, expr]
      end.compact
    end
80900
def sort(self, key, *get_patterns,
             by=None, offset=None, count=None,
             asc=None, alpha=False, store=None):
        """"""
        args = []
        if by is not None:
            args += [b'BY', by]
        if offset is not None and count is not None:
            args += [b'LIMIT', offset, count]
        if get_patterns:
            args += sum(([b'GET', pattern] for pattern in get_patterns), [])
        if asc is not None:
            args += [asc is True and b'ASC' or b'DESC']
        if alpha:
            args += [b'ALPHA']
        if store is not None:
            args += [b'STORE', store]
        return self.execute(b'SORT', key, *args)
846331
function sortMediaQueries(a, b) {
  const A = a.replace(/\D/g, '');
  const B = b.replace(/\D/g, '');

  if (isMax(a) && isMax(b)) {
    return B - A;
  } else if (isMin(a) && isMin(b)) {
    return A - B;
  } else if (isMax(a) && isMin(b)) {
    return 1;
  } else if (isMin(a) && isMax(b)) {
    return -1;
  }

  return 1;
}
387850
def extract_sort(self, params):
        ''''''
        sorts = params.pop('sort', [])
        sorts = [sorts] if isinstance(sorts, basestring) else sorts
        sorts = [(s[1:], 'desc')
                 if s.startswith('-') else (s, 'asc')
                 for s in sorts]
        self.sorts = [
            {self.adapter.sorts[s]: d}
            for s, d in sorts if s in self.adapter.sorts
        ]
1019246
def sort(self, *args, **kwargs):
		""""""
		self._list.sort(*args, **kwargs)
		for index, value in enumerate(self._list):
			self._dict[value] = index
1008361
def order_param(ts, axis=2):
    """"""
    return np.abs(np.exp(1.0j * ts).mean(axis=axis))
296637
public static function sortByDependencies($extensions) {
        $sorted = array();
        $unsorted = array();
        foreach ($extensions as $ext) {
            $unsorted[$ext->getId()] = array_keys($ext->getDependencies());
        }
        while (!empty($unsorted)) {
            $before = count($unsorted);
            foreach (array_keys($unsorted) as $id) {
                $missing = array_diff($unsorted[$id], $sorted);
                if (empty($missing)) {
                    $sorted[] = $id;
                    unset($unsorted[$id]);
                }
            }
            if (count($unsorted) == $before) {
                $notfound = array_diff($missing, array_keys($unsorted));
                if (!empty($notfound)) {
                    throw new common_exception_Error('Missing extensions '.implode(',', $notfound).' for: '.implode(',', array_keys($unsorted)));
                } else {
                    throw new common_exception_Error('Cyclic extension dependencies for: '.implode(',', array_keys($unsorted)));
                }
            }
        }
        
        $returnValue = array();
        foreach ($sorted as $id) {
            foreach ($extensions as $ext) {
                if ($ext->getId() == $id) {
                    $returnValue[$id] = $ext;
                }
            }
        }
        return $returnValue;
    }
787112
def calculate_dependencies():
        
        order = []
        for g in toposort(merge_dicts(dependencies, soft_dependencies)):
            for t in sorted(g, key=lambda x: (priorities[x], x)):
                order.append(t)
        return order
798150
function (allDependencies, patterns) {
    return _.transform(allDependencies, function (result, dependencies, fileType) {
        result[fileType] = _.reject(dependencies, function (dependency) {
            return _.find(patterns, function (pattern) {
                return dependency.match(pattern);
            });
        });
    });
}