Skip to content
Closed
Changes from all commits
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
7 changes: 6 additions & 1 deletion src/tangent_types/thunks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ function LinearAlgebra.LAPACK.trsyl!(transa, transb, A, B, C::AbstractThunk, isg
return throw(MutateThunkException())
end

@inline _usethunks() = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this needs an @inline

rrule(::typeof(_usethunks)) = false, _ -> (NoTangent(),)

"""
@thunk expr

Expand All @@ -136,7 +139,7 @@ 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))
return :(Thunk($(esc(func))))
return :(_usethunks() ? Thunk($(esc(func))) : $(esc(body)))
end

"""
Expand Down Expand Up @@ -229,6 +232,8 @@ struct InplaceableThunk{T<:Thunk,F} <: AbstractThunk
val::T
end

InplaceableThunk(add!, val) = val # if _usethunks() disables @thunk, then bypass this too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong?


unthunk(x::InplaceableThunk) = unthunk(x.val)

function Base.show(io::IO, x::InplaceableThunk)
Expand Down