Exemple #1
0
 def _make_score_number_markup(configuration_number, score_number):
     assert mathtools.is_nonnegative_integer(configuration_number)
     assert mathtools.is_nonnegative_integer(score_number)
     number_string = "{}-{}".format(configuration_number, score_number)
     command = markuptools.MarkupCommand("fontsize", 2, number_string)
     command = markuptools.MarkupCommand("italic", command)
     command = markuptools.MarkupCommand("box", command)
     pair = schemetools.SchemePair("box-padding", 0.75)
     command = markuptools.MarkupCommand("override", pair, command)
     width = 9
     command = markuptools.MarkupCommand("hcenter-in", width, command)
     markup = markuptools.Markup(command)
     return markup
Exemple #2
0
def repeat_sequence_to_length(sequence, length, start=0):
    '''Repeats `sequence` to nonnegative integer `length`.

    ::

        >>> sequencetools.repeat_sequence_to_length(list(range(5)), 11)
        [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0]

    Repeats `sequence` to nonnegative integer `length` from `start`:

    ::

        >>> sequencetools.repeat_sequence_to_length(
        ...     list(range(5)), 11, start=2)
        [2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2]

    Returns newly constructed `sequence` object.
    '''

    if not mathtools.is_nonnegative_integer(length):
        raise TypeError
    if len(sequence) <= 0:
        raise ValueError

    result = []
    start %= len(sequence)
    stop_index = start + length
    repetitions = int(math.ceil(float(stop_index) / len(sequence)))
    for x in range(repetitions):
        for element in sequence:
            result.append(copy.copy(element))
    return type(sequence)(result[start:stop_index])
def repeat_sequence_to_length(sequence, length, start=0):
    '''Repeat `sequence` to nonnegative integer `length`:

    ::

        >>> sequencetools.repeat_sequence_to_length(range(5), 11)
        [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0]

    Repeat `sequence` to nonnegative integer `length` from `start`:

    ::

        >>> sequencetools.repeat_sequence_to_length(range(5), 11, start=2)
        [2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2]

    Returns newly constructed `sequence` object.
    '''

    if not mathtools.is_nonnegative_integer(length):
        raise TypeError
    if len(sequence) <= 0:
        raise ValueError

    result = []
    start %= len(sequence)
    stop_index = start + length
    repetitions = int(math.ceil(stop_index / len(sequence)))
    for x in range(repetitions):
        for element in sequence:
            result.append(copy.copy(element))
    return type(sequence)(result[start:stop_index])
Exemple #4
0
def repeat_sequence(sequence, n):
    '''Repeats `sequence` `n` times.

    ::

        >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 3)
        (1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)

    Repeats `sequence` ``0`` times:

    ::

        >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 0)
        ()

    Returns newly constructed `sequence` object of copied `sequence` elements.
    '''

    if not mathtools.is_nonnegative_integer(n):
        message = 'must be nonnegative integer: {!r}.'
        message = message.format(n)
        raise ValueError(message)

    result = []
    for x in range(n):
        for element in sequence:
            result.append(copy.copy(element))
    return type(sequence)(result)
    def repeat_to_length(self, length):
        r'''Repeat payload to `length`.

        Returns copy of expression with callback.
        '''
        assert mathtools.is_nonnegative_integer(length)
        callback = 'result = self._repeat_to_length(payload_expression, {!r})'
        callback = callback.format(length)
        return self._copy_and_append_callback(callback)
Exemple #6
0
    def repeat_to_length(self, length):
        r'''Repeat payload to `length`.

        Returns copy of expression with callback.
        '''
        assert mathtools.is_nonnegative_integer(length)
        callback = 'result = self._repeat_to_length(payload_expression, {!r})'
        callback = callback.format(length)
        return self._copy_and_append_callback(callback)
def repeat_sequence_to_length(sequence, length, start=0):
    '''Repeats `sequence` to nonnegative integer `length`.

    ..  container:: example

        **Example 1.** Repeats list to length 11:

        ::

            >>> sequencetools.repeat_sequence_to_length(list(range(5)), 11)
            [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0]

    ..  container:: example

        **Example 2.** Repeats `sequence` to nonnegative integer `length` from
        `start`:

        ::

            >>> sequencetools.repeat_sequence_to_length(
            ...     list(range(5)), 11, start=2)
            [2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2]

        **Example 3.** Repeats tuple to length 11:

        ::

            >>> sequencetools.repeat_sequence_to_length(tuple(range(5)), 11)
            (0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0)

    Copies `sequence` element references; does not copy `sequence` elements.

    Returns new object of `sequence` type.
    '''

    if not isinstance(sequence, collections.Sequence):
        message = 'must by sequence {!r}.'
        message = message.format(sequence)
        raise Exception(message)

    sequence_type = type(sequence)

    if not mathtools.is_nonnegative_integer(length):
        raise TypeError
    if len(sequence) <= 0:
        raise ValueError

    result = []
    start %= len(sequence)
    stop_index = start + length
    repetitions = int(math.ceil(float(stop_index) / len(sequence)))
    for x in range(repetitions):
        for element in sequence:
            result.append(element)

    return sequence_type(result[start:stop_index])
def repeat_sequence_to_length(sequence, length, start=0):
    '''Repeats `sequence` to nonnegative integer `length`.

    ..  container:: example

        **Example 1.** Repeats list to length 11:

        ::

            >>> sequencetools.repeat_sequence_to_length(list(range(5)), 11)
            [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0]

    ..  container:: example

        **Example 2.** Repeats `sequence` to nonnegative integer `length` from
        `start`:

        ::

            >>> sequencetools.repeat_sequence_to_length(
            ...     list(range(5)), 11, start=2)
            [2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2]

        **Example 3.** Repeats tuple to length 11:

        ::

            >>> sequencetools.repeat_sequence_to_length(tuple(range(5)), 11)
            (0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0)

    Copies `sequence` element references; does not copy `sequence` elements.

    Returns new object of `sequence` type.
    '''

    if not isinstance(sequence, collections.Sequence):
        message = 'must by sequence {!r}.'
        message = message.format(sequence)
        raise Exception(message)

    sequence_type = type(sequence)

    if not mathtools.is_nonnegative_integer(length):
        raise TypeError
    if len(sequence) <= 0:
        raise ValueError

    result = []
    start %= len(sequence)
    stop_index = start + length
    repetitions = int(math.ceil(float(stop_index) / len(sequence)))
    for x in range(repetitions):
        for element in sequence:
            result.append(element)

    return sequence_type(result[start:stop_index])
Exemple #9
0
 def _make_score_number_markup(
     configuration_number,
     score_number,
     ):
     assert mathtools.is_nonnegative_integer(configuration_number)
     assert mathtools.is_nonnegative_integer(score_number)
     number_string = '{}-{}'.format(
         configuration_number,
         score_number,
         )
     command = markuptools.MarkupCommand('fontsize', 2, number_string)
     command = markuptools.MarkupCommand('italic', command)
     command = markuptools.MarkupCommand('box', command)
     pair = schemetools.SchemePair('box-padding', 0.75)
     command = markuptools.MarkupCommand('override', pair, command)
     width = 9
     command = markuptools.MarkupCommand('hcenter-in', width, command)
     markup = markuptools.Markup(command)
     return markup
Exemple #10
0
 def _make_score_number_markup(
     configuration_number,
     score_number,
 ):
     assert mathtools.is_nonnegative_integer(configuration_number)
     assert mathtools.is_nonnegative_integer(score_number)
     number_string = '{}-{}'.format(
         configuration_number,
         score_number,
     )
     command = markuptools.MarkupCommand('fontsize', 2, number_string)
     command = markuptools.MarkupCommand('italic', command)
     command = markuptools.MarkupCommand('box', command)
     pair = schemetools.SchemePair('box-padding', 0.75)
     command = markuptools.MarkupCommand('override', pair, command)
     width = 9
     command = markuptools.MarkupCommand('hcenter-in', width, command)
     markup = markuptools.Markup(command)
     return markup
Exemple #11
0
def repeat_sequence(sequence, n):
    '''Repeats `sequence` `n` times.

    ..  container:: example

        **Example 1.** Repeats tuple three times:

        ::

            >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 3)
            (1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)

    ..  container:: example

        **Example 2.** Repeats tuple zero times:

        ::

            >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 0)
            ()

    ..  container:: example

        **Example 3.** Repeats list three times:

        ::

            >>> sequencetools.repeat_sequence([1, 2, 3, 4, 5], 3)
            [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

    Repeats references to `sequence` elements; does not copy `sequence`
    elements.

    Returns new object of `sequence` type.
    '''

    if not isinstance(sequence, collections.Sequence):
        message = 'must by sequence {!r}.'
        message = message.format(sequence)
        raise Exception(message)

    sequence_type = type(sequence)

    if not mathtools.is_nonnegative_integer(n):
        message = 'must be nonnegative integer: {!r}.'
        message = message.format(n)
        raise ValueError(message)

    result = []
    for x in range(n):
        for element in sequence:
            result.append(element)

    result = sequence_type(result)
    return result
def repeat_sequence(sequence, n):
    '''Repeats `sequence` `n` times.

    ..  container:: example

        **Example 1.** Repeats tuple three times:

        ::

            >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 3)
            (1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)

    ..  container:: example

        **Example 2.** Repeats tuple zero times:

        ::

            >>> sequencetools.repeat_sequence((1, 2, 3, 4, 5), 0)
            ()

    ..  container:: example

        **Example 3.** Repeats list three times:

        ::

            >>> sequencetools.repeat_sequence([1, 2, 3, 4, 5], 3)
            [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

    Repeats references to `sequence` elements; does not copy `sequence`
    elements.

    Returns new object of `sequence` type.
    '''

    if not isinstance(sequence, collections.Sequence):
        message = 'must by sequence {!r}.'
        message = message.format(sequence)
        raise Exception(message)

    sequence_type = type(sequence)

    if not mathtools.is_nonnegative_integer(n):
        message = 'must be nonnegative integer: {!r}.'
        message = message.format(n)
        raise ValueError(message)

    result = []
    for x in range(n):
        for element in sequence:
            result.append(element)

    result = sequence_type(result)
    return result
Exemple #13
0
def test_mathtools_is_nonnegative_integer_01():

    assert mathtools.is_nonnegative_integer(1)
    assert mathtools.is_nonnegative_integer(int(1))
    assert mathtools.is_nonnegative_integer(Duration(1, 1))
    assert mathtools.is_nonnegative_integer(1.0)
    assert mathtools.is_nonnegative_integer(True)
    assert mathtools.is_nonnegative_integer(0)
    assert mathtools.is_nonnegative_integer(False)
 def __init__(
     self,
     denominator_multiplier_exponent=0,
     beam_each_cell=True,
     beam_cells_together=False,
     ):
     assert mathtools.is_nonnegative_integer(
         denominator_multiplier_exponent)
     RhythmMaker.__init__(self,
         beam_each_cell=beam_each_cell,
         beam_cells_together=beam_cells_together
         )
     self._denominator_multiplier_exponent = \
         denominator_multiplier_exponent
 def __init__(
     self,
     exponent=None,
     beam_specifier=None,
     duration_spelling_specifier=None,
     tie_specifier=None,
     ):
     if exponent is not None:
         assert mathtools.is_nonnegative_integer(exponent)
     RhythmMaker.__init__(
         self,
         beam_specifier=beam_specifier,
         duration_spelling_specifier=duration_spelling_specifier,
         tie_specifier=tie_specifier,
         )
     self._exponent = exponent
Exemple #16
0
 def __init__(
     self,
     exponent=None,
     beam_specifier=None,
     duration_spelling_specifier=None,
     tie_specifier=None,
     tuplet_spelling_specifier=None,
 ):
     if exponent is not None:
         assert mathtools.is_nonnegative_integer(exponent)
     RhythmMaker.__init__(
         self,
         beam_specifier=beam_specifier,
         duration_spelling_specifier=duration_spelling_specifier,
         tie_specifier=tie_specifier,
         tuplet_spelling_specifier=tuplet_spelling_specifier,
     )
     self._exponent = exponent
Exemple #17
0
 def __init__(
     self,
     denominator_multiplier_exponent=0,
     beam_cells_together=False,
     beam_each_cell=True,
     decrease_durations_monotonically=True,
     forbidden_written_duration=None,
     ):
     assert mathtools.is_nonnegative_integer(
         denominator_multiplier_exponent)
     RhythmMaker.__init__(
         self,
         beam_cells_together=beam_cells_together,
         beam_each_cell=beam_each_cell,
         decrease_durations_monotonically=decrease_durations_monotonically,
         forbidden_written_duration=forbidden_written_duration,
         )
     self._denominator_multiplier_exponent = \
         denominator_multiplier_exponent
def repeat_sequence_elements_n_times_each(sequence, n):
    '''Repeat `sequence` elements `n` times each:

    ::

        >>> sequencetools.repeat_sequence_elements_n_times_each((1, -1, 2, -3, 5, -5, 6), 2)
        (1, 1, -1, -1, 2, 2, -3, -3, 5, 5, -5, -5, 6, 6)

    Returns newly constructed `sequence` object with copied `sequence` elements.
    '''

    if not mathtools.is_nonnegative_integer(n):
        raise ValueError

    result = []
    for element in sequence:
        for x in range(n):
            result.append(copy.copy(element))
    return type(sequence)(result)
def all_are_nonnegative_integers(argument):
    '''Is true when `argument` is an iterable collection of nonnegative
    integers. Otherwise false.

    ..  container:: example

        >>> abjad.mathtools.all_are_nonnegative_integers([0, 1, 2, 99])
        True

        >>> abjad.mathtools.all_are_nonnegative_integers([0, 1, 2, -99])
        False

    Returns true or false.
    '''
    from abjad.tools import mathtools
    try:
        return all(mathtools.is_nonnegative_integer(_) for _ in argument)
    except TypeError:
        return False
def all_are_nonnegative_integers(expr):
    '''True when `expr` is a sequence and all elements  in `expr` are nonnegative integers:

    ::

        >>> sequencetools.all_are_nonnegative_integers([0, 1, 2, 99])
        True

    Otherwise false:

    ::

        >>> sequencetools.all_are_nonnegative_integers([0, 1, 2, -99])
        False

    Returns boolean.
    '''

    try:
        return all(mathtools.is_nonnegative_integer(x) for x in expr)
    except TypeError:
        return False
def all_are_nonnegative_integers(expr):
    '''Is true when `expr` is a sequence and all elements  in `expr`
    are nonnegative integers.

    ::

        >>> mathtools.all_are_nonnegative_integers([0, 1, 2, 99])
        True

    Otherwise false:

    ::

        >>> mathtools.all_are_nonnegative_integers([0, 1, 2, -99])
        False

    Returns true or false.
    '''
    from abjad.tools import mathtools

    try:
        return all(mathtools.is_nonnegative_integer(x) for x in expr)
    except TypeError:
        return False
Exemple #22
0
def test_mathtools_is_nonnegative_integer_02():

    assert not mathtools.is_nonnegative_integer(-99)
Exemple #23
0
def test_mathtools_is_nonnegative_integer_03():

    assert not mathtools.is_nonnegative_integer('foo')