MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

maths/radix2_fft.py:52–79  ·  view source on GitHub ↗
(self, poly_a=None, poly_b=None)

Source from the content-addressed store, hash-verified

50 """
51
52 def __init__(self, poly_a=None, poly_b=None):
53 # Input as list
54 self.polyA = list(poly_a or [0])[:]
55 self.polyB = list(poly_b or [0])[:]
56
57 # Remove leading zero coefficients
58 while self.polyA[-1] == 0:
59 self.polyA.pop()
60 self.len_A = len(self.polyA)
61
62 while self.polyB[-1] == 0:
63 self.polyB.pop()
64 self.len_B = len(self.polyB)
65
66 # Add 0 to make lengths equal a power of 2
67 self.c_max_length = int(
68 2 ** np.ceil(np.log2(len(self.polyA) + len(self.polyB) - 1))
69 )
70
71 while len(self.polyA) < self.c_max_length:
72 self.polyA.append(0)
73 while len(self.polyB) < self.c_max_length:
74 self.polyB.append(0)
75 # A complex root used for the fourier transform
76 self.root = complex(mpmath.root(x=1, n=self.c_max_length, k=1))
77
78 # The product
79 self.product = self.__multiply()
80
81 # Discrete fourier transform of A and B
82 def __dft(self, which):

Callers

nothing calls this directly

Calls 4

__multiplyMethod · 0.95
ceilMethod · 0.80
popMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected