def is_positive_integer_power_of_two(argument):
    r"""
    Is true when ``argument`` is a positive integer power of 2.

    ..  container:: example

        >>> for n in range(10):
        ...     print(n, abjad.mathtools.is_positive_integer_power_of_two(n))
        ...
        0 False
        1 True
        2 True
        3 False
        4 True
        5 False
        6 False
        7 False
        8 True
        9 False

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

    return 0 < argument and mathtools.is_nonnegative_integer_power_of_two(
        argument
    )
Exemple #2
0
    def __init__(
        self,
        pair: typings.IntegerPair = (4, 4),
        *,
        partial: Duration = None,
        hide: bool = None,
    ) -> None:
        import abjad

        pair_ = getattr(pair, "pair", pair)
        assert isinstance(pair_, tuple), repr(pair_)
        assert len(pair_) == 2, repr(pair_)
        numerator, denominator = pair_
        assert isinstance(numerator, int), repr(numerator)
        assert isinstance(denominator, int), repr(denominator)
        self._numerator: int = numerator
        self._denominator: int = denominator
        if partial is not None:
            partial = Duration(partial)
        self._partial: typing.Optional[Duration] = partial
        if partial is not None:
            self._partial_repr_string = ", partial=%r" % self._partial
        else:
            self._partial_repr_string = ""
        if hide is not None:
            hide = bool(hide)
        self._hide: typing.Optional[bool] = hide
        self._multiplier = self.implied_prolation
        result = mathtools.is_nonnegative_integer_power_of_two(
            self.denominator)
        assert isinstance(result, bool)
        self._has_non_power_of_two_denominator: bool = not (result)
def all_are_nonnegative_integer_powers_of_two(argument):
    """
    Is true when ``argument`` is an iterable collection of nonnegative
    integer powers of two.

    ..  container:: example

        >>> items = [0, 1, 1, 1, 2, 4, 32, 32]
        >>> abjad.mathtools.all_are_nonnegative_integer_powers_of_two(items)
        True

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

    ..  container:: example

        Is true when ``argument`` is empty:

        >>> abjad.mathtools.all_are_nonnegative_integer_powers_of_two([])
        True

    Returns true or false.
    """
    from abjad import mathtools
    try:
        return all(
            mathtools.is_nonnegative_integer_power_of_two(_) for _ in argument)
    except TypeError:
        return False
def is_positive_integer_power_of_two(argument):
    r"""
    Is true when ``argument`` is a positive integer power of 2.

    ..  container:: example

        >>> for n in range(10):
        ...     print(n, abjad.mathtools.is_positive_integer_power_of_two(n))
        ...
        0 False
        1 True
        2 True
        3 False
        4 True
        5 False
        6 False
        7 False
        8 True
        9 False

    Returns true or false.
    """
    from abjad import mathtools
    return (0 < argument
            and mathtools.is_nonnegative_integer_power_of_two(argument))
Exemple #5
0
    def __init__(
        self,
        pair: typings.IntegerPair = (4, 4),
        *,
        partial: Duration = None,
        hide: bool = None,
    ) -> None:
        import abjad

        pair_ = getattr(pair, "pair", pair)
        assert isinstance(pair_, tuple), repr(pair_)
        assert len(pair_) == 2, repr(pair_)
        numerator, denominator = pair_
        assert isinstance(numerator, int), repr(numerator)
        assert isinstance(denominator, int), repr(denominator)
        self._numerator: int = numerator
        self._denominator: int = denominator
        if partial is not None:
            partial = Duration(partial)
        self._partial: typing.Optional[Duration] = partial
        if partial is not None:
            self._partial_repr_string = ", partial=%r" % self._partial
        else:
            self._partial_repr_string = ""
        if hide is not None:
            hide = bool(hide)
        self._hide: typing.Optional[bool] = hide
        self._multiplier = self.implied_prolation
        result = mathtools.is_nonnegative_integer_power_of_two(
            self.denominator
        )
        assert isinstance(result, bool)
        self._has_non_power_of_two_denominator: bool = not (result)
def all_are_nonnegative_integer_powers_of_two(argument):
    """
    Is true when ``argument`` is an iterable collection of nonnegative
    integer powers of two.

    ..  container:: example

        >>> items = [0, 1, 1, 1, 2, 4, 32, 32]
        >>> abjad.mathtools.all_are_nonnegative_integer_powers_of_two(items)
        True

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

    ..  container:: example

        Is true when ``argument`` is empty:

        >>> abjad.mathtools.all_are_nonnegative_integer_powers_of_two([])
        True

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

    try:
        return all(
            mathtools.is_nonnegative_integer_power_of_two(_) for _ in argument
        )
    except TypeError:
        return False
Exemple #7
0
 def __init__(self, tremolo_flags: int = 16) -> None:
     if isinstance(tremolo_flags, type(self)):
         tremolo_flags = tremolo_flags.tremolo_flags
     tremolo_flags = int(tremolo_flags)
     if not mathtools.is_nonnegative_integer_power_of_two(tremolo_flags):
         message = "nonnegative integer power of 2: {tremolo_flags!r}."
         raise ValueError(message)
     self._tremolo_flags = tremolo_flags
Exemple #8
0
 def __init__(self, tremolo_flags: int = 16) -> None:
     if isinstance(tremolo_flags, type(self)):
         tremolo_flags = tremolo_flags.tremolo_flags
     tremolo_flags = int(tremolo_flags)
     if not mathtools.is_nonnegative_integer_power_of_two(tremolo_flags):
         message = "nonnegative integer power of 2: {tremolo_flags!r}."
         raise ValueError(message)
     self._tremolo_flags = tremolo_flags
Exemple #9
0
    def is_assignable(self):
        r"""
        Is true when duration is assignable.

        ..  container:: example

            Is true when duration is assignable:

            >>> for numerator in range(0, 16 + 1):
            ...     duration = abjad.Duration(numerator, 16)
            ...     sixteenths = duration.with_denominator(16)
            ...     print('{!s}\t{}'.format(sixteenths, duration.is_assignable))
            ...
            0/16    False
            1/16    True
            2/16    True
            3/16    True
            4/16    True
            5/16    False
            6/16    True
            7/16    True
            8/16    True
            9/16    False
            10/16   False
            11/16   False
            12/16   True
            13/16   False
            14/16   True
            15/16   True
            16/16   True

        Returns true or false.
        """
        if 0 < self < 16:
            if mathtools.is_nonnegative_integer_power_of_two(
                self.denominator):
                if mathtools.is_assignable_integer(self.numerator):
                    return True
        return False
Exemple #10
0
    def is_assignable(self) -> bool:
        r"""
        Is true when duration is assignable.

        ..  container:: example

            Is true when duration is assignable:

            >>> for numerator in range(0, 16 + 1):
            ...     duration = abjad.Duration(numerator, 16)
            ...     sixteenths = duration.with_denominator(16)
            ...     print('{!s}\t{}'.format(sixteenths, duration.is_assignable))
            ...
            0/16    False
            1/16    True
            2/16    True
            3/16    True
            4/16    True
            5/16    False
            6/16    True
            7/16    True
            8/16    True
            9/16    False
            10/16   False
            11/16   False
            12/16   True
            13/16   False
            14/16   True
            15/16   True
            16/16   True

        """
        if 0 < self < 16:
            if mathtools.is_nonnegative_integer_power_of_two(self.denominator):
                if mathtools.is_assignable_integer(self.numerator):
                    return True
        return False