@@ -30,11 +30,14 @@ Base.@kwdef struct Trajectory{C,S,T}
3030 function Trajectory (container:: C , sampler:: S , controller:: T ) where {C,S,T<: AsyncInsertSampleRatioController }
3131 t = Threads. @spawn while true
3232 for msg in controller. ch_in
33- if msg. f === Base. push! || msg. f === Base. append!
34- n_pre = length (container)
35- msg. f (container, msg. args... ; msg. kw... )
36- n_post = length (container)
37- controller. n_inserted += n_post - n_pre
33+ if msg. f === Base. push!
34+ x, = msg. args
35+ msg. f (container, x)
36+ controller. n_inserted += 1
37+ elseif msg. f === Base. append!
38+ x, = msg. args
39+ msg. f (container, x)
40+ controller. n_inserted += length (x)
3841 else
3942 msg. f (container, msg. args... ; msg. kw... )
4043 end
@@ -65,11 +68,11 @@ function Base.bind(t::Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController}
6568 bind (t. controler. ch_out, task)
6669end
6770
71+ # !!! by default we assume `x` is a complete example which contains all the traces
72+ # When doing partial inserting, the result of undefined
6873function Base. push! (t:: Trajectory , x)
69- n_pre = length (t. container)
7074 push! (t. container, x)
71- n_post = length (t. container)
72- on_insert! (t. controller, n_post - n_pre)
75+ on_insert! (t. controller, 1 )
7376end
7477
7578struct CallMsg
@@ -78,16 +81,17 @@ struct CallMsg
7881 kw:: Any
7982end
8083
81- Base. push! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController} , args ... ; kw ... ) = put! (t. controller. ch_in, CallMsg (Base. push!, args, kw ))
82- Base. append! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController} , args ... ; kw ... ) = put! (t. controller. ch_in, CallMsg (Base. append!, args, kw ))
84+ Base. push! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController} , x ) = put! (t. controller. ch_in, CallMsg (Base. push!, (x,), NamedTuple () ))
85+ Base. append! (t:: Trajectory{<:Any,<:Any,<:AsyncInsertSampleRatioController} , x ) = put! (t. controller. ch_in, CallMsg (Base. append!, (x,), NamedTuple () ))
8386
8487function Base. append! (t:: Trajectory , x)
85- n_pre = length (t. container)
8688 append! (t. container, x)
87- n_post = length (t. container)
88- on_insert! (t. controller, n_post - n_pre)
89+ on_insert! (t. controller, length (x))
8990end
9091
92+ # !!! bypass the controller
93+ sample (t:: Trajectory ) = sample (t. sampler, t. container)
94+
9195function Base. take! (t:: Trajectory )
9296 res = on_sample! (t. controller)
9397 if isnothing (res)
0 commit comments