-
Notifications
You must be signed in to change notification settings - Fork 27
Description
The to_vec API has served us pretty well for a long time, but there are certain things that it can't handle.
In particular, when applying to_vec to Differentials it is necessary to output something of the same size as the primal to which it will be added when performing finite differencing. For example, what should to_vec(::Zero) return? Since Zero doesn't carry information around with it that tells you what primal it is going to be added to it's not possible to know how to convert it into a vector of an appropriate size.
There are other cases where this bites. For example, if the primal is a Vector and the differential a Fill. In this case, naively applying to_vec to both yields vectors of different lengths since to_vec(::Fill) returns a length-1 vector as only a single number is required to uniquely specify a Fill, while to_vec(::Vector) is essentially the identity operation.
I proposed to introduce a new function as follows:
function differential_to_vec(primal, differential)
function from_vec(differential_vec)
return thing_like_differential
end
return vector_form_differential, from_vec
endThis function literally just ties together a primal and a differential, so that we have enough information to to_vec the differential. That is all.