-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simply FFT roundtrip speed test.
1 second for 2560x6000 along axis 1
- Loading branch information
1 parent
e85e8ec
commit 2ec31c4
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy | ||
|
||
def roundtrip(wave, size): | ||
nchan, ntick = wave.shape | ||
|
||
if size == ntick: | ||
return wave | ||
|
||
spec = numpy.fft.fft(wave, axis=1) | ||
spec = numpy.fft.ifftshift(spec) | ||
|
||
# note: this is not quite right but good enough for speed | ||
if size < ntick: # downsample | ||
half = (ntick-size)//2 | ||
spec = spec[:, half:-half] | ||
else: # upsample | ||
half = (size-ntick)//2 | ||
spec = numpy.hstack( (numpy.zeros((nchan,half), dtype=spec.dtype), | ||
spec, | ||
numpy.zeros((nchan,half), dtype=spec.dtype)) ) | ||
spec = numpy.fft.fftshift(spec) | ||
wave = numpy.real(numpy.fft.ifft(spec)) | ||
return wave * wave.shape[1] / ntick | ||
|
||
import timeit | ||
def main(filename, size): | ||
f = numpy.load(filename) | ||
fr = f[f.files[0]] | ||
|
||
def runit(): | ||
roundtrip(fr, size) | ||
|
||
got = timeit.timeit(runit, number=10) | ||
print(got) | ||
|
||
if '__main__' == __name__: | ||
import sys | ||
try: | ||
size = int(sys.argv[2]) | ||
except IndexError: | ||
size = 6144 | ||
|
||
main(sys.argv[1], int(sys.argv[2])) | ||
|