View source on GitHub
|
Reduces a TFF sequence value given a zero and reduction operator op.
tff.sequence_reduce(
value, zero, op
)
This method reduces a set of elements of a TFF sequence value, using a given
zero in the algebra (i.e., the result of reducing an empty sequence) of some
type U, and a reduction operator op with type signature (<U,T> -> U)
that incorporates a single T-typed element of value into the U-typed
result of partial reduction. In the special case of T equal to U, this
corresponds to the classical notion of reduction of a set using a commutative
associative binary operator. The generalized reduction (with T not equal to
U) requires that repeated application of op to reduce a set of T always
yields the same U-typed result, regardless of the order in which elements
of T are processed in the course of the reduction.
One can also invoke sequence_reduce on a federated sequence, in which case
the reductions are performed pointwise; under the hood, we construct an
expression of the form
federated_map(x -> sequence_reduce(x, zero, op), value). See also the
discussion on sequence_map.
Returns | |
|---|---|
The U-typed result of reducing elements in the sequence, or if the value
is federated, a federated U that represents the result of locally
reducing each member constituent of value.
|
Raises | |
|---|---|
TypeError
|
If the arguments are not of the types specified above. |
View source on GitHub