|
| 1 | +"""Benchmarks for 1-D FFT operations using the mkl_fft root API.""" |
| 2 | + |
| 3 | +import mkl_fft |
| 4 | + |
| 5 | +from ._utils import _DTYPES_ALL, _DTYPES_REAL, BenchC2C, BenchR2C |
| 6 | + |
| 7 | +_SIZES_POW2 = [64, 256, 1024, 4096, 16384, 65536] |
| 8 | +_SIZES_NONPOW2 = [127, 509, 1000, 4001, 10007] |
| 9 | + |
| 10 | + |
| 11 | +# --------------------------------------------------------------------------- |
| 12 | +# Complex-to-complex 1-D (power-of-two sizes) |
| 13 | +# --------------------------------------------------------------------------- |
| 14 | + |
| 15 | + |
| 16 | +class BenchFFT1D(BenchC2C): |
| 17 | + """Forward and inverse complex FFT — power-of-two sizes.""" |
| 18 | + |
| 19 | + params = [_SIZES_POW2, _DTYPES_ALL] |
| 20 | + param_names = ["n", "dtype"] |
| 21 | + |
| 22 | + def setup(self, n, dtype): |
| 23 | + super().setup(n, dtype) |
| 24 | + # prime MKL DFTI descriptor cache |
| 25 | + mkl_fft.fft(self.x) |
| 26 | + mkl_fft.ifft(self.x) |
| 27 | + |
| 28 | + def time_fft(self, n, dtype): |
| 29 | + mkl_fft.fft(self.x) |
| 30 | + |
| 31 | + def time_ifft(self, n, dtype): |
| 32 | + mkl_fft.ifft(self.x) |
| 33 | + |
| 34 | + |
| 35 | +# --------------------------------------------------------------------------- |
| 36 | +# Real-to-complex / complex-to-real 1-D (power-of-two sizes) |
| 37 | +# --------------------------------------------------------------------------- |
| 38 | + |
| 39 | + |
| 40 | +class BenchRFFT1D(BenchR2C): |
| 41 | + """Forward rfft and inverse irfft — power-of-two sizes.""" |
| 42 | + |
| 43 | + params = [_SIZES_POW2, _DTYPES_REAL] |
| 44 | + param_names = ["n", "dtype"] |
| 45 | + |
| 46 | + def setup(self, n, dtype): |
| 47 | + super().setup(n, dtype) |
| 48 | + mkl_fft.rfft(self.x_real) |
| 49 | + mkl_fft.irfft(self.x_complex, n=n) |
| 50 | + |
| 51 | + def time_rfft(self, n, dtype): |
| 52 | + mkl_fft.rfft(self.x_real) |
| 53 | + |
| 54 | + def time_irfft(self, n, dtype): |
| 55 | + mkl_fft.irfft(self.x_complex, n=n) |
| 56 | + |
| 57 | + |
| 58 | +# --------------------------------------------------------------------------- |
| 59 | +# Complex-to-complex 1-D (non-power-of-two sizes) |
| 60 | +# --------------------------------------------------------------------------- |
| 61 | + |
| 62 | + |
| 63 | +class BenchFFT1DNonPow2(BenchC2C): |
| 64 | + """Forward and inverse complex FFT — non-power-of-two sizes. |
| 65 | +
|
| 66 | + MKL uses a different code path for non-power-of-two transforms; |
| 67 | + this suite catches regressions in that path. |
| 68 | + """ |
| 69 | + |
| 70 | + params = [_SIZES_NONPOW2, _DTYPES_ALL] |
| 71 | + param_names = ["n", "dtype"] |
| 72 | + |
| 73 | + def setup(self, n, dtype): |
| 74 | + super().setup(n, dtype) |
| 75 | + mkl_fft.fft(self.x) |
| 76 | + mkl_fft.ifft(self.x) |
| 77 | + |
| 78 | + def time_fft(self, n, dtype): |
| 79 | + mkl_fft.fft(self.x) |
| 80 | + |
| 81 | + def time_ifft(self, n, dtype): |
| 82 | + mkl_fft.ifft(self.x) |
| 83 | + |
| 84 | + |
| 85 | +# --------------------------------------------------------------------------- |
| 86 | +# Real-to-complex / complex-to-real 1-D (non-power-of-two sizes) |
| 87 | +# --------------------------------------------------------------------------- |
| 88 | + |
| 89 | + |
| 90 | +class BenchRFFT1DNonPow2(BenchR2C): |
| 91 | + """Forward rfft and inverse irfft — non-power-of-two sizes.""" |
| 92 | + |
| 93 | + params = [_SIZES_NONPOW2, _DTYPES_REAL] |
| 94 | + param_names = ["n", "dtype"] |
| 95 | + |
| 96 | + def setup(self, n, dtype): |
| 97 | + super().setup(n, dtype) |
| 98 | + mkl_fft.rfft(self.x_real) |
| 99 | + mkl_fft.irfft(self.x_complex, n=n) |
| 100 | + |
| 101 | + def time_rfft(self, n, dtype): |
| 102 | + mkl_fft.rfft(self.x_real) |
| 103 | + |
| 104 | + def time_irfft(self, n, dtype): |
| 105 | + mkl_fft.irfft(self.x_complex, n=n) |
0 commit comments