PooledPriorHandler

Struct PooledPriorHandler 

Source
pub struct PooledPriorHandler<'a, R: RngCore> {
    pub rng: &'a mut R,
    pub trace_builder: TraceBuilder,
    pub pool: &'a mut TracePool,
}
Expand description

Optimized handler that uses memory pooling for zero-allocation inference.

PooledPriorHandler combines TraceBuilder efficiency with TracePool reuse to achieve zero-allocation execution after pool warm-up.

Example:


let mut pool = TracePool::new(10);
let mut rng = StdRng::seed_from_u64(42);

// Run model with pooled handler
let (result, trace) = runtime::handler::run(
    PooledPriorHandler {
        rng: &mut rng,
        trace_builder: TraceBuilder::new(),
        pool: &mut pool,
    },
    sample(addr!("x"), Normal::new(0.0, 1.0).unwrap())
);

// Return trace to pool for reuse
pool.return_trace(trace);

// Subsequent runs will reuse pooled traces (zero allocations)
assert!(result.is_finite());

Fields§

§rng: &'a mut R§trace_builder: TraceBuilder§pool: &'a mut TracePool

Trait Implementations§

Source§

impl<'a, R: RngCore> Handler for PooledPriorHandler<'a, R>

Source§

fn on_sample_f64(&mut self, addr: &Address, dist: &dyn Distribution<f64>) -> f64

Handle an f64 sampling operation (continuous distributions).
Source§

fn on_sample_bool( &mut self, addr: &Address, dist: &dyn Distribution<bool>, ) -> bool

Handle a bool sampling operation (Bernoulli).
Source§

fn on_sample_u64(&mut self, addr: &Address, dist: &dyn Distribution<u64>) -> u64

Handle a u64 sampling operation (Poisson, Binomial).
Source§

fn on_sample_usize( &mut self, addr: &Address, dist: &dyn Distribution<usize>, ) -> usize

Handle a usize sampling operation (Categorical).
Source§

fn on_observe_f64( &mut self, _: &Address, dist: &dyn Distribution<f64>, value: f64, )

Handle an f64 observation operation.
Source§

fn on_observe_bool( &mut self, _: &Address, dist: &dyn Distribution<bool>, value: bool, )

Handle a bool observation operation.
Source§

fn on_observe_u64( &mut self, _: &Address, dist: &dyn Distribution<u64>, value: u64, )

Handle a u64 observation operation.
Source§

fn on_observe_usize( &mut self, _: &Address, dist: &dyn Distribution<usize>, value: usize, )

Handle a usize observation operation.
Source§

fn on_factor(&mut self, logw: f64)

Handle a factor operation. Read more
Source§

fn finish(self) -> Trace

Finalize the handler and return the accumulated trace. Read more

Auto Trait Implementations§

§

impl<'a, R> Freeze for PooledPriorHandler<'a, R>

§

impl<'a, R> RefUnwindSafe for PooledPriorHandler<'a, R>
where R: RefUnwindSafe,

§

impl<'a, R> Send for PooledPriorHandler<'a, R>
where R: Send,

§

impl<'a, R> Sync for PooledPriorHandler<'a, R>
where R: Sync,

§

impl<'a, R> Unpin for PooledPriorHandler<'a, R>

§

impl<'a, R> !UnwindSafe for PooledPriorHandler<'a, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V