AD-backend agnostic system defining custom forward and reverse mode rules. This is the light weight core to allow you to define rules for your functions in your packages, without depending on any particular AD system.
So we could pick either x or y depending on which was a valid inplacable_destination.
And maybe also always chose Array if one of them is an Array (since that is the best destination if that has been allocated)
Argument agaist this is that if y comes from identity_pullback(y)=y
and was provided by the user then the user might be using it for something else also.
Kind feel like that shouldn't be our problem though.
Right now
add!!(x, y)
will only ever mutatex
, nevery
. because of the logically linear nature of AD,y
being a differential (i.e. the output of pullback) means it is used exactly once . Which means we are infact free to mutate it, also since this will be it's only use. (same also says why we are always ok to mutatex
) See https://github.com/google-research/dex-lang/issues/401#issuecomment-756996758 (and to a lesser extent https://twitter.com/oxinabox_frames/status/1387722380978622468)So we could pick either
x
ory
depending on which was a validinplacable_destination
. And maybe also always choseArray
if one of them is anArray
(since that is the best destination if that has been allocated)This would solve at least the basic cases of #345