Skip to content

Commit 7735e45

Browse files
committed
Change argument order on InplaceableThunk
1 parent 4b33290 commit 7735e45

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ for T in (:Thunk, :InplaceableThunk)
5454
return unthunk(x)
5555
end
5656
end
57+
58+
59+
Base.@deprecate InplaceableThunk(t::Thunk, add!) InplaceableThunk(add!, t)

src/differentials/thunks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Base.convert(::Type{<:Thunk}, a::AbstractZero) = @thunk(a)
197197

198198

199199
"""
200-
InplaceableThunk(val::Thunk, add!::Function)
200+
InplaceableThunk(add!::Function, val::Thunk)
201201
202202
A wrapper for a `Thunk`, that allows it to define an inplace `add!` function.
203203
@@ -209,8 +209,8 @@ Most operations on an `InplaceableThunk` treat it just like a normal `Thunk`;
209209
and destroy its inplacability.
210210
"""
211211
struct InplaceableThunk{T<:Thunk,F} <: AbstractThunk
212-
val::T
213212
add!::F
213+
val::T
214214
end
215215

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

test/accumulation.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
@testset "AbstractThunk $(typeof(thunk))" for thunk in (
9191
@thunk(-1.0*ones(2, 2)),
92-
InplaceableThunk(@thunk(-1.0*ones(2, 2)), x -> x .-= ones(2, 2)),
92+
InplaceableThunk(x -> x .-= ones(2, 2), @thunk(-1.0*ones(2, 2))),
9393
)
9494
@testset "in place" begin
9595
accumuland = [1.0 2.0; 3.0 4.0]
@@ -109,10 +109,10 @@
109109
end
110110

111111
@testset "not actually inplace but said it was" begin
112-
ithunk = InplaceableThunk(
113-
@thunk(@assert false), # this should never be used in this test
114-
x -> 77*ones(2, 2) # not actually inplace (also wrong)
115-
)
112+
# thunk should never be used in this test
113+
ithunk = InplaceableThunk(@thunk(@assert false)) do x
114+
77*ones(2, 2) # not actually inplace (also wrong)
115+
end
116116
accumuland = ones(2, 2)
117117
@assert ChainRulesCore.debug_mode() == false
118118
# without debug being enabled should return the result, not error
@@ -127,7 +127,7 @@
127127

128128
@testset "showerror BadInplaceException" begin
129129
BadInplaceException = ChainRulesCore.BadInplaceException
130-
ithunk = InplaceableThunk(@thunk(@assert false), x̄->nothing)
130+
ithunk = InplaceableThunk(->nothing, @thunk(@assert false))
131131
msg = sprint(showerror, BadInplaceException(ithunk, [22], [23]))
132132
@test occursin("22", msg)
133133

test/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ end
2828
@test_deprecated (@thunk(3))() == 3
2929
@test_deprecated (@thunk(@thunk(3)))() isa Thunk
3030
end
31+
32+
@testset "Deprecated: Inplacable Thunk argument order" begin
33+
@test (@test_deprecated InplaceableThunk(@thunk([1]), x->x.+=1)) isa InplaceableThunk
34+
end

test/differentials/thunks.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
@test @thunk(3) isa Thunk
55

66
@testset "==" begin
7-
@test @thunk(3.2) == InplaceableThunk(@thunk(3.2), x -> x + 3.2)
7+
@test @thunk(3.2) == InplaceableThunk(x -> x + 3.2, @thunk(3.2))
88
@test @thunk(3.2) == 3.2
9-
@test 3.2 == InplaceableThunk(@thunk(3.2), x -> x + 3.2)
9+
@test 3.2 == InplaceableThunk(x -> x + 3.2, @thunk(3.2))
1010
end
1111

1212
@testset "iterate" begin

0 commit comments

Comments
 (0)