| |
- accumulate(x, f=<built-in function add>, initial=<no value>)
- For associative function f of two arguments, make an iterator that returns
the accumulated results over all (nonempty) prefixes of the given iterable x.
The applications of f are arranged such that the maximum depth is logarithmic
in the number of elements of x, potentially at the cost of increasing the total
number of applications of f by a logarithmic factor as well.
In contrast, Python's itertools.accumulate() higher-order function arranges
the applications of f in a linear fashion, as in general it cannot be assumed
that f is associative (and that the arguments to f are even of the same type).
If initial is provided (possibly equal to None), the accumulation leads off
with this initial value so that the output has one more element than the input
iterable. Otherwise, the number of elements output matches the input iterable x.
- reduce(f, x, initial=<no value>)
- Apply associative function f of two arguments to the items of iterable x.
The applications of f are arranged in a binary tree of logarithmic depth,
thus limiting the overall round complexity of the secure computation.
In contrast, Python's functools.reduce() higher-order function arranges
the applications of f in a linear chain (a binary tree of linear depth),
and in this case f is not required to be associative; the arguments to f
may even be of different types.
If initial is provided (possibly equal to None), it is placed before the
items of x (hence effectively serves as a default when x is empty). If no
initial value is given and x contains only one item, that item is returned.
|