EnzymeAD / EnzymeAD/Enzyme.jl

Mixed type, variable length, memcpy

Open
#1,672 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
586
Forks
108
Avg merge
1d 5h
Merged PRs (30d)
44

Description

I am on Julia 1.10.3 and Enzyme main (5fc23099cdac3dbdfa9d413ee3f17b34759bb6f2). The following works:
```julia
struct A1{T}
x::T
end

struct B{T}
as::T
end

function f1(x, ::Val{AT}) where AT
as = [A1(x) for i in 1:10]
as2 = AT(as)
b = B(as2)
return b.as[1].x
end

autodiff(Reverse, f1, Active, Active(2.0), Const(Val(Array)))[1][1] # Gives 1.0
```
However, adding an unused field to the `struct` makes the gradient disappear:
```julia
struct A2{T}
index::Int
x::T
end

function f2(x, ::Val{AT}) where AT
as = [A2(i, x) for i in 1:10]
as2 = AT(as)
b = B(as2)
return b.as[1].x
end

autodiff(Reverse, f2, Active, Active(2.0), Const(Val(Array)))[1][1] # Gives 0.0, should be 1.0
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.