Closed
Description
From what I understand Libtask
does not deepcopy struct by default when used in TapedTask
. For example this shares the initial model:
mutable struct Model
t::TArray
n::Int
Model(n::Int) = new(TArray(Float64,n), n)
end
function (model::Model)()
model.t[1] = 1
Libtask.produce(model.t[1])
for i in 2:model.n
r = rand(Normal())
model.t[i] = model.t[i-1] + r
Libtask.produce(model.t[i])
end
end
model = Model(4)
ttask = Libtask.TapedTask(model)
Libtask.consume(ttask) # -> 1
ttask2 = copy(ttask)
Libtask.consume(ttask) # -> 1 + r1
Libtask.consume(ttask2) # -> 1 + r1 + r2 (!)
To get the expected result we need to add:
Libtask.tape_copy(model::Model) = deepcopy(model)
which is hidden somewhere (the comment itself is very helpful)
Libtask.jl/src/tapedfunction.jl
Lines 351 to 360 in f4941a0
Maybe we could mention it somewhere in the readme since it's required to get AdvancedPS.PG
running properly.
Metadata
Metadata
Assignees
Labels
No labels