-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
491 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
ext/DifferentiationInterfaceEnzymeExt/forward_allocating.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Primitives | ||
|
||
function DI.value_and_pushforward!( | ||
_dy::Real, backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing | ||
) | ||
y, new_dy = autodiff(backend.mode, f, Duplicated, Duplicated(x, dx)) | ||
return y, new_dy | ||
end | ||
|
||
function DI.value_and_pushforward!( | ||
dy::AbstractArray, backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing | ||
) | ||
y, new_dy = autodiff(backend.mode, f, Duplicated, Duplicated(x, dx)) | ||
dy .= new_dy | ||
return y, dy | ||
end | ||
|
||
function DI.pushforward!( | ||
_dy::Real, backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing | ||
) | ||
new_dy = only(autodiff(backend.mode, f, DuplicatedNoNeed, Duplicated(x, dx))) | ||
return new_dy | ||
end | ||
|
||
function DI.pushforward!( | ||
dy::AbstractArray, backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing | ||
) | ||
new_dy = only(autodiff(backend.mode, f, DuplicatedNoNeed, Duplicated(x, dx))) | ||
dy .= new_dy | ||
return dy | ||
end | ||
|
||
function DI.value_and_pushforward( | ||
backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing | ||
) | ||
y, dy = autodiff(backend.mode, f, Duplicated, Duplicated(x, dx)) | ||
return y, dy | ||
end | ||
|
||
function DI.pushforward(backend::AutoForwardEnzyme, f, x, dx, extras::Nothing=nothing) | ||
dy = only(autodiff(backend.mode, f, DuplicatedNoNeed, Duplicated(x, dx))) | ||
return dy | ||
end | ||
|
||
## Utilities | ||
|
||
function DI.value_and_jacobian( | ||
backend::AutoForwardEnzyme, f, x::AbstractArray, extras::Nothing=nothing | ||
) | ||
y = f(x) | ||
jac = jacobian(backend.mode, f, x) | ||
# see https://github.com/EnzymeAD/Enzyme.jl/issues/1332 | ||
return y, reshape(jac, length(y), length(x)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Primitives | ||
|
||
function DI.value_and_pushforward!( | ||
y::AbstractArray, | ||
dy::AbstractArray, | ||
backend::AutoForwardEnzyme, | ||
f!, | ||
x, | ||
dx, | ||
extras::Nothing=nothing, | ||
) | ||
dx_sametype = convert(typeof(x), dx) | ||
dy_sametype = convert(typeof(y), dy) | ||
autodiff( | ||
backend.mode, f!, Const, Duplicated(y, dy_sametype), Duplicated(x, dx_sametype) | ||
) | ||
dy .= dy_sametype | ||
return y, dy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.