Skip to content

Commit

Permalink
small upgrade to add!!
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Sep 17, 2022
1 parent f6123ee commit e4ff1ab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/accumulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ function add!!(x, t::InplaceableThunk)
debug_add!(x, t)
end
else
x + t
x + unthunk(t)
end
end

add!!(x::AbstractArray, y::Thunk) = add!!(x, unthunk(y))

function add!!(x::AbstractArray{<:Any,N}, y::AbstractArray{<:Any,N}) where {N}
return if is_inplaceable_destination(x)
x .+= y
if !debug_mode()
x .+= y
else
z = x + y
# Now write junk into x, to test that nothing is relying on mutation, only using returned value:
x .*= NaN
z
end
else
x + y
end
Expand Down

0 comments on commit e4ff1ab

Please sign in to comment.