def is_positive_integer_power_of_two(argument): r'''Is true when `argument` is a positive integer power of 2. Otherwise false. .. 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.tools import mathtools return (0 < argument and mathtools.is_nonnegative_integer_power_of_two(argument))
def __init__( self, pair: typing.Tuple[int, int] = (4, 4), *, partial: Duration = None, hide: bool = None, ) -> None: import abjad pair = getattr(pair, 'pair', pair) assert isinstance(pair, collections.Iterable), 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(expr): '''Is true when `expr` is a sequence and all elements in `expr` are nonnegative integer powers of two. :: >>> mathtools.all_are_nonnegative_integer_powers_of_two([0, 1, 1, 1, 2, 4, 32, 32]) True Is true when `expr` is an empty sequence: :: >>> mathtools.all_are_nonnegative_integer_powers_of_two([]) True Otherwise false: :: >>> mathtools.all_are_nonnegative_integer_powers_of_two(17) False Returns true or false. ''' from abjad.tools import mathtools try: return all( mathtools.is_nonnegative_integer_power_of_two(x) for x in expr ) except TypeError: return False
def _scale(self, multiplier=None): from abjad.tools import containertools from abjad.tools import contexttools from abjad.tools import iterationtools from abjad.tools import timesignaturetools from abjad.tools.scoretools import attach if multiplier is None: return multiplier = durationtools.Multiplier(multiplier) old_time_signature = self.time_signature if mathtools.is_nonnegative_integer_power_of_two(multiplier) and \ 1 <= multiplier: old_numerator = old_time_signature.numerator old_denominator = old_time_signature.denominator new_denominator = old_denominator / multiplier.numerator pair = (old_numerator, new_denominator) new_time_signature = contexttools.TimeSignatureMark(pair) else: old_denominator = old_time_signature.denominator old_duration = old_time_signature.duration new_duration = multiplier * old_duration new_time_signature = \ timesignaturetools.duration_and_possible_denominators_to_time_signature( new_duration, [old_denominator], multiplier.denominator) for mark in self._get_marks(contexttools.TimeSignatureMark): mark.detach() attach(new_time_signature, self) contents_multiplier_denominator = \ mathtools.greatest_power_of_two_less_equal(multiplier.denominator) pair = (multiplier.numerator, contents_multiplier_denominator) contents_multiplier = durationtools.Multiplier(*pair) self._scale_contents(contents_multiplier)
def is_positive_integer_power_of_two(expr): r'''True when `expr` is a positive integer power of ``2``. :: >>> for n in range(10): ... print n, 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 Otherwise false. Returns boolean. ''' from abjad.tools import mathtools return 0 < expr and mathtools.is_nonnegative_integer_power_of_two(expr)
def is_positive_integer_power_of_two(expr): r'''Is true when `expr` is a positive integer power of ``2``. :: >>> for n in range(10): ... print(n, 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 Otherwise false. Returns boolean. ''' from abjad.tools import mathtools return 0 < expr and mathtools.is_nonnegative_integer_power_of_two(expr)
def __init__(self, counts=(1,), denominator=16): counts = self._to_tuple(counts) assert isinstance(counts, tuple) assert all(isinstance(x, int) for x in counts) self._counts = counts assert mathtools.is_nonnegative_integer_power_of_two(denominator) self._denominator = denominator
def all_are_nonnegative_integer_powers_of_two(expr): '''True when `expr` is a sequence and all elements in `expr` are nonnegative integer powers of two: :: >>> sequencetools.all_are_nonnegative_integer_powers_of_two([0, 1, 1, 1, 2, 4, 32, 32]) True True when `expr` is an empty sequence: :: >>> sequencetools.all_are_nonnegative_integer_powers_of_two([]) True False otherwise: :: >>> sequencetools.all_are_nonnegative_integer_powers_of_two(17) False Returns boolean. ''' try: return all(mathtools.is_nonnegative_integer_power_of_two(x) for x in expr) except TypeError: return False
def __init__( self, incise_divisions=False, incise_output=False, prefix_talea=(-1,), prefix_lengths=(0, 1), suffix_talea=(-11,), suffix_lengths=(1,), talea_denominator=32, body_ratio=None, fill_with_notes=True, ): assert isinstance(incise_divisions, bool) self._incise_divisions = incise_divisions assert isinstance(incise_output, bool) self._incise_output = incise_output assert self._is_integer_tuple(prefix_talea) self._prefix_talea = prefix_talea assert self._is_length_tuple(prefix_lengths) self._prefix_lengths = prefix_lengths assert self._is_integer_tuple(suffix_talea) self._suffix_talea = suffix_talea assert self._is_length_tuple(suffix_lengths) self._suffix_lengths = suffix_lengths assert mathtools.is_nonnegative_integer_power_of_two(talea_denominator) self._talea_denominator = talea_denominator if body_ratio is not None: body_ratio = mathtools.Ratio(body_ratio) self._body_ratio = body_ratio assert isinstance(fill_with_notes, bool) self._fill_with_notes = fill_with_notes
def is_assignable(self): r'''Is true when duration is assignable. Otherwise false: :: >>> for numerator in range(0, 16 + 1): ... duration = 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
def all_are_nonnegative_integer_powers_of_two(expr): '''Is true when `expr` is a sequence and all elements in `expr` are nonnegative integer powers of two. :: >>> mathtools.all_are_nonnegative_integer_powers_of_two([0, 1, 1, 1, 2, 4, 32, 32]) True Is true when `expr` is an empty sequence: :: >>> mathtools.all_are_nonnegative_integer_powers_of_two([]) True Otherwise false: :: >>> mathtools.all_are_nonnegative_integer_powers_of_two(17) False Returns boolean. ''' from abjad.tools import mathtools try: return all( mathtools.is_nonnegative_integer_power_of_two(x) for x in expr) except TypeError: return False
def _scale(self, multiplier=None): from abjad.tools import indicatortools if multiplier is None: return multiplier = durationtools.Multiplier(multiplier) old_time_signature = self.time_signature if mathtools.is_nonnegative_integer_power_of_two(multiplier) and \ 1 <= multiplier: old_numerator = old_time_signature.numerator old_denominator = old_time_signature.denominator new_denominator = old_denominator // multiplier.numerator pair = (old_numerator, new_denominator) new_time_signature = indicatortools.TimeSignature(pair) else: old_denominator = old_time_signature.denominator old_duration = old_time_signature.duration new_duration = multiplier * old_duration new_time_signature = \ self._duration_and_possible_denominators_to_time_signature( new_duration, [old_denominator], multiplier.denominator, ) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) contents_multiplier_denominator = \ mathtools.greatest_power_of_two_less_equal(multiplier.denominator) pair = (multiplier.numerator, contents_multiplier_denominator) contents_multiplier = durationtools.Multiplier(*pair) self._scale_contents(contents_multiplier)
def all_are_nonnegative_integer_powers_of_two(argument): '''Is true when `argument` is an iterable collection of nonnegative integer powers of two. Otherwise false. .. 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.tools import mathtools try: return all( mathtools.is_nonnegative_integer_power_of_two(_) for _ in argument) except TypeError: return False
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
def __init__(self, tremolo_flags=16): 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 = 'must be nonnegative integer power of 2: {!r}.' message = message.format(tremolo_flags) raise ValueError(message) self._tremolo_flags = tremolo_flags
def __init__( self, counts=(1,), denominator=16, ): counts = self._to_tuple(counts) assert isinstance(counts, tuple) assert all(isinstance(x, int) for x in counts) self._counts = counts assert mathtools.is_nonnegative_integer_power_of_two(denominator) self._denominator = denominator
def __init__( self, counts=(1,), denominator=16, ): from abjad.tools import rhythmmakertools counts = tuple(counts) assert all(isinstance(x, int) for x in counts) self._counts = counts assert mathtools.is_nonnegative_integer_power_of_two(denominator) self._denominator = denominator
def __init__(self, *args, **kwargs): from abjad.tools import stafftools target_context = kwargs.get('target_context', stafftools.Staff) ContextMark.__init__(self, target_context=target_context) if self._target_context == stafftools.Staff: self._has_default_target_context = True else: self._has_default_target_context = False partial, suppress = None, None # initialize numerator and denominator from *args if len(args) == 1 and isinstance(args[0], type(self)): time_signature = args[0] numerator = time_signature.numerator denominator = time_signature.denominator partial = time_signature.partial suppress = time_signature.suppress elif len(args) == 1 and isinstance(args[0], durationtools.Duration): numerator, denominator = args[0].numerator, args[0].denominator elif len(args) == 1 and isinstance(args[0], tuple): numerator, denominator = args[0][0], args[0][1] elif len(args) == 1 and hasattr(args[0], 'numerator') and \ hasattr(args[0], 'denominator'): numerator, denominator = args[0].numerator, args[0].denominator else: message = 'invalid time_signature initialization: {!r}.' message = message.format(args) raise TypeError(message) self._numerator = numerator self._denominator = denominator # initialize partial from **kwargs partial = partial or kwargs.get('partial', None) if not isinstance(partial, (type(None), durationtools.Duration)): raise TypeError self._partial = partial if partial is not None: self._partial_repr_string = ', partial=%r' % self._partial else: self._partial_repr_string = '' # initialize suppress from kwargs suppress = suppress or kwargs.get('suppress', None) if not isinstance(suppress, (bool, type(None))): raise TypeError self.suppress = suppress # initialize derived attributes self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = \ not mathtools.is_nonnegative_integer_power_of_two( self.denominator)
def __init__( self, prefix_talea=None, prefix_counts=None, suffix_talea=None, suffix_counts=None, talea_denominator=None, body_ratio=None, fill_with_notes=True, outer_divisions_only=None, ): prefix_talea = prefix_talea or () prefix_talea = tuple(prefix_talea) assert self._is_integer_tuple(prefix_talea) self._prefix_talea = prefix_talea prefix_counts = prefix_counts or () prefix_counts = tuple(prefix_counts) assert self._is_length_tuple(prefix_counts) self._prefix_counts = prefix_counts if prefix_counts and prefix_counts != (0, ): assert prefix_talea if prefix_talea: assert prefix_counts suffix_talea = suffix_talea or () suffix_talea = tuple(suffix_talea) assert self._is_integer_tuple(suffix_talea) self._suffix_talea = suffix_talea assert self._is_length_tuple(suffix_counts) suffix_counts = suffix_counts or () suffix_counts = tuple(suffix_counts) self._suffix_counts = suffix_counts if suffix_counts and suffix_counts != (0, ): assert suffix_talea if suffix_talea: assert suffix_counts if talea_denominator is not None: if not mathtools.is_nonnegative_integer_power_of_two( talea_denominator): message = 'talea denominator {!r} must be nonnegative' message += ' integer power of 2.' message = message.format(talea_denominator) raise Exception(message) self._talea_denominator = talea_denominator if prefix_talea or suffix_talea: assert talea_denominator is not None if body_ratio is not None: body_ratio = mathtools.Ratio(body_ratio) self._body_ratio = body_ratio assert isinstance(fill_with_notes, bool) self._fill_with_notes = fill_with_notes assert isinstance(outer_divisions_only, (bool, type(None))) self._outer_divisions_only = outer_divisions_only
def __init__( self, prefix_talea=None, prefix_counts=None, suffix_talea=None, suffix_counts=None, talea_denominator=None, body_ratio=None, fill_with_notes=True, outer_divisions_only=None, ): prefix_talea = prefix_talea or () prefix_talea = tuple(prefix_talea) assert self._is_integer_tuple(prefix_talea) self._prefix_talea = prefix_talea prefix_counts = prefix_counts or () prefix_counts = tuple(prefix_counts) assert self._is_length_tuple(prefix_counts) self._prefix_counts = prefix_counts if prefix_counts and prefix_counts != (0,): assert prefix_talea if prefix_talea: assert prefix_counts suffix_talea = suffix_talea or () suffix_talea = tuple(suffix_talea) assert self._is_integer_tuple(suffix_talea) self._suffix_talea = suffix_talea assert self._is_length_tuple(suffix_counts) suffix_counts = suffix_counts or () suffix_counts = tuple(suffix_counts) self._suffix_counts = suffix_counts if suffix_counts and suffix_counts != (0,): assert suffix_talea if suffix_talea: assert suffix_counts if talea_denominator is not None: if not mathtools.is_nonnegative_integer_power_of_two( talea_denominator): message = 'talea denominator {!r} must be nonnegative' message += ' integer power of 2.' message = message.format(talea_denominator) raise Exception(message) self._talea_denominator = talea_denominator if prefix_talea or suffix_talea: assert talea_denominator is not None if body_ratio is not None: body_ratio = mathtools.Ratio(body_ratio) self._body_ratio = body_ratio assert isinstance(fill_with_notes, bool) self._fill_with_notes = fill_with_notes assert isinstance(outer_divisions_only, (bool, type(None))) self._outer_divisions_only = outer_divisions_only
def __init__( self, counts=(1, ), denominator=16, ): counts = tuple(counts) assert all(isinstance(x, int) for x in counts) self._counts = counts if not mathtools.is_nonnegative_integer_power_of_two(denominator): message = 'denominator must be integer power of 2: {!r}.' message = message.format(denominator) raise Exception(message) self._denominator = denominator
def __init__( self, counts=(1,), denominator=16, ): counts = tuple(counts) assert all(isinstance(x, int) for x in counts) self._counts = counts if not mathtools.is_nonnegative_integer_power_of_two(denominator): message = 'denominator must be integer power of 2: {!r}.' message = message.format(denominator) raise Exception(message) self._denominator = denominator
def __init__( self, counts: typing.Iterable[int] = (1, ), denominator: int = 16, preamble: typing.List[int] = None, ) -> None: assert all(isinstance(_, int) for _ in counts) self._counts = counts if not mathtools.is_nonnegative_integer_power_of_two(denominator): message = f'denominator {denominator} must be integer power of 2.' raise Exception(message) self._denominator = denominator if preamble is not None: assert all(isinstance(_, int) for _ in preamble), repr(preamble) self._preamble = preamble
def __init__( self, prefix_talea=None, prefix_counts=None, suffix_talea=None, suffix_counts=None, talea_denominator=None, body_ratio=None, fill_with_notes=True, outer_divisions_only=False, ): prefix_talea = prefix_talea or () prefix_talea = tuple(prefix_talea) assert self._is_integer_tuple(prefix_talea) self._prefix_talea = prefix_talea prefix_counts = prefix_counts or () prefix_counts = tuple(prefix_counts) assert self._is_length_tuple(prefix_counts) self._prefix_counts = prefix_counts if prefix_counts and prefix_counts != (0,): assert prefix_talea if prefix_talea: assert prefix_counts suffix_talea = suffix_talea or () suffix_talea = tuple(suffix_talea) assert self._is_integer_tuple(suffix_talea) self._suffix_talea = suffix_talea assert self._is_length_tuple(suffix_counts) suffix_counts = suffix_counts or () suffix_counts = tuple(suffix_counts) self._suffix_counts = suffix_counts if suffix_counts and suffix_counts != (0,): assert suffix_talea if suffix_talea: assert suffix_counts if talea_denominator is not None: assert mathtools.is_nonnegative_integer_power_of_two( talea_denominator) self._talea_denominator = talea_denominator if prefix_talea or suffix_talea: assert talea_denominator is not None if body_ratio is not None: body_ratio = mathtools.Ratio(body_ratio) self._body_ratio = body_ratio assert isinstance(fill_with_notes, bool) self._fill_with_notes = fill_with_notes assert isinstance(outer_divisions_only, bool) self._outer_divisions_only = outer_divisions_only
def __init__( self, prefix_talea=None, prefix_counts=None, suffix_talea=None, suffix_counts=None, talea_denominator=None, body_ratio=None, fill_with_notes=True, outer_divisions_only=False, ): prefix_talea = prefix_talea or () prefix_talea = tuple(prefix_talea) assert self._is_integer_tuple(prefix_talea) self._prefix_talea = prefix_talea prefix_counts = prefix_counts or () prefix_counts = tuple(prefix_counts) assert self._is_length_tuple(prefix_counts) self._prefix_counts = prefix_counts if prefix_counts and prefix_counts != (0, ): assert prefix_talea if prefix_talea: assert prefix_counts suffix_talea = suffix_talea or () suffix_talea = tuple(suffix_talea) assert self._is_integer_tuple(suffix_talea) self._suffix_talea = suffix_talea assert self._is_length_tuple(suffix_counts) suffix_counts = suffix_counts or () suffix_counts = tuple(suffix_counts) self._suffix_counts = suffix_counts if suffix_counts and suffix_counts != (0, ): assert suffix_talea if suffix_talea: assert suffix_counts if talea_denominator is not None: assert mathtools.is_nonnegative_integer_power_of_two( talea_denominator) self._talea_denominator = talea_denominator if prefix_talea or suffix_talea: assert talea_denominator is not None if body_ratio is not None: body_ratio = mathtools.Ratio(body_ratio) self._body_ratio = body_ratio assert isinstance(fill_with_notes, bool) self._fill_with_notes = fill_with_notes assert isinstance(outer_divisions_only, bool) self._outer_divisions_only = outer_divisions_only
def __init__(self, *args): if len(args) == 1 and isinstance(args[0], type(self)): tremolo_flags = args[0].tremolo_flags elif len(args) == 1 and not isinstance(args[0], type(self)): tremolo_flags = args[0] elif len(args) == 0: tremolo_flags = 16 else: message = 'can not initialize {}: {!r}.' message = message.format(type(self).__name__, args) raise ValueError(message) if not mathtools.is_nonnegative_integer_power_of_two(tremolo_flags): message = 'must be nonnegative integer power of 2: {!r}.' message = message.format(tremolo_flags) raise ValueError(message) self._tremolo_flags = tremolo_flags
def __init__(self, *args, **kwargs): from abjad.tools import scoretools self._default_scope = scoretools.Staff partial, suppress = None, None # initialize numerator and denominator from *args if len(args) == 0: numerator = 4 denominator = 4 elif len(args) == 1 and isinstance(args[0], type(self)): time_signature = args[0] numerator = time_signature.numerator denominator = time_signature.denominator partial = time_signature.partial suppress = time_signature.suppress elif len(args) == 1 and isinstance(args[0], durationtools.Duration): numerator, denominator = args[0].numerator, args[0].denominator elif len(args) == 1 and isinstance(args[0], tuple): numerator, denominator = args[0][0], args[0][1] elif len(args) == 1 and hasattr(args[0], 'numerator') and \ hasattr(args[0], 'denominator'): numerator, denominator = args[0].numerator, args[0].denominator else: message = 'invalid time_signature initialization: {!r}.' message = message.format(args) raise TypeError(message) self._numerator = numerator self._denominator = denominator # initialize partial from **kwargs partial = partial or kwargs.get('partial', None) if not isinstance(partial, (type(None), durationtools.Duration)): raise TypeError self._partial = partial if partial is not None: self._partial_repr_string = ', partial=%r' % self._partial else: self._partial_repr_string = '' # initialize suppress from kwargs suppress = suppress or kwargs.get('suppress', None) if not isinstance(suppress, (bool, type(None))): raise TypeError self._suppress = suppress # initialize derived attributes self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = \ not mathtools.is_nonnegative_integer_power_of_two( self.denominator)
def __init__(self, *args, **kwargs): from abjad.tools import scoretools self._default_scope = scoretools.Staff partial, suppress = None, None # initialize numerator and denominator from *args if len(args) == 0: numerator = 4 denominator = 4 elif len(args) == 1 and isinstance(args[0], type(self)): time_signature = args[0] numerator = time_signature.numerator denominator = time_signature.denominator partial = time_signature.partial suppress = time_signature.suppress elif len(args) == 1 and isinstance(args[0], durationtools.Duration): numerator, denominator = args[0].numerator, args[0].denominator elif len(args) == 1 and isinstance(args[0], tuple): numerator, denominator = args[0][0], args[0][1] elif len(args) == 1 and hasattr(args[0], "numerator") and hasattr(args[0], "denominator"): numerator, denominator = args[0].numerator, args[0].denominator else: message = "invalid time_signature initialization: {!r}." message = message.format(args) raise TypeError(message) self._numerator = numerator self._denominator = denominator # initialize partial from **kwargs partial = partial or kwargs.get("partial", None) if not isinstance(partial, (type(None), durationtools.Duration)): raise TypeError self._partial = partial if partial is not None: self._partial_repr_string = ", partial=%r" % self._partial else: self._partial_repr_string = "" # initialize suppress from kwargs suppress = suppress or kwargs.get("suppress", None) if not isinstance(suppress, (bool, type(None))): raise TypeError self._suppress = suppress # initialize derived attributes self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = not mathtools.is_nonnegative_integer_power_of_two(self.denominator)
def is_assignable(self): r'''Is true when duration is assignable. Otherwise false. .. container:: example **Example.** Is true when duration is assignable: :: >>> for numerator in range(0, 16 + 1): ... duration = 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
def __init__(self, pair=(4, 4), partial=None, suppress=None): from abjad.tools import scoretools self._default_scope = scoretools.Staff 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 = numerator self._denominator = denominator prototype = (durationtools.Duration, type(None)) assert isinstance(partial, prototype), repr(partial) self._partial = partial if partial is not None: self._partial_repr_string = ', partial=%r' % self._partial else: self._partial_repr_string = '' assert isinstance(suppress, (bool, type(None))), repr(suppress) self._suppress = suppress self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = \ not mathtools.is_nonnegative_integer_power_of_two( self.denominator)
def is_assignable(self): r'''True when assignable. Otherwise false: :: >>> for numerator in range(0, 16 + 1): ... duration = Duration(numerator, 16) ... print '{}\t{}'.format(duration.with_denominator(16), ... 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 boolean. ''' 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
def fset(self, tremolo_flags): if not mathtools.is_nonnegative_integer_power_of_two(tremolo_flags): message = "tremolo flags must be" message += " nonnegative integer power of 2." raise ValueError(message) self._tremolo_flags = tremolo_flags
def _split_by_duration( self, duration, fracture_spanners=False, tie_split_notes=True, use_messiaen_style_ties=False, ): from abjad.tools import scoretools from abjad.tools import selectiontools # check input duration = durationtools.Duration(duration) assert 0 <= duration, repr(duration) # if zero duration then return empty list and self if duration == 0: return [], self # get split point score offset global_split_point = self._get_timespan().start_offset + duration # get any duration-crossing descendents cross_offset = self._get_timespan().start_offset + duration duration_crossing_descendants = [] for descendant in self._get_descendants(): start_offset = descendant._get_timespan().start_offset stop_offset = descendant._get_timespan().stop_offset if start_offset < cross_offset < stop_offset: duration_crossing_descendants.append(descendant) # get any duration-crossing measure descendents measures = [ x for x in duration_crossing_descendants if isinstance(x, scoretools.Measure) ] # if we must split a power-of-two measure at non-power-of-two # split point then go ahead and transform the power-of-two measure # to non-power-of-two equivalent now; # code that crawls and splits later on will be happier if len(measures) == 1: measure = measures[0] split_point_in_measure = \ global_split_point - measure._get_timespan().start_offset if measure.has_non_power_of_two_denominator: if not measure.implied_prolation == \ split_point_in_measure.implied_prolation: raise NotImplementedError elif not mathtools.is_nonnegative_integer_power_of_two( split_point_in_measure.denominator): non_power_of_two_factors = mathtools.remove_powers_of_two( split_point_in_measure.denominator) non_power_of_two_factors = mathtools.factors( non_power_of_two_factors) non_power_of_two_product = 1 for non_power_of_two_factor in non_power_of_two_factors: non_power_of_two_product *= non_power_of_two_factor scoretools.scale_measure_denominator_and_adjust_measure_contents( measure, non_power_of_two_product) # rederive duration crosses with possibly new measure contents cross_offset = self._get_timespan().start_offset + duration duration_crossing_descendants = [] for descendant in self._get_descendants(): start_offset = descendant._get_timespan().start_offset stop_offset = descendant._get_timespan().stop_offset if start_offset < cross_offset < stop_offset: duration_crossing_descendants.append(descendant) elif 1 < len(measures): message = 'measures can not nest.' raise Exception(message) # any duration-crossing leaf will be at end of list bottom = duration_crossing_descendants[-1] did_split_leaf = False # if split point necessitates leaf split if isinstance(bottom, scoretools.Leaf): assert isinstance(bottom, scoretools.Leaf) did_split_leaf = True split_point_in_bottom = \ global_split_point - bottom._get_timespan().start_offset left_list, right_list = bottom._split_by_duration( split_point_in_bottom, fracture_spanners=fracture_spanners, tie_split_notes=tie_split_notes, use_messiaen_style_ties=use_messiaen_style_ties, ) right = right_list[0] leaf_right_of_split = right leaf_left_of_split = left_list[-1] duration_crossing_containers = duration_crossing_descendants[:-1] if not len(duration_crossing_containers): return left_list, right_list # if split point falls between leaves # then find leaf to immediate right of split point # in order to start upward crawl through duration-crossing containers else: duration_crossing_containers = duration_crossing_descendants[:] for leaf in iterate(bottom).by_class(scoretools.Leaf): if leaf._get_timespan().start_offset == global_split_point: leaf_right_of_split = leaf leaf_left_of_split = leaf_right_of_split._get_leaf(-1) break else: message = 'can not split empty container {!r}.' message = message.format(bottom) raise Exception(message) # find component to right of split that is also immediate child of # last duration-crossing container for component in \ leaf_right_of_split._get_parentage(include_self=True): if component._parent is duration_crossing_containers[-1]: highest_level_component_right_of_split = component break else: message = 'should we be able to get here?' raise ValueError(message) # crawl back up through duration-crossing containers and # fracture spanners if requested if fracture_spanners: start_offset = leaf_right_of_split._get_timespan().start_offset for parent in leaf_right_of_split._get_parentage(): if parent._get_timespan().start_offset == start_offset: for spanner in parent._get_spanners(): index = spanner._index(parent) spanner._fracture(index, direction=Left) if parent is component: break # crawl back up through duration-crossing containers and split each previous = highest_level_component_right_of_split for duration_crossing_container in \ reversed(duration_crossing_containers): assert isinstance( duration_crossing_container, scoretools.Container) i = duration_crossing_container.index(previous) left, right = duration_crossing_container._split_at_index( i, fracture_spanners=fracture_spanners, ) previous = right # NOTE: If logical tie here is convenience, then fusing is good. # If logical tie here is user-given, then fusing is less good. # Maybe later model difference between user logical ties and not. left_logical_tie = leaf_left_of_split._get_logical_tie() right_logical_tie = leaf_right_of_split._get_logical_tie() left_logical_tie._fuse_leaves_by_immediate_parent() right_logical_tie._fuse_leaves_by_immediate_parent() # reapply tie here if crawl above killed tie applied to leaves if did_split_leaf: if (tie_split_notes and isinstance(leaf_left_of_split, scoretools.Note)): if (leaf_left_of_split._get_parentage().root is leaf_right_of_split._get_parentage().root): leaves_around_split = \ (leaf_left_of_split, leaf_right_of_split) selection = selectiontools.ContiguousSelection( leaves_around_split) selection._attach_tie_spanner_to_leaf_pair( use_messiaen_style_ties=use_messiaen_style_ties, ) # return pair of left and right list-wrapped halves of container return ([left], [right])
def scale_and_adjust_time_signature(self, multiplier=None): r'''Scales `measure` by `multiplier` and adjusts time signature. .. container:: example Scales measure by non-power-of-two multiplier: :: >>> measure = Measure((3, 8), "c'8 d'8 e'8") >>> measure.implicit_scaling = True >>> show(measure) # doctest: +SKIP .. doctest:: >>> print(format(measure)) { \time 3/8 c'8 d'8 e'8 } :: >>> measure.scale_and_adjust_time_signature(Multiplier(2, 3)) >>> show(measure) # doctest: +SKIP .. doctest:: >>> print(format(measure)) { \time 3/12 \scaleDurations #'(2 . 3) { c'8 d'8 e'8 } } Returns none. ''' from abjad.tools import indicatortools from abjad.tools import scoretools if multiplier == 0: raise ZeroDivisionError old_time_signature = self.time_signature old_pair = \ (old_time_signature.numerator, old_time_signature.denominator) old_multiplier = old_time_signature.implied_prolation old_multiplier_pair = \ (old_multiplier.numerator, old_multiplier.denominator) multiplied_pair = mathtools.NonreducedFraction(old_multiplier_pair) multiplied_pair = multiplied_pair.multiply_without_reducing(multiplier) multiplied_pair = multiplied_pair.pair reduced_pair = mathtools.NonreducedFraction(old_multiplier_pair) reduced_pair = reduced_pair.multiply_with_cross_cancelation(multiplier) reduced_pair = reduced_pair.pair if reduced_pair != multiplied_pair: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = \ new_pair.multiply_with_numerator_preservation(multiplier) new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) remaining_multiplier = durationtools.Multiplier(reduced_pair) if remaining_multiplier != durationtools.Multiplier(1): self._scale_contents(remaining_multiplier) elif self._all_contents_are_scalable_by_multiplier(multiplier): self._scale_contents(multiplier) if (old_time_signature.has_non_power_of_two_denominator or not mathtools.is_nonnegative_integer_power_of_two( multiplier)): new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_cross_cancelation(multiplier) new_pair = new_pair.pair # multiplier is a negative power of two, like 1/2, 1/4, etc. elif multiplier < durationtools.Multiplier(0): new_pair = \ mathtools.NonreducedFraction.multiply_without_reducing( old_pair, multiplier) # multiplier is a nonnegative power of two, like 0, 1, 2, 4, etc. elif durationtools.Multiplier(0) < multiplier: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_numerator_preservation( multiplier) elif multiplier == durationtools.Multiplier(0): raise ZeroDivisionError new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) if new_time_signature.has_non_power_of_two_denominator: self.implicit_scaling = True else: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_numerator_preservation( multiplier) new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) if new_time_signature.has_non_power_of_two_denominator: self.implicit_scaling = True remaining_multiplier = \ multiplier / new_time_signature.implied_prolation if remaining_multiplier != durationtools.Multiplier(1): self._scale_contents(remaining_multiplier)
def __init__(self, pair=(4, 4), partial=None, suppress=None): from abjad.tools import scoretools self._default_scope = scoretools.Staff # #partial, suppress = None, None # # initialize numerator and denominator from *args # if len(args) == 0: # numerator = 4 # denominator = 4 # elif len(args) == 1 and isinstance(args[0], type(self)): # time_signature = args[0] # numerator = time_signature.numerator # denominator = time_signature.denominator # partial = time_signature.partial # suppress = time_signature.suppress # elif len(args) == 1 and isinstance(args[0], durationtools.Duration): # numerator, denominator = args[0].numerator, args[0].denominator # elif len(args) == 1 and isinstance(args[0], tuple): # numerator, denominator = args[0][0], args[0][1] # elif (len(args) == 1 and hasattr(args[0], 'numerator') and # hasattr(args[0], 'denominator')): # numerator, denominator = args[0].numerator, args[0].denominator # else: # message = 'invalid time_signature initialization: {!r}.' # message = message.format(args) # raise TypeError(message) 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 = numerator self._denominator = denominator # # initialize partial from **kwargs # partial = partial or kwargs.get('partial', None) # if not isinstance(partial, (type(None), durationtools.Duration)): # raise TypeError prototype = (durationtools.Duration, type(None)) assert isinstance(partial, prototype), repr(partial) self._partial = partial if partial is not None: self._partial_repr_string = ', partial=%r' % self._partial else: self._partial_repr_string = '' # # initialize suppress from kwargs # suppress = suppress or kwargs.get('suppress', None) # if not isinstance(suppress, (bool, type(None))): # raise TypeError assert isinstance(suppress, (bool, type(None))), repr(suppress) self._suppress = suppress # initialize derived attributes self._multiplier = self.implied_prolation self._has_non_power_of_two_denominator = \ not mathtools.is_nonnegative_integer_power_of_two( self.denominator)
def scale_and_adjust_time_signature(self, multiplier=None): r'''Scales `measure` by `multiplier` and adjusts time signature. .. container:: example Scales measure by non-power-of-two multiplier: :: >>> measure = Measure((3, 8), "c'8 d'8 e'8") >>> measure.implicit_scaling = True >>> show(measure) # doctest: +SKIP .. doctest:: >>> print(format(measure)) { \time 3/8 c'8 d'8 e'8 } :: >>> measure.scale_and_adjust_time_signature(Multiplier(2, 3)) >>> show(measure) # doctest: +SKIP .. doctest:: >>> print(format(measure)) { \time 3/12 \scaleDurations #'(2 . 3) { c'8 d'8 e'8 } } Returns none. ''' from abjad.tools import indicatortools from abjad.tools import scoretools if multiplier == 0: raise ZeroDivisionError old_time_signature = self.time_signature old_pair = \ (old_time_signature.numerator, old_time_signature.denominator) old_multiplier = old_time_signature.implied_prolation old_multiplier_pair = \ (old_multiplier.numerator, old_multiplier.denominator) multiplied_pair = mathtools.NonreducedFraction(old_multiplier_pair) multiplied_pair = multiplied_pair.multiply_without_reducing(multiplier) multiplied_pair = multiplied_pair.pair reduced_pair = mathtools.NonreducedFraction(old_multiplier_pair) reduced_pair = reduced_pair.multiply_with_cross_cancelation(multiplier) reduced_pair = reduced_pair.pair if reduced_pair != multiplied_pair: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = \ new_pair.multiply_with_numerator_preservation(multiplier) new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) remaining_multiplier = durationtools.Multiplier(reduced_pair) if remaining_multiplier != durationtools.Multiplier(1): self._scale_contents(remaining_multiplier) elif self._all_contents_are_scalable_by_multiplier(multiplier): self._scale_contents(multiplier) if ( old_time_signature.has_non_power_of_two_denominator or not mathtools.is_nonnegative_integer_power_of_two(multiplier) ): new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_cross_cancelation(multiplier) new_pair = new_pair.pair # multiplier is a negative power of two, like 1/2, 1/4, etc. elif multiplier < durationtools.Multiplier(0): new_pair = \ mathtools.NonreducedFraction.multiply_without_reducing( old_pair, multiplier) # multiplier is a nonnegative power of two, like 0, 1, 2, 4, etc. elif durationtools.Multiplier(0) < multiplier: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_numerator_preservation( multiplier) elif multiplier == durationtools.Multiplier(0): raise ZeroDivisionError new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) if new_time_signature.has_non_power_of_two_denominator: self.implicit_scaling = True else: new_pair = mathtools.NonreducedFraction(old_pair) new_pair = new_pair.multiply_with_numerator_preservation( multiplier) new_time_signature = indicatortools.TimeSignature(new_pair) detach(indicatortools.TimeSignature, self) attach(new_time_signature, self) if new_time_signature.has_non_power_of_two_denominator: self.implicit_scaling = True remaining_multiplier = \ multiplier / new_time_signature.implied_prolation if remaining_multiplier != durationtools.Multiplier(1): self._scale_contents(remaining_multiplier)
def test_mathtools_is_nonnegative_integer_power_of_two_04(): r'''Returns Is true when expr is an integer or Duration power of two, otherwise False.''' assert mathtools.is_nonnegative_integer_power_of_two(Duration(1, 1)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(1, 2)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 3)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(1, 4)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 5)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 6)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 7)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(1, 8)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 9)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 10)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 11)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(1, 12))
def _split_by_duration( self, duration, fracture_spanners=False, tie_split_notes=True, use_messiaen_style_ties=False, ): from abjad.tools import scoretools from abjad.tools import selectiontools # check input duration = durationtools.Duration(duration) assert 0 <= duration, repr(duration) # if zero duration then return empty list and self if duration == 0: return [], self # get split point score offset global_split_point = self._get_timespan().start_offset + duration # get any duration-crossing descendents cross_offset = self._get_timespan().start_offset + duration duration_crossing_descendants = [] for descendant in self._get_descendants(): start_offset = descendant._get_timespan().start_offset stop_offset = descendant._get_timespan().stop_offset if start_offset < cross_offset < stop_offset: duration_crossing_descendants.append(descendant) # get any duration-crossing measure descendents measures = [ x for x in duration_crossing_descendants if isinstance(x, scoretools.Measure) ] # if we must split a power-of-two measure at non-power-of-two # split point then go ahead and transform the power-of-two measure # to non-power-of-two equivalent now; # code that crawls and splits later on will be happier if len(measures) == 1: measure = measures[0] split_point_in_measure = \ global_split_point - measure._get_timespan().start_offset if measure.has_non_power_of_two_denominator: if not measure.implied_prolation == \ split_point_in_measure.implied_prolation: raise NotImplementedError elif not mathtools.is_nonnegative_integer_power_of_two( split_point_in_measure.denominator): non_power_of_two_factors = mathtools.remove_powers_of_two( split_point_in_measure.denominator) non_power_of_two_factors = mathtools.factors( non_power_of_two_factors) non_power_of_two_product = 1 for non_power_of_two_factor in non_power_of_two_factors: non_power_of_two_product *= non_power_of_two_factor scoretools.scale_measure_denominator_and_adjust_measure_contents( measure, non_power_of_two_product) # rederive duration crosses with possibly new measure contents cross_offset = self._get_timespan().start_offset + duration duration_crossing_descendants = [] for descendant in self._get_descendants(): start_offset = descendant._get_timespan().start_offset stop_offset = descendant._get_timespan().stop_offset if start_offset < cross_offset < stop_offset: duration_crossing_descendants.append(descendant) elif 1 < len(measures): message = 'measures can not nest.' raise Exception(message) # any duration-crossing leaf will be at end of list bottom = duration_crossing_descendants[-1] did_split_leaf = False # if split point necessitates leaf split if isinstance(bottom, scoretools.Leaf): assert isinstance(bottom, scoretools.Leaf) did_split_leaf = True split_point_in_bottom = \ global_split_point - bottom._get_timespan().start_offset left_list, right_list = bottom._split_by_duration( split_point_in_bottom, fracture_spanners=fracture_spanners, tie_split_notes=tie_split_notes, use_messiaen_style_ties=use_messiaen_style_ties, ) right = right_list[0] leaf_right_of_split = right leaf_left_of_split = left_list[-1] duration_crossing_containers = duration_crossing_descendants[:-1] if not len(duration_crossing_containers): return left_list, right_list # if split point falls between leaves # then find leaf to immediate right of split point # in order to start upward crawl through duration-crossing containers else: duration_crossing_containers = duration_crossing_descendants[:] for leaf in iterate(bottom).by_class(scoretools.Leaf): if leaf._get_timespan().start_offset == global_split_point: leaf_right_of_split = leaf leaf_left_of_split = leaf_right_of_split._get_leaf(-1) break else: message = 'can not split empty container {!r}.' message = message.format(bottom) raise Exception(message) # find component to right of split that is also immediate child of # last duration-crossing container for component in \ leaf_right_of_split._get_parentage(include_self=True): if component._parent is duration_crossing_containers[-1]: highest_level_component_right_of_split = component break else: message = 'should we be able to get here?' raise ValueError(message) # crawl back up through duration-crossing containers and # fracture spanners if requested if fracture_spanners: start_offset = leaf_right_of_split._get_timespan().start_offset for parent in leaf_right_of_split._get_parentage(): if parent._get_timespan().start_offset == start_offset: for spanner in parent._get_spanners(): index = spanner._index(parent) spanner._fracture(index, direction=Left) if parent is component: break # crawl back up through duration-crossing containers and split each previous = highest_level_component_right_of_split for duration_crossing_container in \ reversed(duration_crossing_containers): assert isinstance(duration_crossing_container, scoretools.Container) i = duration_crossing_container.index(previous) left, right = duration_crossing_container._split_at_index( i, fracture_spanners=fracture_spanners, ) previous = right # NOTE: If logical tie here is convenience, then fusing is good. # If logical tie here is user-given, then fusing is less good. # Maybe later model difference between user logical ties and not. left_logical_tie = leaf_left_of_split._get_logical_tie() right_logical_tie = leaf_right_of_split._get_logical_tie() left_logical_tie._fuse_leaves_by_immediate_parent() right_logical_tie._fuse_leaves_by_immediate_parent() # reapply tie here if crawl above killed tie applied to leaves if did_split_leaf: if (tie_split_notes and isinstance(leaf_left_of_split, scoretools.Note)): if (leaf_left_of_split._get_parentage().root is leaf_right_of_split._get_parentage().root): leaves_around_split = \ (leaf_left_of_split, leaf_right_of_split) selection = selectiontools.ContiguousSelection( leaves_around_split) selection._attach_tie_spanner_to_leaf_pair( use_messiaen_style_ties=use_messiaen_style_ties, ) # return pair of left and right list-wrapped halves of container return ([left], [right])
def test_mathtools_is_nonnegative_integer_power_of_two_03(): r'''Returns Is true when expr is an integer or Duration power of two, otherwise False.''' assert mathtools.is_nonnegative_integer_power_of_two(Duration(0)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(1)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(2)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(3)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(4)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(5)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(6)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(7)) assert mathtools.is_nonnegative_integer_power_of_two(Duration(8)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(9)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(10)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(11)) assert not mathtools.is_nonnegative_integer_power_of_two(Duration(12))
def test_mathtools_is_nonnegative_integer_power_of_two_01(): r'''Returns Is true when expr is an integer or Duration power of two, otherwise False.''' assert mathtools.is_nonnegative_integer_power_of_two(0) assert mathtools.is_nonnegative_integer_power_of_two(1) assert mathtools.is_nonnegative_integer_power_of_two(2) assert not mathtools.is_nonnegative_integer_power_of_two(3) assert mathtools.is_nonnegative_integer_power_of_two(4) assert not mathtools.is_nonnegative_integer_power_of_two(5) assert not mathtools.is_nonnegative_integer_power_of_two(6) assert not mathtools.is_nonnegative_integer_power_of_two(7) assert mathtools.is_nonnegative_integer_power_of_two(8) assert not mathtools.is_nonnegative_integer_power_of_two(9) assert not mathtools.is_nonnegative_integer_power_of_two(10) assert not mathtools.is_nonnegative_integer_power_of_two(11) assert not mathtools.is_nonnegative_integer_power_of_two(12)
def test_mathtools_is_nonnegative_integer_power_of_two_02(): r'''Returns Is true when expr is an integer or Duration power of two, otherwise False.''' assert mathtools.is_nonnegative_integer_power_of_two(0) assert not mathtools.is_nonnegative_integer_power_of_two(-1) assert not mathtools.is_nonnegative_integer_power_of_two(-2) assert not mathtools.is_nonnegative_integer_power_of_two(-3) assert not mathtools.is_nonnegative_integer_power_of_two(-4) assert not mathtools.is_nonnegative_integer_power_of_two(-5) assert not mathtools.is_nonnegative_integer_power_of_two(-6) assert not mathtools.is_nonnegative_integer_power_of_two(-7) assert not mathtools.is_nonnegative_integer_power_of_two(-8) assert not mathtools.is_nonnegative_integer_power_of_two(-9) assert not mathtools.is_nonnegative_integer_power_of_two(-10) assert not mathtools.is_nonnegative_integer_power_of_two(-11) assert not mathtools.is_nonnegative_integer_power_of_two(-12)