pub struct TraceBuilder { /* private fields */ }Expand description
Efficient trace builder that minimizes allocations during construction.
TraceBuilder uses pre-allocated collections and provides type-specific methods to build traces efficiently with minimal memory overhead.
Example:
let mut builder = TraceBuilder::new();
// Add different types of samples efficiently
builder.add_sample(addr!("x"), 1.5, -0.5);
builder.add_sample_bool(addr!("flag"), true, -0.693);
builder.add_sample_u64(addr!("count"), 42, -1.0);
// Add observations and factors
builder.add_observation(-2.3); // Likelihood contribution
builder.add_factor(-0.1); // Soft constraint
// Build final trace
let trace = builder.build();
assert_eq!(trace.choices.len(), 3);Implementations§
Source§impl TraceBuilder
impl TraceBuilder
pub fn new() -> Self
pub fn with_capacity(_capacity: usize) -> Self
pub fn add_sample(&mut self, addr: Address, value: f64, log_prob: f64)
pub fn add_sample_bool(&mut self, addr: Address, value: bool, log_prob: f64)
pub fn add_sample_u64(&mut self, addr: Address, value: u64, log_prob: f64)
pub fn add_sample_usize(&mut self, addr: Address, value: usize, log_prob: f64)
pub fn add_observation(&mut self, log_likelihood: f64)
pub fn add_factor(&mut self, log_weight: f64)
pub fn build(self) -> Trace
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TraceBuilder
impl RefUnwindSafe for TraceBuilder
impl Send for TraceBuilder
impl Sync for TraceBuilder
impl Unpin for TraceBuilder
impl UnwindSafe for TraceBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more