-
Notifications
You must be signed in to change notification settings - Fork 64
Disable thunks for 2nd order AD #683
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
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # Disable thunks for 2nd order AD. | ||
| _usethunks() = true | ||
| rrule(::typeof(_usethunks)) = false, (NoTangent(),) | ||
|
|
||
| abstract type AbstractThunk <: AbstractTangent end | ||
|
|
||
| struct MutateThunkException <: Exception end | ||
|
|
@@ -141,7 +145,11 @@ macro thunk(body) | |
| # Basically `:(Thunk(() -> $(esc(body))))` but use the location where it is defined. | ||
| # so we get useful stack traces if it errors. | ||
| func = Expr(:->, Expr(:tuple), Expr(:block, __source__, body)) | ||
|
Comment on lines
145
to
147
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could go further and generate a name for the thunk, based on source location, instead of anon. But not this PR perhaps... |
||
| return :(Thunk($(esc(func)))) | ||
| return quote | ||
| $(esc(_usethunks))() ? | ||
| Thunk($(esc(func))) : | ||
| $(esc(func))() | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments on this approach over |
||
| end | ||
|
|
||
| """ | ||
|
|
@@ -233,6 +241,12 @@ and destroy its inplacability. | |
| struct InplaceableThunk{T<:Thunk,F} <: AbstractThunk | ||
| add!::F | ||
| val::T | ||
|
|
||
| function InplaceableThunk(add!::F, val::T) where {F, T} | ||
| _usethunks() ? | ||
| new{T, F}(add!, val) : | ||
| val | ||
| end | ||
| end | ||
|
|
||
| unthunk(x::InplaceableThunk) = unthunk(x.val) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.