|View source on GitHub|
Maps a TFF sequence
value pointwise using a given function
tff.sequence_map( mapping_fn, value )
Used in the notebooks
|Used in the tutorials|
This function supports two modes of usage:
When applied to a non-federated sequence, it maps individual elements of the sequence pointwise. If the supplied
mapping_fnis of type
T->Uand the sequence
valueis of type
T*(a sequence of
T-typed elements), the result is a sequence of type
U*(a sequence of
U-typed elements), with each element of the input sequence individually mapped by
mapping_fn. In this mode of usage,
sequence_mapbehaves like a compuatation with type signature
<T->U,T*> -> U*.
When applied to a federated sequence,
sequence_mapbehaves as if it were individually applied to each member constituent. In this mode of usage, one can think of
sequence_mapas a specialized variant of
federated_mapthat is designed to work with sequences and allows one to specify a
mapping_fnthat operates at the level of individual elements. Indeed, under the hood, when
sequence_mapis invoked on a federated type, it injects
federated_map, thus emitting expressions like
federated_map(a -> sequence_map(mapping_fn, x), value).
mapping_fn: A mapping function to apply pointwise to elements of
value: A value of a TFF type that is either a sequence, or a federated sequence.
A sequence with the result of applying
mapping_fn pointwise to each
value, or if
value was federated, a federated sequence
with the result of invoking
sequence_map on member sequences locally
and independently at each location.
TypeError: If the arguments are not of the appropriate types.