Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Lib/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def _quartic_invcdf_estimate(p):

@register('quartic', 'biweight')
def quartic_kernel():
pdf = lambda t: 15/16 * (1.0 - t * t) ** 2
pdf = lambda t: 15/16 * (u := 1.0 - t * t) * u

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does not improve readability. Do you have a bench ark for the gain of this change?

@rhettinger rhettinger Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. The timings were in the individual commit messages. I just moved them to the top message in Conversation.

It is not a beautiful edit, but it isn't terrible either. Note, besides giving a nice speed-up, the reduction in strength from x ** 2 to x * x also improves accuracy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rhettinger If it improves accuracy, it changes behavior. Can you add a news entry and a test?

(since you already merged the PR, this should be a followup PR)

cdf = lambda t: sumprod((3/16, -5/8, 15/16, 1/2),
(t**5, t**3, t, 1.0))
invcdf = _newton_raphson(_quartic_invcdf_estimate, f=cdf, f_prime=pdf)
Expand Down Expand Up @@ -1486,15 +1486,13 @@ def _sum(data):
"""
count = 0
types = set()
types_add = types.add
partials = {}
partials_get = partials.get

for typ, values in groupby(data, type):
types_add(typ)
types.add(typ)
for n, d in map(_exact_ratio, values):
count += 1
partials[d] = partials_get(d, 0) + n
partials[d] = partials.get(d, 0) + n

if None in partials:
# The sum will be a NAN or INF. We can ignore all the finite
Expand Down Expand Up @@ -1524,12 +1522,11 @@ def _ss(data, c=None):

count = 0
types = set()
types_add = types.add
sx_partials = defaultdict(int)
sxx_partials = defaultdict(int)

for typ, values in groupby(data, type):
types_add(typ)
types.add(typ)
for n, d in map(_exact_ratio, values):
count += 1
sx_partials[d] += n
Expand Down
Loading