Skip to content

Commit 5c2979e

Browse files
authored
to_vec for inplaceablethunk (#203)
1 parent 2d334a6 commit 5c2979e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FiniteDifferences"
22
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
3-
version = "0.12.23"
3+
version = "0.12.24"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/to_vec.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,14 @@ function FiniteDifferences.to_vec(t::Thunk)
287287
Thunk_from_vec = v -> @thunk(back(v))
288288
return v, Thunk_from_vec
289289
end
290+
291+
function FiniteDifferences.to_vec(t::InplaceableThunk)
292+
v, back = to_vec(unthunk(t))
293+
function InplaceableThunk_from_vec(v)
294+
return InplaceableThunk(
295+
Δ -> Δ += back(b),
296+
@thunk(back(v))
297+
)
298+
end
299+
return v, InplaceableThunk_from_vec
300+
end

test/to_vec.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ end
249249
end
250250

251251
@testset "Thunks" begin
252-
test_to_vec(@thunk(3.2+4.3))
252+
t = @thunk(3.2+4.3)
253+
test_to_vec(t)
254+
test_to_vec(InplaceableThunk-> Δ += t, t))
253255
end
254256
end
255257

0 commit comments

Comments
 (0)