コード例 #1
0
ファイル: ColorFingering.py プロジェクト: thomasmarsh/abjad
 def __init__(
     self, number: int = None, *, tweaks: LilyPondTweakManager = None
 ) -> None:
     if number is not None:
         assert mathtools.is_positive_integer(number)
     self._number = number
     if tweaks is not None:
         assert isinstance(tweaks, LilyPondTweakManager), repr(tweaks)
     self._tweaks = LilyPondTweakManager.set_tweaks(self, tweaks)
コード例 #2
0
 def __init__(
     self,
     number: int = None,
     *,
     tweaks: typing.Union[typing.List[typing.Tuple],
                          LilyPondTweakManager] = None,
 ) -> None:
     if number is not None:
         assert mathtools.is_positive_integer(number)
     self._number = number
     self._tweaks = None
     LilyPondTweakManager.set_tweaks(self, tweaks)
コード例 #3
0
ファイル: factors.py プロジェクト: Abjad/abjad
def factors(n):
    """
    Gets prime factors less than or equal to ``n`` .

    ..  container:: example

        >>> abjad.mathtools.factors(84)
        [2, 2, 3, 7]

        >>> for n in range(10, 20):
        ...   print(n, abjad.mathtools.factors(n))
        ...
        10 [2, 5]
        11 [11]
        12 [2, 2, 3]
        13 [13]
        14 [2, 7]
        15 [3, 5]
        16 [2, 2, 2, 2]
        17 [17]
        18 [2, 3, 3]
        19 [19]

    ``n`` must be a positive integer.

    Returns factors in increasing order.

    Returns list of positive integers.
    """
    from abjad import mathtools

    if not mathtools.is_positive_integer(n):
        message = "must be positive integer: {!r}."
        message = message.format(n)
        raise TypeError(message)
    factor = 2
    factors = []
    while 1 < n:
        if n % factor == 0:
            factors.append(factor)
            n = n / factor
        else:
            factor = factor + 1
    return factors
コード例 #4
0
ファイル: Enumerator.py プロジェクト: tuchang/abjad
    def _yield_restricted_growth_functions(length):
        """
        Yields restricted growth functions of ``length``.

        ..  container:: example

            >>> rgfs = abjad.Enumerator._yield_restricted_growth_functions(4)
            >>> for rgf in rgfs:
            ...     rgf
            ...
            (1, 1, 1, 1)
            (1, 1, 1, 2)
            (1, 1, 2, 1)
            (1, 1, 2, 2)
            (1, 1, 2, 3)
            (1, 2, 1, 1)
            (1, 2, 1, 2)
            (1, 2, 1, 3)
            (1, 2, 2, 1)
            (1, 2, 2, 2)
            (1, 2, 2, 3)
            (1, 2, 3, 1)
            (1, 2, 3, 2)
            (1, 2, 3, 3)
            (1, 2, 3, 4)

        Returns restricted growth functions in lex order.

        Returns generator of tuples.
        """
        assert mathtools.is_positive_integer(length), repr(length)
        last_rgf = list(range(1, length + 1))
        rgf = length * [1]
        yield tuple(rgf)
        while not rgf == last_rgf:
            for i, x in enumerate(reversed(rgf)):
                stop = -(i + 1)
                if x < max(rgf[:stop]) + 1:
                    first_part = rgf[:stop]
                    increased_part = [rgf[stop] + 1]
                    trailing_ones = i * [1]
                    rgf = first_part + increased_part + trailing_ones
                    yield tuple(rgf)
                    break
コード例 #5
0
def all_are_positive_integers(argument):
    """
    Is true when ``argument`` is an iterable collection of positive integers.

    ..  container:: example

        >>> abjad.mathtools.all_are_positive_integers([1, 2, 3, 99])
        True

        >>> abjad.mathtools.all_are_positive_integers(17)
        False

    Returns true or false.
    """
    from abjad import mathtools
    try:
        return all(mathtools.is_positive_integer(_) for _ in argument)
    except TypeError:
        return False
コード例 #6
0
ファイル: factors.py プロジェクト: gsy/gmajor
def factors(n):
    """
    Gets prime factors less than or equal to ``n`` .

    ..  container:: example

        >>> abjad.mathtools.factors(84)
        [2, 2, 3, 7]

        >>> for n in range(10, 20):
        ...   print(n, abjad.mathtools.factors(n))
        ...
        10 [2, 5]
        11 [11]
        12 [2, 2, 3]
        13 [13]
        14 [2, 7]
        15 [3, 5]
        16 [2, 2, 2, 2]
        17 [17]
        18 [2, 3, 3]
        19 [19]

    ``n`` must be a positive integer.

    Returns factors in increasing order.

    Returns list of positive integers.
    """
    from abjad import mathtools
    if not mathtools.is_positive_integer(n):
        message = 'must be positive integer: {!r}.'
        message = message.format(n)
        raise TypeError(message)
    factor = 2
    factors = []
    while 1 < n:
        if n % factor == 0:
            factors.append(factor)
            n = n / factor
        else:
            factor = factor + 1
    return factors
コード例 #7
0
def all_are_positive_integers(argument):
    """
    Is true when ``argument`` is an iterable collection of positive integers.

    ..  container:: example

        >>> abjad.mathtools.all_are_positive_integers([1, 2, 3, 99])
        True

        >>> abjad.mathtools.all_are_positive_integers(17)
        False

    Returns true or false.
    """
    from abjad import mathtools

    try:
        return all(mathtools.is_positive_integer(_) for _ in argument)
    except TypeError:
        return False