-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: short-circuit (left == right).all() comparisons #32339
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
Comments
cc @seberg any idea why this is so much slower in the not-short-circuit case? |
@jbrockmendel my guess is: We are using SIMD loops in this case (at least sometimes), and cython probably does not manage to do that. Are you sure what you are doing is a good idea though? First, -0 and 0 are not different normally. Second, there are many many NaNs, and you are making some of them return True. |
@scoder thoughts? |
Might make a difference here, yes. Make sure your CFLAGS allow for auto-vectorisation, and that your C compiler is modern enough to figure it out for you. It sometimes helps the compiler to make your algorithm redundant, i.e. instead of just |
In places like
equals
methods andarray_equivalent
, we do things like(left == right).all()
or((left == right) | (isna(left) & isna(right))).all()
. For large arrays that are not equal, we can do much better with something like:Some profiling results:
So in cases that short circuit early, we can get massive speedups, but this implementation is actually 2x slower in cases that dont short-circuit (for reasons that are not clear to me).
The text was updated successfully, but these errors were encountered: