Repository navigation
Fixed #1111 Add branching logic for sdp #1200
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?
Changes from 1 commit
b2221b1
5450557
61bd5b7
d01573d
a3538d1
6a48340
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -648,33 +648,85 @@ def check_window_size(m, max_size=None, n=None): | |
| warnings.warn(msg) | ||
|
|
||
|
|
||
| def sliding_dot_product(Q, T): | ||
| def make_sliding_dot_product(boundaries=None, default_func=None): | ||
| """ | ||
| Calculate the sliding window dot product. | ||
| A closure to compute the sliding dot product that allows users | ||
| to use different methods in different cases | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Q : numpy.ndarray | ||
| Query array or subsequence | ||
|
|
||
| T : numpy.ndarray | ||
| Time series or sequence | ||
| boundaries : nested list | ||
| A list of items, where each item is a list of 3 elements: | ||
| * index 0: (LB_m, UB_m) | ||
| * index 1: (LB_n, UB_n) | ||
| * index 2: func | ||
| where, fucn is the sdp function for computing | ||
| the sliding dot product of ``Q`` and ``T``, when | ||
| m=len(Q) falls into [LB_m, UB_m], and n=len(T) falls | ||
| into [LB_n, UB_n]. | ||
|
|
||
| default_func : class 'function' | ||
| A callable object for | ||
|
|
||
| Returns | ||
| ------- | ||
| output : numpy.ndarray | ||
| Sliding dot product between `Q` and `T`. | ||
| """ | ||
| if len(Q) == len(T): | ||
| out = np.array([np.dot(Q, T)]) | ||
| elif len(Q) <= config.STUMPY_NJIT_SDP_Q_LENGTH: | ||
| out = sdp._njit_sliding_dot_product(Q, T) | ||
| elif sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||
| out = sdp._pyfftw_sliding_dot_product(Q, T) | ||
| else: | ||
| out = sdp._sliding_dot_product(Q, T) | ||
| stumpy_default_func = sdp._sliding_dot_product | ||
| if sdp.PYFFTW_IS_AVAILABLE: # pragma: no cover | ||
| stumpy_default_func = sdp._pyfftw_sliding_dot_product | ||
|
|
||
| return out | ||
| if default_func is None: | ||
| default_func = stumpy_default_func | ||
|
|
||
| if boundaries is None: | ||
| boundaries = [ | ||
| # [ | ||
| # (LB_m, UB_m), | ||
| # (LB_n, UB_n), | ||
| # func | ||
| # ] | ||
| [ | ||
| (3, 2**6), | ||
| (3, np.inf), | ||
| sdp._njit_sliding_dot_product, | ||
| ], | ||
| ] | ||
|
|
||
| def sliding_dot_product(Q, T): | ||
| """ | ||
| Compute the sliding dot product between ``Q`` and ``T`` | ||
| by using different methods according to len(Q) and len(T) | ||
|
|
||
| Parameters | ||
| ---------- | ||
| Q : numpy.ndarray | ||
| Query array or subsequence. | ||
|
|
||
| T : numpy.ndarray | ||
| Time series or sequence. | ||
|
|
||
| Returns | ||
| ------- | ||
| out : numpy.ndarray | ||
| Sliding dot product between ``Q`` and ``T``. | ||
| """ | ||
| m, n = len(Q), len(T) | ||
| if m == n: | ||
| return np.array([np.dot(Q, T)]) | ||
|
|
||
| for item in boundaries: | ||
|
Contributor
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. There's just something about this that doesn't sit right with me. Here's what I am seeing:
So, while the logic is sound, this point:
is still relevant. Yes, the sets of boundaries are supplied/embedded once into Having said that, are we going to have a way for users to run a function and come up with boundaries and functions that are best suited for their hardware?
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.
Right, I misunderstood your point before.
Let's replace that for-loop with Is it a bad design? This allows [advanced] users to use different ways to implement branching logic for their
We can always add a caching mechanism on top of the function As a side, regarding the following question you raised before in another comment:
I think the proposal should address that
Finding "boundaries" is tricky. I have a narrower scope (and, tbh, simpler solution 😅) in mind... a function that gets
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.
Okay, I think it might be tricky for most users too! So, maybe they appreciate if we just come up with a function that helps them identify boundaries approximately. For instance, we just explore cases where
Contributor
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. I am mostly interested in what the
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. I wanted to say a simple if-else... but I think it can get ugly later. I think we should do what you proposed before in stumpy-dev/sliding_dot_product#18 (comment), a 2D lookup table. And, I think there is no longer a need for The So, I feel I need to think about...
In this PR.
Contributor
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.
Even using
I wouldn't do this inside of |
||
| (LB_m, UB_m), (LB_n, UB_n), func = item | ||
| if LB_m <= m <= UB_m and LB_n <= n <= UB_n: | ||
| return func(Q, T) | ||
|
|
||
| return default_func(Q, T) | ||
|
|
||
| return sliding_dot_product | ||
|
|
||
|
|
||
| sliding_dot_product = make_sliding_dot_product() | ||
|
|
||
|
|
||
| @njit( | ||
|
|
||
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.
funcnotfucn