FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-130203: Further simplify `math.sumprod` documentation by Akuli · Pull Request #130206 · python/cpython · GitHub

/ cpython Public
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/library/math.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ Summation and product functions

Roughly equivalent to::

sum(map(operator.mul, p, q, strict=True))
sum(px * qx for px, qx in zip(p, q, strict=True))

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would suggest leaving as is but adding a sentence below such as:

sum(map(operator.mul, p, q, strict=True))

where the multiply operator is used to multiply each item in the *p* and *q* iterables together 
and sum the products.

I'm not sure but I suspect the original command is more performant. I'm fine also with adding the proposed item as an alternative illustration.

I would leave the .c file unchanged using map and operator.mul.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ISTM the proposed extra sentence just repeats the first sentence before the rough equivalent.


For float and mixed int/float inputs, the intermediate products
and sums are computed with extended precision.
Expand Down
4 changes: 2 additions & 2 deletions Modules/clinic/mathmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Modules/mathmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2750,15 +2750,15 @@ Return the sum of products of values from two iterables p and q.

Roughly equivalent to:

sum(map(operator.mul, p, q, strict=True))
sum(px * qx for px, qx in zip(p, q, strict=True))

For float and mixed int/float inputs, the intermediate products
and sums are computed with extended precision.
[clinic start generated code]*/

static PyObject *
math_sumprod_impl(PyObject *module, PyObject *p, PyObject *q)
/*[clinic end generated code: output=6722dbfe60664554 input=a2880317828c61d2]*/
/*[clinic end generated code: output=6722dbfe60664554 input=75b4b596dce5611e]*/
{
PyObject *p_i = NULL, *q_i = NULL, *term_i = NULL, *new_total = NULL;
PyObject *p_it, *q_it, *total;
Expand Down

Back | FazBrowse Home | New Git URL