Skip to content

Commit ae1f3f9

Browse files
committed
perf: use fma for m3_update
1 parent edc2393 commit ae1f3f9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pandas/_libs/window/aggregations.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from libc.math cimport (
44
fabs,
5+
fma,
56
round,
67
signbit,
78
sqrt,
@@ -532,7 +533,7 @@ cdef void add_skew(float64_t val, int64_t *nobs,
532533
delta_n = delta / n
533534
term1 = delta * delta_n * (n - 1.0)
534535

535-
m3_update = delta_n * (term1 * (n - 2.0) - 3.0 * m2[0])
536+
m3_update = delta_n * fma(term1, n - 2.0, -3.0 * m2[0])
536537
new_m3 = m3[0] + m3_update
537538
if fabs(m3_update) + fabs(m3[0]) > 1e10 * fabs(new_m3):
538539
# possible catastrophic cancellation
@@ -559,7 +560,7 @@ cdef void remove_skew(float64_t val, int64_t *nobs,
559560
delta_n = delta / n
560561
term1 = delta_n * delta * (n + 1.0)
561562

562-
m3_update = delta_n * (term1 * (n + 2.0) - 3.0 * m2[0])
563+
m3_update = delta_n * fma(term1, n + 2.0, -3.0 * m2[0])
563564
new_m3 = m3[0] - m3_update
564565

565566
if fabs(m3_update) + fabs(m3[0]) > 1e10 * fabs(new_m3):

0 commit comments

Comments
 (0)