After further experimentation, I figured out that my problem lies elsewhere. In particular, it has to do with how I use the struct layer
. I have created the following MWE that demonstrates the issue I am facing:
struct example{F}
f::F
end
function (e::example)(x)
e.f(x)
end
function (V::Vector{example})(x)
out = x
for v in V
out = v(out)
end
out
end
Let’s put this to work via the following:
V = [example(cos); example(sin)]
V(1.0) # try whether this works - yes it does
@code_warntype V(1.0) # check type stability - it fails!
Please help me understand why there is a type instability when calling V(1.0)
. I believe I am facing the same issue in my simple neural network code.
I suspect the issue has to do with me instantiating a Vector{example}
type when I create V
.