Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FAQ section to docs #1343

Merged
merged 11 commits into from
Mar 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/EnzymeCore/src/EnzymeCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ Mark a function argument `x` of [`autodiff`](@ref Enzyme.autodiff) as duplicated
auto-differentiate in respect to such arguments, with `dx` acting as an
accumulator for gradients (so ``\\partial f / \\partial x`` will be *added to*)
`∂f_∂x`.

# Note

Enzyme forces `x` and `∂f_∂x` to have the same types when constructing `Duplicated`.
This is not a mathematical requirement, but rather a guardrail to prevent user error.
The memory locations of `x` and `∂f_∂x` are accessed in the same way by the differentiation code, so they should have the same data layout.
Equality of types is an approximation of this condition.

In some ways, type equality is too strict, but in other ways it is not strict enough.
gdalle marked this conversation as resolved.
Show resolved Hide resolved
For instance, if `x` and `∂f_∂x` are sparse arrays, their sparsity pattern should be identical, but this is not encoded in the type.
To make sure that `∂f_∂x` has the right data layout, create it with `∂f_∂x = Enzyme.make_zero(x)`.
gdalle marked this conversation as resolved.
Show resolved Hide resolved
"""
struct Duplicated{T} <: Annotation{T}
val::T
Expand Down
Loading