Drop redundant k clamp in _mpdist_vect and _aampdist_vect#1159
Open
DMZ22 wants to merge 1 commit into
Open
Conversation
P_ABBA is allocated as np.empty(2 * j), so P_ABBA.shape[0] - 1 is 2 * j - 1. The k = min(int(k), P_ABBA.shape[0] - 1) that follows therefore already applies the same upper bound that the min(..., 2 * j - 1) inside the k is None branch does, making the inner clamp redundant. Remove it in both mpdist and aampdist, as suggested in the issue. Closes stumpy-dev#1082.
|
Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1159 |
Contributor
|
@DMZ22 Thank you for your help. I will merge this once the tests all pass |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directoryOn that last item: I'm on Windows, so rather than
./test.shI ran the two affected suites directly —pytest tests/test_mpdist.py tests/test_aampdist.py→ 82 passed. Happy to run anything further you'd like.blackreported 99 files unchanged andflake8was clean.(Reopening #1158, which the template bot closed because I'd replaced the checklist with a plain description — my mistake.)
Closes #1082.
P_ABBAis allocated asnp.empty(2 * j, ...), soP_ABBA.shape[0] - 1is2 * j - 1. That means thek = min(int(k), P_ABBA.shape[0] - 1)on the following line already applies exactly the same upper bound as themin(..., 2 * j - 1)inside theif k is Nonebranch, so the inner clamp is redundant:Applied to
aampdistas well, as you noted on the issue.Why it's behaviour-preserving
min(min(a, b), b) == min(a, b), and theint()is a no-op becausemath.ceilalready returns anint. I also checked it empirically over 20,000 randomised(n, m, percentage)combinations — includingpercentagevalues outside[0, 1]so the clipping path is exercised — and the resultingkwas identical in every case.