# Registering jacobians of composite types in AutoGrad.jl

**URL:** <https://discourse.julialang.org/t/registering-jacobians-of-composite-types-in-autograd-jl/18149>\
**Category:** Machine Learning\
**Created:** [November 29, 2018, 4:19pm UTC](https://discourse.julialang.org/t/registering-jacobians-of-composite-types-in-autograd-jl/18149 "2018-11-29T16:19:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crinders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crinders/32/8434_2.png) [@crinders](https://discourse.julialang.org/u/crinders)\
**Post date:** [November 29, 2018, 4:19pm UTC](https://discourse.julialang.org/t/registering-jacobians-of-composite-types-in-autograd-jl/18149/1 "2018-11-29T16:19:45Z")

</div>

I am posting this question here, because AutoGrad.jl is associated with Knet.

I have a derivative of the `svd`.  
`svd` returns an object of type `SVD`, with components `U`, `Vt`, and `S`. I want to register the derivative with `AutoGrad` such that a scalar function of any or all these subcomponents can be differentiated with for instance `@diff`. Currently, I have not wrapped the derivatives in a composite type, but return a Tuple of tensors. I have successfully registered the derivative with

```julia
@primitive svd(x) dsvd(x)

```

but I can’t test it with `@diff` because it doesn’t do non-scalar functions (that I have found). I must be missing something though, because the following does differentiate:

```julia
h(x) = (x,x.^2, x.^3)
hh(x) = ( a = h(x); sum(a[1]+a[3]))
X = Param([3.0])
y = @diff hh(X) # T(30.0)
grad(y,X) # 28.0

```

Clearly, `AutoGrad` computed the jacobian of the Tuple.  
Any hints on how I should declare the `dsvd` so it can be used to differentiate functions of `svd`?

---

<div class="post-metadata">

**Author:** ![CarloLucibello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlolucibello/32/3278_2.png) [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)\
**Post date:** [November 30, 2018, 9:53am UTC](https://discourse.julialang.org/t/registering-jacobians-of-composite-types-in-autograd-jl/18149/2 "2018-11-30T09:53:07Z")

</div>

Autograd used to support `svd` but the functionality got lost in the revamp for julia 1.0.  
I just opened this issue for your problem [https://github.com/denizyuret/Knet.jl/issues/403](https://github.com/denizyuret/Knet.jl/issues/403)  
but unfortunately I don’t know how to handle composite types

---

<div class="post-metadata">

**Author:** ![crinders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crinders/32/8434_2.png) [@crinders](https://discourse.julialang.org/u/crinders)\
**Post date:** [November 30, 2018, 1:59pm UTC](https://discourse.julialang.org/t/registering-jacobians-of-composite-types-in-autograd-jl/18149/3 "2018-11-30T13:59:29Z")

</div>

I wasn’t aware that `svd` and `qr` had been supported. It would be great to reenable them in `Autograd`. Thanks for opening the issue.
