Optimizers often use per-parameter auxiliary variables (e.g. Adam maintains first and second moments for each parameter).
Such auxiliary variables are naturally represented as a instance of a ParameterAggregate
-conforming type (because they have one value for each parameter).
Complex iteration and mutation of parameters, alongside gradients and auxiliary variables, is enabled using key paths as described here.
Learn more about key paths here: https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md Key path API documentation: https://developer.apple.com/documentation/swift/swift_standard_library/key_path_expressions