8000 GH-100485: Add math.sumprod() by rhettinger · Pull Request #100677 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-100485: Add math.sumprod() #100677

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 43 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5776b0f
Stub function.
rhettinger Jan 1, 2023
8ffd49e
Core fuctionality without error handling
rhettinger Jan 1, 2023
f5a3ecb
Test core functionality.
rhettinger Jan 2, 2023
37fcb0a
Add docs
rhettinger Jan 2, 2023
6cfc5cc
Check for non-iterable inputs
rhettinger Jan 2, 2023
fbeca6b
Handle uneven lengths and error returns from PyIter_Next().
rhettinger Jan 2, 2023
40cfc8f
Handle errors arising during the multiplications or additions.
rhettinger Jan 2, 2023
2ac24f5
Test special values
rhettinger Jan 2, 2023
1a64fd8
Add blurb
rhettinger Jan 2, 2023
5f4e493
Regenerate clinic files
rhettinger Jan 2, 2023
31fa258
Beautify with booleans.
rhettinger Jan 3, 2023
d19a38b
Add int_path. Needs work on refcount and addition overflow.
rhettinger Jan 3, 2023
a28fd71
Add more assertions and refcount fixes
rhettinger Jan 3, 2023
f998ee4
Only test for ints when iterators are not stopped.
rhettinger Jan 3, 2023
94a9cbd
Test long addition for overflow
rhettinger Jan 3, 2023
c778865
Improve wording regarding extended precision.
rhettinger Jan 3, 2023
6d619dd
Add the "finished" summary variable for readability.
rhettinger Jan 3, 2023
83dbf96
Add flt path
rhettinger Jan 4, 2023
c2e5f3d
add flt/int path
rhettinger Jan 4, 2023
b8c9127
.
rhettinger Jan 4, 2023
fdaf31b
Merge branch 'sumprod4' into sumprod
rhettinger Jan 4, 2023
4f22a7f
Update docs and docstrings.
rhettinger Jan 4, 2023
7d7fd87
Fix typo
rhettinger Jan 4, 2023
c16f90a
Use extended precision for float/float and int/float cases.
rhettinger Jan 4, 2023
c52bb84
Brevity is the soul of wit.
rhettinger Jan 4, 2023
bf8059c
Beautification.
rhettinger Jan 4, 2023
1326e83
Various minor improvments
rhettinger Jan 5, 2023
9b03468
Fully encapsulate the dl (double length) logic.
rhettinger Jan 5, 2023
8b88f4d
Add performance comment.
rhettinger Jan 5, 2023
83ca929
Write tight.
rhettinger Jan 5, 2023
708f314
Abbreviate comment.
rhettinger Jan 5, 2023
90f1ee4
Remove case for int/int while float in use.
rhettinger Jan 5, 2023
02035dc
Beautify dl_add()
rhettinger Jan 5, 2023
9b1edcc
Add stress tests.
rhettinger Jan 5, 2023
22249d6
Update itertools recipe to reflect the promotion.
rhettinger Jan 5, 2023
ec50404
Remove doctest for dotproduct().
rhettinger Jan 5, 2023
19dfd08
Speed-up iterator access. Let float be selected by bools.
rhettinger Jan 6, 2023
13f1d4f
Add assertion for a key checkpoint
rhettinger Jan 6, 2023
a07e03d
Move dl_mul() out to a separate function. Dekker (5.8).
rhettinger Jan 6, 2023
d274325
Add the smaller magnitude component first.
rhettinger Jan 6, 2023
67f82ca
Use Dekker (5.12) directly. Avoids calling dl_add() and saves a compa…
rhettinger Jan 7, 2023
5d165be
Update timing in comment.
rhettinger Jan 7, 2023
2e772cb
Add in the large component first.
rhettinger Jan 7, 2023
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
Prev Previous commit
Next Next commit
Remove case for int/int while float in use.
  • Loading branch information
rhettinger committed Jan 5, 2023
commit 90f1ee4b972956a090e270fcdf0b64a7f485fc2b
4 changes: 4 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,10 @@ def __rmul__(self, other):
self.assertTrue(math.isnan(sumprod([10.1, math.inf], [math.nan, 30.3])))
self.assertTrue(math.isnan(sumprod([10.1, math.inf], [20.3, math.nan])))

# Error cases that arose during development
args = ((-5, -5, 10), (1.5, 4611686018427387904, 2305843009213693952))
self.assertEqual(sumprod(*args), 0.0)


@requires_IEEE_754
@unittest.skipIf(HAVE_DOUBLE_ROUNDING,
Expand Down
14 changes: 0 additions & 14 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3056,20 +3056,6 @@ math_sumprod_impl(PyObject *module, PyObject *p, PyObject *q)
PyErr_Clear();
goto finalize_flt_path;
}
} else if (flt_total_in_use && PyLong_CheckExact(p_i) && PyLong_CheckExact(q_i)) {
/* This path makes sure that we don't throw-away a double
length float accumulation if a subsequent int/int pair is
encountered. */
flt_p = PyLong_AsDouble(p_i);
if (flt_p == -1.0 && PyErr_Occurred()) {
PyErr_Clear();
goto finalize_flt_path;
}
flt_q = PyLong_AsDouble(q_i);
if (flt_q == -1.0 && PyErr_Occurred()) {
PyErr_Clear();
goto finalize_flt_path;
}
} else {
goto finalize_flt_path;
}
Expand Down
0