Skip to content

Commit aa24438

Browse files
committed
add!! with Thunk
1 parent 3352d15 commit aa24438

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesCore"
22
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
3-
version = "0.9.41"
3+
version = "0.9.42"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/accumulation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function add!!(x, t::InplaceableThunk)
2424
end
2525
end
2626

27+
add!!(x::AbstractArray, y::Thunk) = add!!(x, unthunk(y))
28+
2729
function add!!(x::AbstractArray{<:Any, N}, y::AbstractArray{<:Any, N}) where N
2830
return if is_inplaceable_destination(x)
2931
x .+= y

test/accumulation.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,21 @@
8787
end
8888
end
8989

90-
@testset "InplaceableThunk" begin
91-
ithunk = InplaceableThunk(
92-
@thunk(-1.0*ones(2, 2)),
93-
x -> x .-= ones(2, 2)
94-
)
95-
90+
@testset "AbstractThunk $(typeof(thunk))" for thunk in (
91+
@thunk(-1.0*ones(2, 2)),
92+
InplaceableThunk(@thunk(-1.0*ones(2, 2)), x -> x .-= ones(2, 2)),
93+
)
9694
@testset "in place" begin
9795
accumuland = [1.0 2.0; 3.0 4.0]
98-
ret = add!!(accumuland, ithunk)
96+
ret = add!!(accumuland, thunk)
9997
@test ret == [0.0 1.0; 2.0 3.0] # must return right answer
10098
@test ret === accumuland # must be same object
10199
end
102100

103101
@testset "out of place" begin
104102
accumuland = @SMatrix [1.0 2.0; 3.0 4.0]
105103

106-
ret = add!!(accumuland, ithunk)
104+
ret = add!!(accumuland, thunk)
107105
@test ret == [0.0 1.0; 2.0 3.0] # must return right answer
108106
@test ret !== accumuland # must not be same object
109107
@test accumuland == [1.0 2.0; 3.0 4.0] # must not have mutated

0 commit comments

Comments
 (0)