Skip to content

Commit

Permalink
Document lookup decoder models
Browse files Browse the repository at this point in the history
Includes several new doc tests.
  • Loading branch information
robamler committed Aug 28, 2024
1 parent 1d2e70d commit 9a89565
Show file tree
Hide file tree
Showing 7 changed files with 666 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ impl<B: Seek> Seek for Reverse<B> {
/// );
/// // Encoding *a few* more symbols works ...
/// cursor_coder.encode_iid_symbols_reverse(65..75, &model).unwrap();
/// // ... but at some point we'll run out of buffer space.
/// // ... but at some point we'll run out of buffer space:
/// assert_eq!(
/// cursor_coder.encode_iid_symbols_reverse(50..65, &model),
/// Err(CoderError::Backend(constriction::backends::BoundedWriteError::OutOfSpace))
Expand Down
2 changes: 1 addition & 1 deletion src/stream/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub trait EncoderModel<const PRECISION: usize>: EntropyModel<PRECISION> {
/// let probabilities = vec![1u32 << 21, 1 << 23, 1 << 22, 1 << 21];
/// let model = DefaultNonContiguousCategoricalEncoderModel // "Default" uses `PRECISION = 24`
/// ::from_symbols_and_nonzero_fixed_point_probabilities(
/// symbols.iter().copied(), &probabilities, false)
/// symbols.iter().copied(), probabilities.iter().copied(), false)
/// .unwrap();
///
/// assert_eq!(model.floating_point_probability::<f64>('a'), 0.125);
Expand Down
3 changes: 2 additions & 1 deletion src/stream/model/categorical/contiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ impl<Probability: BitArray, const PRECISION: usize>
/// assert_eq!(probabilities.iter().sum::<u32>(), 1 << 24);
///
/// let model = DefaultContiguousCategoricalEntropyModel
/// ::from_nonzero_fixed_point_probabilities(&probabilities, false).unwrap();
/// ::from_nonzero_fixed_point_probabilities(
/// probabilities.iter().copied(), false).unwrap();
/// let symbol_table = model.floating_point_symbol_table::<f64>().collect::<Vec<_>>();
/// assert_eq!(
/// symbol_table,
Expand Down
11 changes: 4 additions & 7 deletions src/stream/model/categorical/lazy_contiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ pub type SmallLazyContiguousCategoricalEntropyModel<F = f32, Pmf = Vec<F>> =
///
/// # When Should I Use This Type of Entropy Model?
///
/// - Use this type if you want to encode or decode only a few (or even just a single)
/// - Use this type if you want to encode or decode only very few (or even just a single)
/// symbol with the same categorical distribution.
/// - Use [`ContiguousCategoricalEntropyModel`], [`NonContiguousCategoricalEncoderModel`],
/// or [`NonContiguousCategoricalDecoderModel`] if you want to encode many symbols with
/// the same categorical distribution (more precisely, if the number of encoded or decoded
/// symbols is on the order of, or larger than, the square root of the size of the
/// alphabet, i.e., the support of the model). These models precalculate the fixed-point
/// or [`NonContiguousCategoricalDecoderModel`] if you want to encode several symbols with
/// the same categorical distribution. These models precalculate the fixed-point
/// approximation of the entire cumulative distribution function at model construction.
/// - Use [`ContiguousLookupDecoderModel`] or [`NonContiguousLookupDecoderModel`] (together
/// with a small `Probability` data type, see [discussion of presets]) for decoding a
Expand All @@ -72,7 +70,7 @@ pub type SmallLazyContiguousCategoricalEntropyModel<F = f32, Pmf = Vec<F>> =
/// [`NonContiguousCategoricalDecoderModel`].
/// - encoding a symbol (calling [`EncoderModel::left_cumulative_and_probability`]):
/// - runtime cost: `Θ(1)` (cheaper than for [`NonContiguousCategoricalEncoderModel`]
/// since it compiles to a simiple array lookup rather than a `HashMap` lookup)
/// since it compiles to a simple array lookup rather than a `HashMap` lookup)
/// - memory footprint: no heap allocations, constant stack space.
/// - decoding a symbol (calling [`DecoderModel::quantile_function`]):
/// - runtime cost: `Θ(log(N))` (both expected and worst-case; probably slightly cheaper
Expand Down Expand Up @@ -101,7 +99,6 @@ pub type SmallLazyContiguousCategoricalEntropyModel<F = f32, Pmf = Vec<F>> =
/// [compatibility table for `ContiguousCategoricalEntropyModel`]:
/// crate::stream::model::ContiguousCategoricalEntropyModel#compatibility-table
/// [discussion of presets]: crate::stream#presets

#[derive(Debug, Clone, Copy)]
pub struct LazyContiguousCategoricalEntropyModel<Probability, F, Pmf, const PRECISION: usize> {
/// Invariants:
Expand Down
Loading

0 comments on commit 9a89565

Please sign in to comment.