# Custom stuct and Jacobian: Issue with Zygote not understanding custom struct

**URL:** https://discourse.julialang.org/t/custom-stuct-and-jacobian-issue-with-zygote-not-understanding-custom-struct/123781
**Category:** Specific Domains
**Tags:** zygote, autodiff
**Created:** [December 12, 2024, 6:35pm UTC](https://discourse.julialang.org/t/custom-stuct-and-jacobian-issue-with-zygote-not-understanding-custom-struct/123781 "2024-12-12T18:35:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![KapilKhanal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapilkhanal/32/43976_2.png) [@KapilKhanal](https://discourse.julialang.org/u/KapilKhanal)
#### Post date: [December 12, 2024, 6:35pm UTC](https://discourse.julialang.org/t/custom-stuct-and-jacobian-issue-with-zygote-not-understanding-custom-struct/123781/1 "2024-12-12T18:35:38Z")

</div>

The function with ‘normals’ input is fine but when it’s inside the struct, Zygote returns (nothing)

```julia
# MWE 
struct MeshExample
    normals::AbstractMatrix
    other::Float64
end
function radiation_using_struct(mesh::MeshExample, dof::AbstractVector, omega::AbstractFloat)
    return -1im * omega .* sum(mesh.normals .* dof', dims=2)
end

function radiation_using_normals(normals, dof::AbstractVector, omega::AbstractFloat)
    return -1im * omega .* sum(normals .* dof', dims=2)
end

normals = rand(10, 3)  
mesh = MeshExample(normals, 0.1)
dof = [0, 0, 1]  
omega = 2.0    

println(Zygote.jacobian(m->imag.(radiation_using_struct(mesh,dof,omega)),mesh))
println(Zygote.jacobian(m->imag.(radiation_using_normals(m,dof,omega)),normals))

```

Ideally, I would prefer to use mesh as input.
