def setup(A, B): """ Prepares two Patterns, A & B, for correct use in operands""" #A, B = copy(A), copy(B) cls = Base.Dominant(A, B) A, B = cls(A), cls(B) length = LCM(len(A), len(B)) A.stretch(length) B.stretch(length) return A, B
def __call__(self, A, B): """ A is always a pattern. """ # If the first pattern is empty, return the other as a pattern if len(A) == 0: return Base.Pattern(B) # Get the dominant pattern type and convert B cls = Base.Dominant(A, B) A = cls(A) B = cls(B) # Calculate total length before operations i, length = 0, LCM(len(A), len(B)) P1 = [] while i < length: try: val = self.operate(A[i], B[i]) except ZeroDivisionError: val = 0 P1.append(val) i += 1 return cls(P1)