コード例 #1
0
ファイル: framework.py プロジェクト: numerical/argtrust
 def make_generator(self, up=True):
     """Returns a generator that cycles through every combination of Ar
     if up is True starts generating from the empty set to Ar, otherwise
     starts generating from Ar to the empty set
     """
     if up:
         for i in range(len(self._Ar)+1):
             for j in _combinations(self._Ar, i):
                 yield set(j)
     else:
         for i in range(len(self._Ar), -1, -1): # iterate from top to bottom
             for j in _combinations(self._Ar, i):
                 yield set(j)
コード例 #2
0
ファイル: _provisions.py プロジェクト: nisavid/bedframe
def provisionsets_combinations(provisionsets, choose0=True):

    """
    The authentication security provision sets that are yielded by
    combinations of given sets.

    :param provisionsets:
        A set of security provision sets.
    :type provisionsets: ~[:class:`ProvisionSetABC`]

    :param bool choose0:
        Whether to include the empty choice.  If true, then the empty set of
        security provisions is always included in the result.  Otherwise, it
        is included only if *provisionsets* contains it.

    :rtype: :class:`ProvisionSetABC`

    """

    if choose0:
        yield iter(provisionsets).next().__class__()

    for combination \
            in _chain(*(_combinations(provisionsets, nchoices)
                        for nchoices in range(1, len(provisionsets) + 1))):
        yield _reduce(_or, combination)
コード例 #3
0
ファイル: _stereo_.py プロジェクト: avcopan/automol-old
 def _is_stereogenic(atm_key):
     atm_bnd_keys = atm_bnd_keys_dct[atm_key]
     bnchs = [_branch(xgr, atm_key, bnd_key) for bnd_key in atm_bnd_keys]
     assert len(atm_bnd_keys) in (3, 4)
     _ans = not any(
         _starmap(_backbone_isomorphic, _combinations(bnchs, r=2)))
     return _ans
コード例 #4
0
def combinations(seq, k):
    """ Return j length subsequences of elements from the input iterable.

    This version uses Numpy/Scipy and should be preferred over itertools. It avoids
    the creation of all intermediate Python objects.

    Examples
    --------

    >>> import numpy as np
    >>> from itertools import combinations as iter_comb
    >>> x = np.arange(3)
    >>> c1 = combinations(x, 2)
    >>> print(c1)
    [[0 1]
     [0 2]
     [1 2]]
    >>> c2 = np.array(tuple(iter_comb(x, 2)))
    >>> print(c2)
    [[0 1]
     [0 2]
     [1 2]]
    """
    from itertools import combinations as _combinations, chain
    from scipy.special import comb

    count = comb(len(seq), k, exact=True)
    res = np.fromiter(chain.from_iterable(_combinations(seq, k)),
                      int,
                      count=count * k)
    return res.reshape(-1, k)
コード例 #5
0
ファイル: p021.py プロジェクト: tylercrompton/project-euler
def factors(number):
	'''Find all positive factors of a positive integer.'''

	_prime_factors = prime_factors(number)
	combinations = set()
	for i in range(1, len(_prime_factors) + 1):
		combinations.update(_combinations(_prime_factors, i))
	return {_functools.reduce(_mul, combination) for combination in combinations}.union({1})
コード例 #6
0
ファイル: utils.py プロジェクト: mijikai/euler-python
def powerset(iterable):
    """Generate another iterable composed of tuple that is a subset of iterable
    Example:
    >>> list(powerset([1,2,3]))
    [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
    """
    seq = tuple(iterable)
    return _chain.from_iterable(map(lambda i: _combinations(seq, i),
        range(len(seq) + 1)))
コード例 #7
0
ファイル: p012.py プロジェクト: tylercrompton/project-euler
def p012(min_divisors):
	i = 1
	jump = 2
	while True:
		prime_factors = tuple(prime_factor(i))
		number_of_factors = sum(len(set(_combinations(prime_factors, i))) for i in range(1, len(prime_factors) + 1)) + 1
		if number_of_factors > min_divisors:
			return i
		i += jump
		jump += 1
コード例 #8
0
	def forall(self,t="product"):
		if t.startswith("pr"):
			_k = list([list(i) for i in _product(self,repeat=2)])
		elif t.startswith("pe"):
			_k = list([list(i) for i in _permutations(self,2)])
		elif t.startswith("c") and t.endswith("s"):
			_k = list([list(i) for i in _combinations(self,2)])
		else:
			_k = list([list(i) for i in _combinations_with_replacement(self,2)])
		return lzlist(_k)
コード例 #9
0
ファイル: product_tica.py プロジェクト: fabian-paul/simplex
 def _transform_array(self, X):
     d = min(X.shape[1], self._take_max_dim)
     Y = _np.zeros((X.shape[0], self.dimension()), dtype=X.dtype)
     Y[:, 0:
       d] = X[:, 0:
              d]  # orig. data = products with the implicit 1 eigenfunctions
     # TODO: optimize
     for i in range(d):
         Y[:, i + d] = X[:, i] * X[:, i]  # squares
     for i, (k, l) in enumerate(_combinations(range(d), 2)):
         Y[:, i + 2 * d] = X[:, k] * X[:, l]  # products
     return Y
コード例 #10
0
def connectivity_graph(geo):
    """ connectivity graph
    """
    syms = _symbols(geo)
    xyzs = _coordinates(geo)

    def _are_bonded(idx_pair):
        xyz1, xyz2 = map(xyzs.__getitem__, idx_pair)
        sym1, sym2 = map(syms.__getitem__, idx_pair)
        dist = numpy.linalg.norm(numpy.subtract(xyz1, xyz2))
        return (False if 'X' in (sym1, sym2) else
                (dist < RH_BOND_MAX) if 'H' in (sym1, sym2) else
                (dist < RQ_BOND_MAX))

    idxs = range(len(xyzs))
    bnds = list(filter(_are_bonded, _combinations(idxs, r=2)))
    return _graph_from_data(atom_symbols=syms, bond_keys=bnds)
コード例 #11
0
ファイル: keywords.py プロジェクト: RaRe-Technologies/gensim
def _process_first_window(graph, tokens, split_text):
    """Sets an edges between nodes taken from first :const:`~gensim.parsing.keywords.WINDOW_SIZE`
    words of `split_text` if they exist in `tokens` and `graph`, inplace.

    Parameters
    ----------
    graph : :class:~gensim.summarization.graph.Graph
        Given graph.
    tokens : dict
        Original units (words) as keys and processed units (tokens) as values.
    split_text : list of str
        Splitted text.

    """
    first_window = _get_first_window(split_text)
    for word_a, word_b in _combinations(first_window, 2):
        _set_graph_edge(graph, tokens, word_a, word_b)
コード例 #12
0
ファイル: _carpanlar.py プロジェクト: yasar11732/PyMathGerec
def carpanlar(sayi):
    asal_carpanlar = asalCarpanlar(sayi)
    if len(asal_carpanlar) == 1:
        return [1] + [sayi]
    
    sonuc = [1]
    for i in range(1,len(asal_carpanlar)):
        
        for carpilcaklar in _combinations(asal_carpanlar, i):
            
            carpim = carpilcaklar[0]
            for j in range(1,i):
                carpim *= carpilcaklar[j]
            sonuc.append(carpim)

    sonuc.append(sayi)
    return sorted(tuple(set(sonuc)))
コード例 #13
0
ファイル: keywords.py プロジェクト: jabogithub/samenvattr
def _process_first_window(graph, tokens, split_text):
    """Sets an edges between nodes taken from first :const:`~samenvattr.parsing.keywords.WINDOW_SIZE`
    words of `split_text` if they exist in `tokens` and `graph`, inplace.

    Parameters
    ----------
    graph : :class:~samenvattr.summarization.graph.Graph
        Given graph.
    tokens : dict
        Original units (words) as keys and processed units (tokens) as values.
    split_text : list of str
        Splitted text.

    """
    first_window = _get_first_window(split_text)
    for word_a, word_b in _combinations(first_window, 2):
        _set_graph_edge(graph, tokens, word_a, word_b)
コード例 #14
0
ファイル: keywords.py プロジェクト: pdmorale/Summarization
def _process_first_window(graph, tokens, split_text):
    first_window = _get_first_window(split_text)
    for word_a, word_b in _combinations(first_window, 2):
        _set_graph_edge(graph, tokens, word_a, word_b)
コード例 #15
0
ファイル: _connectors.py プロジェクト: nisavid/bedframe
from ... import digest as _digest
from .. import _std as _std_http


_DIGEST_USER_OPTIONAL_TOKENS = ('qop', 'digest_algorithm', 'client_nonce',
                                'opaque', 'server_nonce_use_count')

_DIGEST_USER_REQUIRED_TOKENS = ('user', 'realm', 'server_nonce', 'digest_uri',
                                'digest')

_DIGEST_USER_TOKENSETS = \
    _frozenusetset(_chain(_DIGEST_USER_REQUIRED_TOKENS, optional_tokens)
                   for optional_tokens
                   in _chain((),
                             *(_combinations(_DIGEST_USER_OPTIONAL_TOKENS,
                                             n + 1)
                               for n
                               in range(len(_DIGEST_USER_OPTIONAL_TOKENS)))))


class HttpDigestClerk(_std_http.HttpStandardClerk):

    """An authentication clerk for HTTP Digest authentication"""

    __metaclass__ = _abc.ABCMeta

    _DIGEST_USER_OPTIONAL_TOKENS = _DIGEST_USER_OPTIONAL_TOKENS

    _DIGEST_USER_REQUIRED_TOKENS = _DIGEST_USER_REQUIRED_TOKENS

    _DIGEST_USER_TOKENSETS = _DIGEST_USER_TOKENSETS
コード例 #16
0
ファイル: _tokens.py プロジェクト: nisavid/bedframe
def tokens_combinations(tokens_or_names):
    names = tokens_names(tokens_or_names)
    return _chain(*(_combinations(names, ntokens)
                    for ntokens in range(len(names) + 1)))
コード例 #17
0
def combinations(r, it):
    return _combinations(it, r)
コード例 #18
0
ファイル: utils.py プロジェクト: mijikai/euler-python
def powerset_reverse(iterable):
    seq = tuple(reversed(iterable))
    return _chain.from_iterable(map(lambda i: _combinations(seq, i),
        range(len(seq), 0, -1)))
コード例 #19
0
ファイル: keywords.py プロジェクト: summanlp/textrank
def _process_first_window(graph, tokens, split_text):
    first_window = _get_first_window(split_text)
    for word_a, word_b in _combinations(first_window, 2):
        _set_graph_edge(graph, tokens, word_a, word_b)