Add layer wrapper type for Collection
types #1021
Description
Add a SequentialComposition<Base>
layer wrapper type.
SequentialComposition
is a Layer
that wraps a collection, applying each element in sequence to an input to produce an output. The callAsFunction
method calls differentiableReduce
, with the input as the initial value.
This allows collections of Layer
s like [Dense<Float>]
to be treated as a Layer
.
Original idea and work by @dabrahams.
Work-in-progress implementation: currently blocked by Collection.differentiableReduce(_:_:)
.
An alternative idea is to directly conform Array
to Layer
: #708.
But this hardcodes a particular Array: Layer
conformance, when there may be multiple ways to interpret an Array
as a Layer
. A generic "SequentialComposition<Base>
" layer wrapper type is more flexible and explicit about the Layer
behavior.