pub struct CowTrace { /* private fields */ }Expand description
Copy-on-write trace for efficient memory sharing in MCMC operations.
Most MCMC operations modify only a small number of choices, so CowTrace
shares the majority of trace data between states using Arc<BTreeMap>.
Example:
// Convert from regular trace
let cow_trace = CowTrace::from_trace(trace);
// Clone is very efficient (shares memory)
let clone1 = cow_trace.clone();
let clone2 = cow_trace.clone();
// Modification triggers copy-on-write only when needed
let mut modified = clone1.clone();
modified.insert_choice(addr!("new"), Choice {
addr: addr!("new"),
value: ChoiceValue::F64(42.0),
logp: -1.0,
});
// Now `modified` has its own copy, others still shareImplementations§
Source§impl CowTrace
impl CowTrace
Sourcepub fn from_trace(trace: Trace) -> Self
pub fn from_trace(trace: Trace) -> Self
Convert from regular trace.
Sourcepub fn choices_mut(&mut self) -> &mut BTreeMap<Address, Choice>
pub fn choices_mut(&mut self) -> &mut BTreeMap<Address, Choice>
Get mutable access to choices, copying if necessary.
Sourcepub fn insert_choice(&mut self, addr: Address, choice: Choice)
pub fn insert_choice(&mut self, addr: Address, choice: Choice)
Insert a choice, copying the map if needed.
Sourcepub fn total_log_weight(&self) -> f64
pub fn total_log_weight(&self) -> f64
Total log weight.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CowTrace
impl RefUnwindSafe for CowTrace
impl Send for CowTrace
impl Sync for CowTrace
impl Unpin for CowTrace
impl UnwindSafe for CowTrace
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