-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: nancorr_spearman #41857
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
PERF: nancorr_spearman #41857
Conversation
What is the scenario in which prange is available but the user would want to disable it? |
Sorry "allow" was a poor word choice. More specifically, I think it would make sense for By default |
thanks, thats what i was missing. Would any of this Just Work if this were implemented in numba instead of cython? I don't have a strong opinion on this per se, but am wary of a) using a cython feature (prange) that we don't currently use and that i don't know i) how well supported it is or ii) if its behavior is e.g. platform-dependent and b) user-facing kwargs that will give us combinatorially more cases to test |
numba will just work for parallelism +1 on adding similar apis as we have for window functions cc @mroeschke |
Agree with the concerns, was just mentioning as something to consider for the future, not meant for this pr EDIT: also agree numba would make things easier, do you know if there has been any exploration of using numba instead of cython? |
asv_bench/benchmarks/stat_ops.py
Outdated
@@ -99,6 +99,7 @@ class Correlation: | |||
param_names = ["method"] | |||
|
|||
def setup(self, method): | |||
np.random.seed(0) |
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.
You don't need this random seed. The imported setup
function sets the random seed for all benchmarks
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.
Thanks, will remove
All window aggregations and groupby transform/agg have API support for a You can see |
see #40530, although that's a bit ambitious as the goal there is to remove cython completely to create a no-arch pandas build. ( I think would maybe be good for new contributors or for exploration of the libs api, see later). I'm working through slowly but still on 'a' for algos. (next is wrappers for take_2d in algos.) A significant benefit I would see for using numba would be the native handling of datetimes by numba avoiding i8 conversions in the main code and passing is_datetime like flags to the cython libs. I originally started to this also, but makes keeping my branch in sync harder. So I'm just looking to swap out the libraries as a first steps and keep the same api for the libs.
I think you still have the same issue regarding what the default setting should be. IIRC in #40530 where I made take_1d parallel, running the test suite with n=auto was a lot slower and needed to use the environment settings to turn off parallelism. although I have since changed that to only use parallelism when the number of rows > 10_000, so probably no longer an issue for the test suite. |
Thanks for explaining @mroeschke and @simonjayhawkins! |
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.
just a question
result[xi, yi] = result[yi, xi] = NaN | ||
else: | ||
if not all_ranks: | ||
with gil: |
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.
why the gil here?
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.
rank_1d
can't be called with nogil
. Perhaps some refactoring could allow calling some nogil rank_1d
helper instead, but that would be a larger change.
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.
i c, ok i think its worthile to make that nogil (but not in this PR), followon preferred.
# We need to slice back to nobs because rank_1d will | ||
# require arrays of nobs length | ||
labels_nobs = np.zeros(nobs, dtype=np.int64) | ||
rankedx = rank_1d(np.array(maskedx)[:nobs], |
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.
yeah should really take a memory view (or have a helper function to do it)
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.
some followon suggestions.
Will look into removing that gil section. The main complication is that |
Think a lot more can be squeezed out, so not closing the issue. Initial results:
This speedup factor increases the larger the frame since more time gets spent in the ~O(N^2K) algo. With the nogil added, we could also explore using
prange
on the outer loop and exposing some newkwarg
to allow cython parallelism.