-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: window ewm slowdown #43052
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
REGR: window ewm slowdown #43052
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -1489,7 +1489,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights, | |
|
||
def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end, | ||
int minp, float64_t com, bint adjust, bint ignore_na, | ||
const float64_t[:] deltas) -> np.ndarray: | ||
const float64_t[:] deltas=None) -> np.ndarray: | ||
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. can u update the doc string 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. done |
||
""" | ||
Compute exponentially-weighted moving average using center-of-mass. | ||
|
||
|
@@ -1511,14 +1511,17 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end, | |
|
||
cdef: | ||
Py_ssize_t i, j, s, e, nobs, win_size, N = len(vals), M = len(start) | ||
const float64_t[:] sub_deltas, sub_vals | ||
const float64_t[:] sub_vals | ||
const float64_t[:] sub_deltas=None | ||
ndarray[float64_t] sub_output, output = np.empty(N, dtype=np.float64) | ||
float64_t alpha, old_wt_factor, new_wt, weighted_avg, old_wt, cur | ||
bint is_observation | ||
bint is_observation, use_deltas | ||
|
||
if N == 0: | ||
return output | ||
|
||
use_deltas = deltas is not None | ||
|
||
alpha = 1. / (1. + com) | ||
old_wt_factor = 1. - alpha | ||
new_wt = 1. if adjust else alpha | ||
|
@@ -1529,7 +1532,8 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end, | |
sub_vals = vals[s:e] | ||
# note that len(deltas) = len(vals) - 1 and deltas[i] is to be used in | ||
# conjunction with vals[i+1] | ||
sub_deltas = deltas[s:e - 1] | ||
if use_deltas: | ||
sub_deltas = deltas[s:e - 1] | ||
win_size = len(sub_vals) | ||
sub_output = np.empty(win_size, dtype=np.float64) | ||
|
||
|
@@ -1547,7 +1551,10 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end, | |
if weighted_avg == weighted_avg: | ||
|
||
if is_observation or not ignore_na: | ||
old_wt *= old_wt_factor ** sub_deltas[i - 1] | ||
if use_deltas: | ||
old_wt *= old_wt_factor ** sub_deltas[i - 1] | ||
else: | ||
old_wt *= old_wt_factor | ||
if is_observation: | ||
|
||
# avoid numerical errors on constant series | ||
|
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.
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.
move to 1.3.3
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.
done