pub struct RateBackendBitSession { /* private fields */ }Expand description
Stateful bit-level session over a rate backend.
Byte-packed sessions keep the underlying backend byte-native and expose it
through a lazy prefix-mass view. They therefore require whole-byte stream
boundaries: total_bits, when provided, must be a multiple of 8, and
finish must not leave a dangling partial byte. Within one buffered byte,
callers must also stay within either adaptive updates or conditioning-only
updates; switching modes mid-byte is rejected because the backend only
commits whole-byte symbols. Binary-token sessions model each bit either
through the backend’s native binary-token application or, for byte-native
backends, by adapting the predictor to the literal byte symbols 0 and 1
and renormalizing those two choices.
The complete checkpoint/restore contract is available in both Rust and
Python (infotheory_rs.RateBackendBitSession with
RateBackendBitSessionCheckpoint).
Implementations§
Source§impl RateBackendBitSession
impl RateBackendBitSession
Sourcepub fn from_backend(
backend: CompiledRateBackend,
total_bits: Option<u64>,
semantics: BitStreamSemantics,
) -> InfotheoryResult<Self>
pub fn from_backend( backend: CompiledRateBackend, total_bits: Option<u64>, semantics: BitStreamSemantics, ) -> InfotheoryResult<Self>
Create a bit session from an explicit compiled backend.
For BitStreamSemantics::BytePacked, total_bits must be None or a
multiple of 8.
Sourcepub fn from_spec(
backend: RateBackend,
total_bits: Option<u64>,
semantics: BitStreamSemantics,
) -> InfotheoryResult<Self>
pub fn from_spec( backend: RateBackend, total_bits: Option<u64>, semantics: BitStreamSemantics, ) -> InfotheoryResult<Self>
Create a bit session from a wrapper backend spec.
For BitStreamSemantics::BytePacked, total_bits must be None or a
multiple of 8.
Sourcepub fn predict_bit(&mut self) -> BinaryPrediction
pub fn predict_bit(&mut self) -> BinaryPrediction
Predict the next bit without updating state.
Sourcepub fn predict_one(&mut self) -> f64
pub fn predict_one(&mut self) -> f64
Convenience prediction for P(bit = 1).
Sourcepub fn checkpoint(&mut self) -> RateBackendBitSessionCheckpoint
pub fn checkpoint(&mut self) -> RateBackendBitSessionCheckpoint
Capture a reversible checkpoint for later restoration.
Backends that store full snapshots restore bit-identical floating-point predictions. Backends that use compact reversible journals may differ by a few ULP after restore because floating-point accumulators are replayed instead of cloned byte-for-byte.
Sourcepub fn restore_checkpoint(
&mut self,
checkpoint: &RateBackendBitSessionCheckpoint,
) -> InfotheoryResult<()>
pub fn restore_checkpoint( &mut self, checkpoint: &RateBackendBitSessionCheckpoint, ) -> InfotheoryResult<()>
Restore the session to a previously captured checkpoint.
Snapshot-backed predictors restore bit-identical predictions. Compact journaled predictors restore the same discrete predictor state and stream position, with predictions equal up to floating-point round-off.
A checkpoint is tied to the backend and bit-stream semantics it was created from. Restoring a checkpoint into a different bit session is a programmer error and returns an explicit runtime error.
Sourcepub fn clear_checkpoints_if_supported(&mut self)
pub fn clear_checkpoints_if_supported(&mut self)
Clear compact checkpoint journals when no stored checkpoints remain.
This is an optimization hint for backends with journaled checkpoints. Calling it while a checkpoint may still be restored violates the checkpoint contract. Byte-packed sessions preserve the invariant between buffered prefix state and predictor-native prefix state before clearing.
Sourcepub fn try_step_bit(&mut self, bit: bool) -> InfotheoryResult<BinaryPrediction>
pub fn try_step_bit(&mut self, bit: bool) -> InfotheoryResult<BinaryPrediction>
Predict and then observe one adaptive/fitting bit.
Sourcepub fn step_bit(&mut self, bit: bool) -> BinaryPrediction
pub fn step_bit(&mut self, bit: bool) -> BinaryPrediction
Predict and then observe one adaptive/fitting bit.
Sourcepub fn try_observe_bit(&mut self, bit: bool) -> InfotheoryResult<()>
pub fn try_observe_bit(&mut self, bit: bool) -> InfotheoryResult<()>
Observe one adaptive/fitting bit.
Sourcepub fn observe_bit(&mut self, bit: bool)
pub fn observe_bit(&mut self, bit: bool)
Observe one adaptive/fitting bit.
Sourcepub fn try_condition_bit(&mut self, bit: bool) -> InfotheoryResult<()>
pub fn try_condition_bit(&mut self, bit: bool) -> InfotheoryResult<()>
Advance conditioning state with one bit without fitting/adapting.
Sourcepub fn condition_bit(&mut self, bit: bool)
pub fn condition_bit(&mut self, bit: bool)
Advance conditioning state with one bit without fitting/adapting.
Sourcepub fn reset_frozen(&mut self, total_bits: Option<u64>) -> InfotheoryResult<()>
pub fn reset_frozen(&mut self, total_bits: Option<u64>) -> InfotheoryResult<()>
Reset dynamic conditioning state while preserving fitted parameters/statistics.
Sourcepub fn finish(&mut self) -> InfotheoryResult<()>
pub fn finish(&mut self) -> InfotheoryResult<()>
Finalize the underlying stream if the backend needs it.
Trait Implementations§
Source§impl Clone for RateBackendBitSession
impl Clone for RateBackendBitSession
Source§fn clone(&self) -> RateBackendBitSession
fn clone(&self) -> RateBackendBitSession
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl OnlineBitPredictor for RateBackendBitSession
impl OnlineBitPredictor for RateBackendBitSession
Source§fn begin_bit_stream(
&mut self,
total_bits: Option<u64>,
semantics: BitStreamSemantics,
) -> Result<(), String>
fn begin_bit_stream( &mut self, total_bits: Option<u64>, semantics: BitStreamSemantics, ) -> Result<(), String>
Source§fn bit_prediction(&mut self) -> BinaryPrediction
fn bit_prediction(&mut self) -> BinaryPrediction
Source§fn update_bit(&mut self, bit: bool)
fn update_bit(&mut self, bit: bool)
Source§fn update_bit_frozen(&mut self, bit: bool)
fn update_bit_frozen(&mut self, bit: bool)
Auto Trait Implementations§
impl Freeze for RateBackendBitSession
impl !RefUnwindSafe for RateBackendBitSession
impl Send for RateBackendBitSession
impl !Sync for RateBackendBitSession
impl Unpin for RateBackendBitSession
impl UnsafeUnpin for RateBackendBitSession
impl !UnwindSafe for RateBackendBitSession
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.