Store
public struct Store
A key-value based parameter store.
-
Declaration
Swift
public struct OpenFlag : OptionSet
-
Declaration
Swift
public struct Codec : OptionSet
-
Read only shape of a tensor from the store.
Declaration
Swift
public func read(like key: String) -> AnyTensor?
Parameters
like
The key corresponding to that particular tensor.
-
Retrieve codec for a particular key. It must be a tensor to make sense of this.
Declaration
Swift
public func codec(for key: String) -> Codec?
Parameters
key
The key corresponding to a particular tensor.
-
Read a tensor from the store into tensor variable from dynamic graph.
Declaration
Swift
@discardableResult public func read(_ key: String, variable: DynamicGraph_Any, codec: Codec = []) -> Bool
Parameters
key
The key corresponding to that particular tensor.
variable
The tensor variable to be initialized with.
-
Declaration
Swift
public enum ModelReaderResult
-
Read parameters into a given model.
Declaration
Swift
public func read( _ key: String, model: Model, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil )
Parameters
key
The key corresponding to a particular model.
model
The model to be initialized with parameters from a given key.
reader
You can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model builder.
Declaration
Swift
public func read( _ key: String, model: AnyModelBuilder, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil )
Parameters
key
The key corresponding to a particular model.
model
The model builder to be initialized with parameters from a given key.
reader
You can customize your reader to load parameter with a different name etc.
-
Write a tensor variable to the store.
Declaration
Swift
public func write(_ key: String, variable: DynamicGraph_Any, codec: Codec = [])
Parameters
key
The key corresponding to a particular tensor.
variable
The tensor variable to be persisted.
-
Declaration
Swift
public enum ModelWriterResult
-
Write a model to the store.
Declaration
Swift
public func write( _ key: String, model: Model, codec: Codec = [], writer: ((String, NNC.AnyTensor) -> ModelWriterResult)? = nil )
Parameters
key
The key corresponding to a particular model.
model
The model where its parameters to be persisted.
writer
You can customize your writer to writer parameter with a different name or skip entirely.
-
Retrieve a list of all tensors in this file. This reads from the disk and could take some time to finish.
Declaration
Swift
public var keys: [String] { get }
-
Remove one tensor by its key.
Declaration
Swift
public func remove(_ key: String)
-
Remove all tensors from the store. This also vacuums the store to minimize its size.
Declaration
Swift
public func removeAll()
-
Explicit vacuum the database.
Declaration
Swift
public func vacuum()
-
Wrap the database ops in a transaction.
Declaration
Swift
public func withTransaction<Result>(_ closure: () throws -> Result) rethrows -> Result