o.velocity contains a velocity array for each parameter array in the model being optimized. One way to do that would be to create another instance of the model type that contains velocities instead of parameters, but a lighter-weight option is to use an
IdDict, a data structure that allows using the object identities (essentially, “memory locations”) of arbitrary Julia values as keys.
To be more concrete, if you used a normal
Dictionary, then looking up a velocity array that corresponds to a parameter array would require hashing the entire parameter array, when just hashing the parameter array’s location in memory is enough (and in fact we want two parameter arrays that happen to have the same values in them to still have independent velocity arrays).
get! function looks up a key in any dict-like object and, if the key isn’t present, creates an entry with that key and a given initial value (in this case
zero(x)); either way it then returns the value for the key.