fn left_cumulative_and_probability(
        &self,
        symbol: impl Borrow<Symbol>,
    ) -> Option<(Probability, Probability::NonZero)> {
        let min_symbol_inclusive = self.quantizer.min_symbol_inclusive;
        let max_symbol_inclusive = self.quantizer.max_symbol_inclusive;
        let free_weight = self.quantizer.free_weight;

        if symbol.borrow() < &min_symbol_inclusive || symbol.borrow() > &max_symbol_inclusive {
            return None;
        };
        let slack = slack(*symbol.borrow(), min_symbol_inclusive);

        // Round both cumulatives *independently* to fixed point precision.
        let left_sided_cumulative = if symbol.borrow() == &min_symbol_inclusive {
            // Corner case: only makes a difference if we're cutting off a fairly significant
            // left tail of the distribution.
            Probability::zero()
        } else {
            let non_leaky: Probability =
                (free_weight * self.inner.distribution((*symbol.borrow()).into() - 0.5)).as_();
            non_leaky + slack
        };

        let right_sided_cumulative = if symbol.borrow() == &max_symbol_inclusive {
            // Corner case: make sure that the probabilities add up to one. The generic
            // calculation in the `else` branch may lead to a lower total probability
            // because we're cutting off the right tail of the distribution and we're
            // rounding down.
            wrapping_pow2(PRECISION)
        } else {
            let non_leaky: Probability =
                (free_weight * self.inner.distribution((*symbol.borrow()).into() + 0.5)).as_();
            non_leaky + slack + Probability::one()
        };

        let probability = right_sided_cumulative
            .wrapping_sub(&left_sided_cumulative)
            .into_nonzero()
            .expect("Invalid underlying continuous probability distribution.");

        Some((left_sided_cumulative, probability))
    }
/// Performs (one direction of) the quantization.
///
/// # Panics
///
/// Panics if it detects some invalidity in the underlying probability distribution.
/// This means that there is a bug in the implementation of [`Distribution`] for the
/// distribution `D`: the cumulative distribution function is either not monotonically
/// nondecreasing, returns NaN, or its values exceed the interval `[0.0, 1.0]` at some
/// point.
///
/// More precisely, this method panics if the quantization procedure leads to a zero
/// probability despite the added leakiness (and despite the fact that the constructor
/// checks that `min_symbol_inclusive < max_symbol_inclusive`, i.e., that there are at
/// least two symbols with nonzero probability and therefore the probability of a single
/// symbol should not be able to overflow).
///
/// See [requirements for correctness](LeakyQuantizer#requirements-for-correctness).
///
/// [`Distribution`]: probability::distribution::Distribution
Performs (one direction of) the quantization.
Performs ( one direction of ) the quantization .
fn left_cumulative_and_probability(
        &self,
        symbol: impl Borrow<Symbol>,
    ) -> Option<(Probability, Probability::NonZero)> {
        let min_symbol_inclusive = self.quantizer.min_symbol_inclusive;
        let max_symbol_inclusive = self.quantizer.max_symbol_inclusive;
        let free_weight = self.quantizer.free_weight;
        if symbol.borrow() < &min_symbol_inclusive || symbol.borrow() > &max_symbol_inclusive {
            return None;
        };
        let slack = slack(*symbol.borrow(), min_symbol_inclusive);
        // Round both cumulatives *independently* to fixed point precision.
        let left_sided_cumulative = if symbol.borrow() == &min_symbol_inclusive {
            // Corner case: only makes a difference if we're cutting off a fairly significant
            // left tail of the distribution.
            Probability::zero()
        } else {
            let non_leaky: Probability =
                (free_weight * self.inner.distribution((*symbol.borrow()).into() - 0.5)).as_();
            non_leaky + slack
        };
        let right_sided_cumulative = if symbol.borrow() == &max_symbol_inclusive {
            // Corner case: make sure that the probabilities add up to one. The generic
            // calculation in the `else` branch may lead to a lower total probability
            // because we're cutting off the right tail of the distribution and we're
            // rounding down.
            wrapping_pow2(PRECISION)
        } else {
            let non_leaky: Probability =
                (free_weight * self.inner.distribution((*symbol.borrow()).into() + 0.5)).as_();
            non_leaky + slack + Probability::one()
        };
        let probability = right_sided_cumulative
            .wrapping_sub(&left_sided_cumulative)
            .into_nonzero()
            .expect("Invalid underlying continuous probability distribution.");
        Some((left_sided_cumulative, probability))
    }
fn left_cumulative_and_probability ( & self , symbol : impl Borrow < Symbol > , ) -> Option < ( Probability , Probability :: NonZero ) > { let min_symbol_inclusive = self . quantizer . min_symbol_inclusive ; let max_symbol_inclusive = self . quantizer . max_symbol_inclusive ; let free_weight = self . quantizer . free_weight ; if symbol . borrow ( ) < & min_symbol_inclusive || symbol . borrow ( ) > & max_symbol_inclusive { return None ; } ; let slack = slack ( * symbol . borrow ( ) , min_symbol_inclusive ) ; // Round both cumulatives *independently* to fixed point precision. let left_sided_cumulative = if symbol . borrow ( ) == & min_symbol_inclusive { // Corner case: only makes a difference if we're cutting off a fairly significant // left tail of the distribution. Probability :: zero ( ) } else { let non_leaky : Probability = ( free_weight * self . inner . distribution ( ( * symbol . borrow ( ) ) . into ( ) - 0.5 ) ) . as_ ( ) ; non_leaky + slack } ; let right_sided_cumulative = if symbol . borrow ( ) == & max_symbol_inclusive { // Corner case: make sure that the probabilities add up to one. The generic // calculation in the `else` branch may lead to a lower total probability // because we're cutting off the right tail of the distribution and we're // rounding down. wrapping_pow2 ( PRECISION ) } else { let non_leaky : Probability = ( free_weight * self . inner . distribution ( ( * symbol . borrow ( ) ) . into ( ) + 0.5 ) ) . as_ ( ) ; non_leaky + slack + Probability :: one ( ) } ; let probability = right_sided_cumulative . wrapping_sub ( & left_sided_cumulative ) . into_nonzero ( ) . expect ( " " ) ; Some ( ( left_sided_cumulative , probability ) ) }
Performs (one direction of) the quantization.
Performs ( one direction of ) the quantization .
&self
symbol
impl Borrow<Symbol>
&self
symbol
impl Borrow<Symbol>
panics
Panics if it detects some invalidity in the underlying probability distribution.
This means that there is a bug in the implementation of [`Distribution`] for the
distribution `D`: the cumulative distribution function is either not monotonically
nondecreasing, returns NaN, or its values exceed the interval `[0.0, 1.0]` at some
point.

More precisely, this method panics if the quantization procedure leads to a zero
probability despite the added leakiness (and despite the fact that the constructor
checks that `min_symbol_inclusive < max_symbol_inclusive`, i.e., that there are at
least two symbols with nonzero probability and therefore the probability of a single
symbol should not be able to overflow).

See [requirements for correctness](LeakyQuantizer#requirements-for-correctness).

[`Distribution`]: probability::distribution::Distribution
Panics if it detects some invalidity in the underlying probability distribution . This means that there is a bug in the implementation of [ ` Distribution ` ] for the distribution ` D ` : the cumulative distribution function is either not monotonically nondecreasing returns NaN or its values exceed the interval ` [ 0 . 0 1 . 0 ] ` at some point . More precisely this method panics if the quantization procedure leads to a zero probability despite the added leakiness ( and despite the fact that the constructor checks that ` min_symbol_inclusive < max_symbol_inclusive ` i . e . that there are at least two symbols with nonzero probability and therefore the probability of a single symbol should not be able to overflow ) . See [ requirements for correctness ] ( LeakyQuantizer#requirements - for - correctness ) . [ ` Distribution ` ] : probability :: distribution :: Distribution