You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
functiondifferential_to_vec(primal, differential)
functionfrom_vec(differential_vec)
return thing_like_differential
endreturn vector_form_differential, from_vec
end
This function literally just ties together a primal and a differential, so that we have enough information to to_vec the differential. That is all.
The text was updated successfully, but these errors were encountered:
Whether or not this is helpful depends on whether we do #97 . If we do it, it's redundant. If, for some reason, we decide not to do it, then this is important.
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
toDifferentials
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 shouldto_vec(::Zero)
return? SinceZero
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 aFill
. In this case, naively applyingto_vec
to both yields vectors of different lengths sinceto_vec(::Fill)
returns a length-1 vector as only a single number is required to uniquely specify aFill
, whileto_vec(::Vector)
is essentially the identity operation.I proposed to introduce a new function as follows:
This function literally just ties together a primal and a differential, so that we have enough information to
to_vec
the differential. That is all.The text was updated successfully, but these errors were encountered: