@@ -26,25 +26,22 @@ def preprocess_text_and_pattern(text: str, pattern: str) -> tuple[list[int], lis
2626
2727 return text_int , pattern_int
2828
29- def fft_convolution (a : list [int ], b : list [int ]) -> np .ndarray :
29+ def fft_convolution (first_seq : list [int ], second_seq : list [int ]) -> np .ndarray :
3030 """Performs convolution using the Fast Fourier Transform (FFT).
3131
3232 Args:
33- a : The first sequence.
33+ first_seq : The first sequence.
3434 b: The second sequence.
3535
3636 Returns:
3737 The convolution of the two sequences.
3838 """
39- n = len (a ) + len (b ) - 1
40- a_fft = fft (a , n )
41- b_fft = fft (b , n )
42- return np .real (ifft (a_fft * b_fft ))
39+ n = len (first_seq ) + len (second_seq ) - 1
40+ first_seq_fft = fft (first_seq , n )
41+ second_seq_fft = fft (second_seq , n )
42+ return np .real (ifft (first_seq_fft * second_seq_fft ))
43+
4344
44- n = len (input_seq_a ) + len (input_seq_b ) - 1
45- A = fft (input_seq_a , n )
46- B = fft (input_seq_b , n )
47- return np .real (ifft (A * B ))
4845
4946
5047def compute_a_fft (text_int : list [int ], pattern_int : list [int ]) -> np .ndarray :
@@ -86,6 +83,13 @@ def compute_a_fft(text_int: list[int], pattern_int: list[int]) -> np.ndarray:
8683# Main function to run the matching
8784if __name__ == "__main__" :
8885 # Example test case
86+ import doctest
87+ doctest .testmod ()
88+ # Get text and pattern as input from the user
89+ # text = input("Enter the text: ")
90+ # pattern = input("Enter the pattern (use '*' for wildcard): ")
91+
92+
8993 text = "abcabc"
9094 pattern = "abc*"
9195
0 commit comments