Skip to content

Refactor/sdp structure cleanup#1126

Open
NimaSarajpoor wants to merge 2 commits intostumpy-dev:mainfrom
NimaSarajpoor:refactor/sdp-structure-cleanup
Open

Refactor/sdp structure cleanup#1126
NimaSarajpoor wants to merge 2 commits intostumpy-dev:mainfrom
NimaSarajpoor:refactor/sdp-structure-cleanup

Conversation

@NimaSarajpoor
Copy link
Collaborator

This is to address PR 1 described in this comment. Have copied the corresponding notes below:

  1. Create a new sdp.py file
  2. Move _sliding_dot_product to sdp.py and call it _njit_sliding_dot_product
  3. Removing the core._sliding_dot_product altogether (currently, you are keeping both and calling one from the other. This is a bad idea)
  4. Replace all (three) references to core._sliding_dot_product with sdp._njit_sliding_dot_product
  5. Update move tests from tests/test_core.py to tests/test_sdp.py
  6. Add an sdp._sliding_dot_product that simply calls _njit_sliding_dot_product (complexity gets added in future PRs)
  7. Make core.sliding_dot_product = sdp._sliding_dot_product

@gitnotebooks
Copy link

gitnotebooks bot commented Feb 7, 2026

Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1126

QT = convolve(Qr, T)

return QT.real[m - 1 : n]
return sdp._sliding_dot_product(Q, T)
Copy link
Collaborator Author

@NimaSarajpoor NimaSarajpoor Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanlaw
Regarding core.sliding_dot_prodiuct: Is this what you meant when you said in this comment (see notes on PR 1):

  1. Make core.sliding_dot_product = sdp._sliding_dot_product

?


I think we should handle sdp._convolve_sliding_dot_product (see PR 2 in this comment) in this PR. The function core.sliding_dot_product in the branch main can be copied to the sdp module, and renamed to _convolve_sliding_dot_product. sdp._sliding_dot_product should point to sdp._convolve_sliding_dot_product. This is not a serious issue if the plan is to handle PR 2 quickly right after PR 1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes perfect sense. It's not actually new code or new SDP methods. It's simply a refactoring of existing code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdp._sliding_dot_product should point to sdp._convolve_sliding_dot_product

And then, in subsequent PRs, it should point to multiple functions using some branching logic, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct 👍

from stumpy import sdp


def naive_rolling_window_dot_product(Q, T):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a similar function in tests/test_core.py. Refactor and put this function in tests/naive.py.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason why I didn't want to put it in naive.py was because it wasn't actually being used in any other file except for test_core.py. The only time I would move a function to naive.py is when it was used across multiple test files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only time I would move a function to naive.py is when it was used across multiple test files.

Noted. Since I am now using it in tests/test_sdp.py too, it makes sense to just move it to naive.py. Is that correct?

@NimaSarajpoor
Copy link
Collaborator Author

NimaSarajpoor commented Feb 7, 2026

@seanlaw
We also need to modify Tutorial_DiscordMERLIN.ipynb as it uses core._sliding_dot_product, and need to run the whole notebook again. However, the problem is that the notebook loads data from directories that do not exist. Also, the data provided by MERLIN webpage is not accessible anymore.

Copy link
Contributor

@seanlaw seanlaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NimaSarajpoor Looking good! This is much easier to track

QT = convolve(Qr, T)

return QT.real[m - 1 : n]
return sdp._sliding_dot_product(Q, T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes perfect sense. It's not actually new code or new SDP methods. It's simply a refactoring of existing code

T_squared[i - 1] - T[i - 1] * T[i - 1] + T[i + m - 1] * T[i + m - 1]
)
QT = _sliding_dot_product(Q, T)
QT = sdp._njit_sliding_dot_product(Q, T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the name being sdp._njit_sliding_dot_product, it actually makes logical sense. This _p_norm_distance_profile is an NJIT decorated function and, therefore, it MUST use an NJIT capable SDP function! I like that this distinction is clear and obvious

While core.sliding_dot_product is NOT necessarily an NJIT function (it could be but doesn't have to be).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this distinction is clear and obvious

While core.sliding_dot_product is NOT necessarily an NJIT function (it could be but doesn't have to be).

YES, and YES!!!

QT = convolve(Qr, T)

return QT.real[m - 1 : n]
return sdp._sliding_dot_product(Q, T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdp._sliding_dot_product should point to sdp._convolve_sliding_dot_product

And then, in subsequent PRs, it should point to multiple functions using some branching logic, right?

from stumpy import sdp


def naive_rolling_window_dot_product(Q, T):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason why I didn't want to put it in naive.py was because it wasn't actually being used in any other file except for test_core.py. The only time I would move a function to naive.py is when it was used across multiple test files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants