tff.sequence_reduce

Reduces a TFF sequence value given a zero and reduction operator op.

Used in the notebooks

Used in the tutorials

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.

value A value that is either a TFF sequence, or a federated sequence.
zero The result of reducing a sequence with no elements.
op An operator with type signature (<U,T> -> U), where T is the type of the elements of the sequence, and U is the type of zero to be used in performing the reduction.

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.

TypeError If the arguments are not of the types specified above.