pub fn stochastic_rounding<T: FloatExt, S: Data<Elem = T>, D: Dimension>(
data: ArrayBase<S, D>,
precision: NonNegative<T>,
seed: u64,
) -> Array<T, D>where
Open01: Distribution<T>,
Expand description
Stochastically rounds the data
to the nearest multiple of the precision
.
The nearest representable multiple is chosen such that the absolute difference between the original value and the rounded value do not exceed the precision. Therefore, the rounded value may have a non-zero remainder.
This function first hashes the input array data and shape to then seed
a
pseudo-random number generator that is used to sample the stochasticity for
rounding. Therefore, passing in the same input with the same seed
will
produce the same stochasticity and thus the same encoded output.