@@ -26,25 +26,22 @@ def preprocess_text_and_pattern(text: str, pattern: str) -> tuple[list[int], lis
26
26
27
27
return text_int , pattern_int
28
28
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 :
30
30
"""Performs convolution using the Fast Fourier Transform (FFT).
31
31
32
32
Args:
33
- a : The first sequence.
33
+ first_seq : The first sequence.
34
34
b: The second sequence.
35
35
36
36
Returns:
37
37
The convolution of the two sequences.
38
38
"""
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
+
43
44
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 ))
48
45
49
46
50
47
def 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:
86
83
# Main function to run the matching
87
84
if __name__ == "__main__" :
88
85
# 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
+
89
93
text = "abcabc"
90
94
pattern = "abc*"
91
95
0 commit comments