Exemple #1
0
 def __init__(self, numbers=(1, 1)):
     from abjad.tools import mathtools
     if isinstance(numbers, type(self)):
         numbers = numbers.numbers
     numbers = [int(_) for _ in numbers]
     gcd = mathtools.greatest_common_divisor(*numbers)
     numbers = [_ // gcd for _ in numbers]
     self._numbers = tuple(numbers)
Exemple #2
0
 def __init__(self, numbers=(1, 1)):
     from abjad.tools import mathtools
     if isinstance(numbers, type(self)):
         numbers = numbers.numbers
     numbers = [int(_) for _ in numbers]
     gcd = mathtools.greatest_common_divisor(*numbers)
     numbers = [_ // gcd for _ in numbers]
     self._numbers = tuple(numbers)
Exemple #3
0
 def __init__(self, numbers=(1, 1)):
     from abjad.tools import mathtools
     if isinstance(numbers, type(self)):
         numbers = numbers.numbers
     numbers = [int(_) for _ in numbers]
     gcd = mathtools.greatest_common_divisor(*numbers)
     numbers = [_ // gcd for _ in numbers]
     superclass = super(Ratio, self)
     superclass.__init__(numbers=numbers, )
Exemple #4
0
 def __init__(self, items=(1, 1), item_class=None):
     from abjad.tools import mathtools
     items = [int(_) for _ in items]
     gcd = mathtools.greatest_common_divisor(*items)
     items = [_ // gcd for _ in items]
     superclass = super(Ratio, self)
     superclass.__init__(
         items=items,
         )
Exemple #5
0
 def __init__(self, numbers=(1, 1)):
     from abjad.tools import mathtools
     if isinstance(numbers, type(self)):
         numbers = numbers.numbers
     numbers = [int(_) for _ in numbers]
     gcd = mathtools.greatest_common_divisor(*numbers)
     numbers = [_ // gcd for _ in numbers]
     superclass = super(Ratio, self)
     superclass.__init__(
         numbers=numbers,
         )
Exemple #6
0
 def __new__(cls, *args):
     from abjad.tools import mathtools
     if len(args) == 1 and isinstance(args[0], (list, tuple)):
         args = args[0]
     elif len(args) == 0:
         args = (1, 1)
     assert args, repr(args)
     assert all(x != 0 for x in args), repr(args)
     gcd = mathtools.greatest_common_divisor(*args)
     args = [x / gcd for x in args]
     self = NonreducedRatio.__new__(cls, args)
     return self
Exemple #7
0
 def __new__(cls, *args):
     from abjad.tools import mathtools
     if len(args) == 1 and isinstance(args[0], collections.Sequence):
         args = args[0]
     elif len(args) == 0:
         args = (1, 1)
     assert args, repr(args)
     assert all(x != 0 for x in args), repr(args)
     gcd = mathtools.greatest_common_divisor(*args)
     args = [x // gcd for x in args]
     self = NonreducedRatio.__new__(cls, args)
     return self
def test_mathtools_greatest_common_divisor_01():
    r'''Greatest common integer divisor of integers.
    '''

    assert mathtools.greatest_common_divisor(84, -96, -144) == 12
    assert mathtools.greatest_common_divisor(84, 85) == 1
    assert mathtools.greatest_common_divisor(-84) == 84
    assert mathtools.greatest_common_divisor(6, 8, 12) == 2
    assert mathtools.greatest_common_divisor(-8, -12) == 4
    assert mathtools.greatest_common_divisor(11, 12) == 1
def divide_sequence_elements_by_greatest_common_divisor(sequence):
    '''Divide `sequence` elements by greatest common divisor:

    ::

        >>> sequencetools.divide_sequence_elements_by_greatest_common_divisor([2, 2, -8, -16])
        [1, 1, -4, -8]

    Allow negative `sequence` elements.

    Raise type error on noninteger `sequence` elements.

    Raise not implemented error when ``0`` in `sequence`.

    Returns new `sequence` object.
    '''

    gcd = mathtools.greatest_common_divisor(*sequence)
    result = [element / gcd for element in sequence]
    return type(sequence)(result)