Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 1443c87

Browse files
committed
Explore LayerModule protocol to enable better type inference
1 parent 1a5a8e9 commit 1443c87

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Models/LayerInit/AutoModule.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import TensorFlow
2+
3+
public protocol AutoModule: AutoLayer {
4+
associatedtype LayerType: AutoLayer
5+
6+
var initializeLayer: LayerType { mutating get }
7+
}
8+
9+
extension AutoModule {
10+
public typealias InstanceType = LayerType.InstanceType
11+
public typealias InputShape = LayerType.InputShape
12+
public typealias OutputShape = LayerType.OutputShape
13+
14+
public func buildModelWithOutputShape(inputShape: InputShape) -> (InstanceType, OutputShape) {
15+
var selfCopy = self
16+
return selfCopy.initializeLayer.buildModelWithOutputShape(inputShape: inputShape)
17+
}
18+
}

0 commit comments

Comments
 (0)