# How to make Zygote not use its default @adjoint for transposition in my custom matrix representation

**URL:** <https://discourse.julialang.org/t/how-to-make-zygote-not-use-its-default-adjoint-for-transposition-in-my-custom-matrix-representation/37422>\
**Category:** General Usage\
**Created:** [April 11, 2020, 10:20pm UTC](https://discourse.julialang.org/t/how-to-make-zygote-not-use-its-default-adjoint-for-transposition-in-my-custom-matrix-representation/37422 "2020-04-11T22:20:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [April 11, 2020, 11:43pm UTC](https://discourse.julialang.org/t/how-to-make-zygote-not-use-its-default-adjoint-for-transposition-in-my-custom-matrix-representation/37422/2 "2020-04-11T23:43:43Z")

</div>

I think the adjoint you need is:

```julia
@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?](https://discourse.julialang.org/t/how-to-deal-with-zygote-sometimes-pirating-its-own-adjoints-with-worse-ones/32579)), 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.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-make-zygote-not-use-its-default-adjoint-for-transposition-in-my-custom-matrix-representation/37422)._
