Description
I am writing an rrule
for *(::Struct, arr)
where the structure and function look like,
struct Struct where {T<:Real}
x # stuff that can't be differentiated
y::T
end
*(s::Struct, arr) = y * x(arr)
However, I am unable to test my rrule
, even with a manually provided tangent for an instance of Struct
that looks like Tangent{Struct}(;x=NoTangent(), y=one(T))
.
The reason seems to be that finite differences tries to to_vec
the instance of struct. Given that the struct is not completely ignored, only the field x
, it ends up trying to to_vec
the field x
as well. But this field is a reference to a rather crazy mutable structure with circular references, and so I end up with an error, and am unable to test that the rrule
is correct w.r.t. y
.
(To make it more concrete, the structure in question is a ScaledPlan
from AbstractFFTs
and the field x
refers to a primitive FFT plan from FFTW
, which is mutable because of its pinv
cache.)
Ideally, it shouldn't matter what value is in the field x
, since it is marked as NoTangent
in the user-provided tangent? Just as how the entire input gets ignored if it is marked as NoTangent
.