-
Notifications
You must be signed in to change notification settings - Fork 2
Fixed #22 Propose new pyfftw_sdp #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NimaSarajpoor
wants to merge
21
commits into
main
Choose a base branch
from
challenge_pyfftw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−33
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
59b49e1
propose revised pyfftw in challenger
NimaSarajpoor c8074a2
minor fix
NimaSarajpoor bb8b9ea
update files
NimaSarajpoor aa592db
improve comments
NimaSarajpoor d8f0423
fix black formating
NimaSarajpoor 73447a7
addressed comments
NimaSarajpoor 47ec8b7
fixed unnecessary import
NimaSarajpoor c2d5247
add comment to improve clarity
NimaSarajpoor 4014bf8
addressed comments
NimaSarajpoor f9d4bb3
increase the default value of max_n parameter
NimaSarajpoor 1f1bae6
added test function
NimaSarajpoor 6954b31
renamed test function
NimaSarajpoor 1acd761
fixed minor issue
NimaSarajpoor f013dd7
minor change
NimaSarajpoor 20318d9
Revised comment
NimaSarajpoor c79ea81
addressed comments
NimaSarajpoor 70bf879
minor changes
NimaSarajpoor b259eae
minor change in docstring
NimaSarajpoor a419895
minor change in docstring
NimaSarajpoor c358de9
add comment to test function to show its purpose
NimaSarajpoor 28b1b75
avoid tracking len(T) via attribute
NimaSarajpoor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,75 @@ | ||
| import pyfftw | ||
| import numpy as np | ||
|
|
||
|
|
||
| class SLIDING_DOT_PRODUCT: | ||
| # https://stackoverflow.com/a/30615425/2955541 | ||
| def __init__(self): | ||
| self.m = 0 | ||
| self.n = 0 | ||
| self.shape = 0 | ||
| self.threads = 1 | ||
|
|
||
| def __call__(self, Q, T): | ||
| self.m = Q.shape[0] | ||
|
|
||
| need_new_obj = False | ||
| if self.n != T.shape[0]: | ||
| # need to re-compute shape | ||
| self.n = T.shape[0] | ||
| shape = pyfftw.next_fast_len(self.n) | ||
| if self.shape != shape: | ||
| self.shape = shape | ||
| need_new_obj = True | ||
|
|
||
| if need_new_obj: | ||
| # create input and output arrays and FFTW objects | ||
| self.real_arr = pyfftw.empty_aligned(self.shape, dtype="float64") | ||
| self.complex_arr = pyfftw.empty_aligned( | ||
| 1 + self.shape // 2, dtype="complex128" | ||
| ) | ||
|
|
||
| self.rfft_obj = pyfftw.FFTW( | ||
| input_array=self.real_arr, | ||
| output_array=self.complex_arr, | ||
| flags=("FFTW_MEASURE",), | ||
| direction="FFTW_FORWARD", | ||
| threads=self.threads, | ||
| ) | ||
|
|
||
| self.irfft_obj = pyfftw.FFTW( | ||
| input_array=self.complex_arr, | ||
| output_array=self.real_arr, | ||
| flags=("FFTW_MEASURE", "FFTW_DESTROY_INPUT"), | ||
| direction="FFTW_BACKWARD", | ||
| threads=self.threads, | ||
| ) | ||
|
|
||
| # RFFT(T) | ||
| self.real_arr[: self.n] = T | ||
| self.real_arr[self.n : self.shape] = 0.0 | ||
| self.rfft_obj.execute() # output is in self.complex_arr | ||
| complex_arr_T = self.complex_arr.copy() | ||
|
|
||
| # RFFT(Q) | ||
| self.real_arr[: self.m] = Q[::-1] / self.shape # reversed Q and scale | ||
| self.real_arr[self.m : self.shape] = 0.0 | ||
| self.rfft_obj.execute() # output is in self.complex_arr | ||
|
|
||
| # RFFT(T) * RFFT(Q) | ||
| np.multiply(self.complex_arr, complex_arr_T, out=self.complex_arr) | ||
| self.irfft_obj.execute() # output is in self.real_arr | ||
|
|
||
| return self.real_arr[self.m - 1 : self.n] | ||
|
|
||
|
|
||
| _sliding_dot_product = SLIDING_DOT_PRODUCT() | ||
|
|
||
|
|
||
| def setup(Q, T): | ||
| _sliding_dot_product(Q, T) | ||
| return | ||
|
|
||
|
|
||
| def sliding_dot_product(Q, T): | ||
| m = len(Q) | ||
| l = T.shape[0] - m + 1 | ||
| out = np.empty(l) | ||
| for i in range(l): | ||
| out[i] = np.dot(Q, T[i : i + m]) | ||
| return out | ||
| return _sliding_dot_product(Q, T) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.