swift-apis icon indicating copy to clipboard operation
swift-apis copied to clipboard

Add layer wrapper type for `Collection` types

Open dan-zheng opened this issue 5 years ago • 0 comments

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 Layers 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.

Full rationale by @dabrahams.

dan-zheng avatar Jun 24 '20 06:06 dan-zheng