I think the adjoint you need is:
@adjoint Matrix(a::MyMat) = a.m, Δ -> (MyMat(Matrix(Δ), 0), )
I think what’s happening is that the default version for this doesn’t quite work with your matrix type and so it defaults to returning a named tuple (m=.., n=..)
rather than a proper MyMat
, but then the next step in the backpropagation tries to take the transpose
of that named tuple which doesn’t work.
Btw, this is in some sense the same question I asked here (How to deal with Zygote sometimes "pirating" its own adjoints with worse ones?), there is a generic solution given there which might end up being helpful, since this sort of thing tends to happen alot in my experience with Zygote and custom matrix types.