-
Notifications
You must be signed in to change notification settings - Fork 349
Add pyfftw sdp #1132
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
base: main
Are you sure you want to change the base?
Add pyfftw sdp #1132
Changes from all commits
87dfcdb
ae90507
6051ab4
0a3427e
58d99e2
0e82fbf
db09a61
73d8229
61d8351
96b68b5
2ebbac1
ec3744d
22e5a55
7e75ade
68d767c
d6fda46
51a21eb
de9cade
e5bf50e
a050a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -70,8 +70,10 @@ | |||||||
|
|
||||||||
| def get_sdp_function_names(): | ||||||||
| out = [] | ||||||||
| for func_name, func in inspect.getmembers(sdp, inspect.isfunction): | ||||||||
| if func_name.endswith("sliding_dot_product"): | ||||||||
| for func_name, func in inspect.getmembers(sdp, callable): | ||||||||
| if func_name.endswith("sliding_dot_product") and inspect.signature( | ||||||||
| func | ||||||||
| ).parameters.keys() >= {"Q", "T"}: | ||||||||
| out.append(func_name) | ||||||||
|
|
||||||||
| return out | ||||||||
|
|
@@ -152,3 +154,84 @@ def test_sdp_power2(): | |||||||
| raise e | ||||||||
|
|
||||||||
| return | ||||||||
|
|
||||||||
|
|
||||||||
| def test_pyfftw_sdp_max_n(): | ||||||||
| if not sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||||||||
| pytest.skip("Skipping Test pyFFTW Not Installed") | ||||||||
|
|
||||||||
| # When `len(T)` larger than `real_arr` in pyfftw_sdp, | ||||||||
| # the internal preallocated arrays should be resized. | ||||||||
| # This test checks that functionality. | ||||||||
|
|
||||||||
| max_n = 2**10 | ||||||||
| _pyfftw_sliding_dot_product = sdp._make_pyfftw_sliding_dot_product( | ||||||||
| max_n=max_n, real_dtype="float64" | ||||||||
| ) | ||||||||
|
|
||||||||
| # len(T) > max_n to trigger array resizing | ||||||||
| T = np.random.rand(max_n + 1) | ||||||||
| Q = np.random.rand(2**2) | ||||||||
|
|
||||||||
| comp = _pyfftw_sliding_dot_product(Q, T) | ||||||||
| ref = naive.rolling_window_dot_product(Q, T) | ||||||||
|
|
||||||||
| np.testing.assert_allclose(comp, ref) | ||||||||
|
|
||||||||
| return | ||||||||
|
|
||||||||
|
|
||||||||
| def test_pyfftw_sdp_longdoube(): | ||||||||
| if not sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||||||||
| pytest.skip("Skipping Test pyFFTW Not Installed") | ||||||||
|
|
||||||||
| # This test checks that the pyfftw_sdp can be initialized with longdouble data type | ||||||||
| max_n = 2**10 | ||||||||
| sdp_func = sdp._make_pyfftw_sliding_dot_product(max_n, real_dtype="longdouble") | ||||||||
|
|
||||||||
| T = np.random.rand(max_n) | ||||||||
| Q = np.random.rand(2**8) | ||||||||
|
|
||||||||
| comp = sdp_func(Q, T) | ||||||||
| ref = naive.rolling_window_dot_product(Q, T) | ||||||||
|
|
||||||||
| np.testing.assert_allclose(comp, ref) | ||||||||
|
|
||||||||
| return | ||||||||
|
|
||||||||
|
|
||||||||
| def test_pyfftw_sdp_multithreaded(): | ||||||||
| if not sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||||||||
| pytest.skip("Skipping Test pyFFTW Not Installed") | ||||||||
|
|
||||||||
| # This test checks that the pyfftw_sdp can be initialized | ||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| # with multiple threads | ||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| T = np.random.rand(2**5) | ||||||||
| Q = np.random.rand(2**4) | ||||||||
|
|
||||||||
| comp = sdp._pyfftw_sliding_dot_product(Q, T, n_threads=2) | ||||||||
| ref = naive.rolling_window_dot_product(Q, T) | ||||||||
|
|
||||||||
| np.testing.assert_allclose(comp, ref) | ||||||||
|
|
||||||||
| return | ||||||||
|
|
||||||||
|
|
||||||||
| def test_pyfftw_sdp_multithreaded_longdouble(): | ||||||||
| if not sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||||||||
| pytest.skip("Skipping Test pyFFTW Not Installed") | ||||||||
|
|
||||||||
| # This test checks that the pyfftw_sdp can be initialized | ||||||||
| # with multiple threads and longdouble data type | ||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note that the number of threads is not set when the instance is created |
||||||||
| max_n = 2**10 | ||||||||
| sdp_func = sdp._make_pyfftw_sliding_dot_product(max_n, real_dtype="longdouble") | ||||||||
|
|
||||||||
| T = np.random.rand(max_n) | ||||||||
| Q = np.random.rand(2**8) | ||||||||
|
|
||||||||
| comp = sdp_func(Q, T, n_threads=2) | ||||||||
| ref = naive.rolling_window_dot_product(Q, T) | ||||||||
|
|
||||||||
| np.testing.assert_allclose(comp, ref) | ||||||||
|
|
||||||||
| return | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment here that says: "The name of any callable object that computes the sliding dot product should end with
sliding_dot_product"