Skip to content

CLN/PERF: no need for kahan for int group_cumsum #41874

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 8 commits into from
Jun 9, 2021

Conversation

mzeitlin11
Copy link
Member

Surprised at lack of impact here - doesn't noticeably affect benchmarks.

Targeting the cython algo specifically shows an improvement (but smaller than I'd expect given the removed operations):

import numpy as np
import pandas._libs.groupby as libgroupby

N = 4_000_000
vals = np.random.randint(0, 10, (N, 5), dtype=np.int64)
result = np.empty_like(vals)

%timeit libgroupby.group_cumsum(result, vals, np.ones(N, dtype="int"), 1, False)
# 28.9 ms ± 805 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)  # this pr
# 37.3 ms ± 206 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)   # master

@@ -253,18 +253,16 @@ def group_cumsum(numeric[:, ::1] out,
t = accum[lab, j] + y
compensation[lab, j] = t - accum[lab, j] - y
accum[lab, j] = t
out[i, j] = accum[lab, j]
out[i, j] = t
Copy link
Member Author

@mzeitlin11 mzeitlin11 Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubt this affects compiled result, but may as well to not depend on a smart compiler avoiding this extra indexing step

@mzeitlin11 mzeitlin11 added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Clean Groupby Performance Memory or execution speed performance labels Jun 8, 2021
y = val - compensation[lab, j]
t = accum[lab, j] + y
compensation[lab, j] = t - accum[lab, j] - y
t = val + accum[lab, j]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm this is affecting all dtypes. do we not have tests for this for small floats?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inside the else block from an if statement if numeric == float32_t or numeric == float64_t: so only non-floats should end up here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh ok that was not clear from the difff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment to that effect (maybe just on the float32/64 branch, e.g. using Kahan summation)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added a comment

@jreback jreback added this to the 1.3 milestone Jun 9, 2021
@jreback
Copy link
Contributor

jreback commented Jun 9, 2021

hmm seemingly unrelated failures. maybe on master? cc @jbrockmendel

@jreback jreback merged commit 3ca84fc into pandas-dev:master Jun 9, 2021
@jreback
Copy link
Contributor

jreback commented Jun 9, 2021

thanks @mzeitlin11

@mzeitlin11 mzeitlin11 deleted the perf/grp_cumsum_int branch June 9, 2021 12:48
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Clean Groupby Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants