-
-
Notifications
You must be signed in to change notification settings - Fork 11k
ENH: Speed up trim_zeros #16911
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
Merged
Merged
ENH: Speed up trim_zeros #16911
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2dd352c
Added a benchmark for `trim_zeros()`
59e7cde
Updated the benchmark with `param_names` and `params`
b6fa460
Improve the performance of `np.trim_zeros()`
5f85a1c
Fixed a string-representation
af728c8
docstring update; fixed an issue with the try/except approach in 'B'
3da3f3c
Removed a sentence which is redundant since 2a2d9d622e9bdeafd5cfafc9f…
e3da361
Reverted a redundant documentation change
ca5d462
Improve readability: use ndarray.any() to check for empty arrays
f4ae522
Revert "Improve readability: use ndarray.any() to check for empty arr…
8aade1b
The performance increase of 997bdc793234d6c1c75738035ba63730d686b356 …
189e808
Increase the variety of the tests
7a9d0e2
BUG: check if array-length is non-zero before calling `argmax()`
75ad305
Implement https://github.com/numpy/numpy/pull/16911#discussion_r45733…
9d1662b
Implement https://github.com/numpy/numpy/pull/16911#discussion_r45735…
ccf1c21
Implemented https://github.com/numpy/numpy/pull/16911#discussion_r457…
4d91311
Implemented https://github.com/numpy/numpy/pull/16911#issuecomment-66…
eae7275
TST: Avoid the use of `warnings.simplefilter('ignore', ...)
20829cf
MAINT: Gramar fix
a25620e
TST,MAINT: Fixed an incorrect exception name
25d2d23
STY: remove trailing whitespaces
16d5072
DEP: Added a date/version deprecation comment
ab313d5
MAINT: Typo fix; added a missing space
8b99f60
TST,DEP: Added a deprecation testcase
2392fe3
DEP,REL: Added a deprecation release note
dea951f
TST,DEP: Moved leftovers from a deprecation test
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .common import Benchmark | ||
|
||
import numpy as np | ||
|
||
_FLOAT = np.dtype('float64') | ||
_COMPLEX = np.dtype('complex128') | ||
_INT = np.dtype('int64') | ||
_BOOL = np.dtype('bool') | ||
|
||
|
||
class TrimZeros(Benchmark): | ||
param_names = ["dtype", "size"] | ||
params = [ | ||
[_INT, _FLOAT, _COMPLEX, _BOOL], | ||
[3000, 30_000, 300_000] | ||
] | ||
|
||
def setup(self, dtype, size): | ||
n = size // 3 | ||
self.array = np.hstack([ | ||
np.zeros(n), | ||
np.random.uniform(size=n), | ||
np.zeros(n), | ||
]).astype(dtype) | ||
|
||
def time_trim_zeros(self, dtype, size): | ||
np.trim_zeros(self.array) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
``trim_zeros`` now requires a 1D array compatible with ``ndarray.astype(bool)`` | ||
------------------------------------------------------------------------------- | ||
The ``trim_zeros`` function will, in the future, require an array with the | ||
following two properties: | ||
|
||
* It must be 1D. | ||
* It must be convertable into a boolean array. |
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
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
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
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.