Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Doc/library/math.rst
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
Contributor

Choose a reason for hiding this comment

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

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
Contributor

Choose a reason for hiding this comment

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

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
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
Loading