Created
July 10, 2020 17:07
-
-
Save s1ddok/77f5999c1046f3544f1021407317894d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Checkpoint { | |
/// ... | |
var userInfo: [String: Codable] = [:] | |
} | |
protocol Checkpointable { | |
init(checkpoint: Checkpoint) | |
func read(from: Checkpoint) | |
func write(to: Checkpoint) | |
} | |
// make it optional | |
extension Checkpointable { | |
init(checkpoint: Checkpoint) { fatalError()} | |
} | |
struct Model: Checkpointable { | |
let hiddenLayerFeatureChannels: Int | |
init(hiddenLayerFeatureChannels: Int) { | |
self.hiddenLayerFeatureChannels = hiddenLayerFeatureChannels | |
} | |
init(checkpoint: Checkpoint) { | |
guard | |
let hiddenLayerFeatureChannels = checkpoint.userInfo["ngf"] as? Int | |
else { fatalError()} | |
self.init(hiddenLayerFeatureChannels: hiddenLayerFeatureChannels) | |
self.read(from: checkpoint) | |
} | |
func read(from: Checkpoint) { | |
// Normal reading | |
} | |
func write(to checkpoint: Checkpoint) { | |
// Normal writing | |
checkpoint.userInfo["ngf"] = hiddenLayerFeatureChannels | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment