pub struct StochasticRoundingCodec {
pub precision: NonNegative<f64>,
pub seed: u64,
pub version: StaticCodecVersion<1, 0, 0>,
}
Expand description
Codec that stochastically rounds the data to the nearest multiple of
precision
on encoding and passes through the input unchanged during
decoding.
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 codec 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.
Fields§
§precision: NonNegative<f64>
The precision of the rounding operation
seed: u64
Seed for the random generator
version: StaticCodecVersion<1, 0, 0>
The codec’s encoding format version. Do not provide this parameter explicitly.
Trait Implementations§
Source§impl Clone for StochasticRoundingCodec
impl Clone for StochasticRoundingCodec
Source§fn clone(&self) -> StochasticRoundingCodec
fn clone(&self) -> StochasticRoundingCodec
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Codec for StochasticRoundingCodec
impl Codec for StochasticRoundingCodec
Source§fn encode(&self, data: AnyCowArray<'_>) -> Result<AnyArray, Self::Error>
fn encode(&self, data: AnyCowArray<'_>) -> Result<AnyArray, Self::Error>
data
and returns the result. Read moreSource§fn decode(&self, encoded: AnyCowArray<'_>) -> Result<AnyArray, Self::Error>
fn decode(&self, encoded: AnyCowArray<'_>) -> Result<AnyArray, Self::Error>
encoded
data and returns the result. Read moreSource§fn decode_into(
&self,
encoded: AnyArrayView<'_>,
decoded: AnyArrayViewMut<'_>,
) -> Result<(), Self::Error>
fn decode_into( &self, encoded: AnyArrayView<'_>, decoded: AnyArrayViewMut<'_>, ) -> Result<(), Self::Error>
Source§impl<'de> Deserialize<'de> for StochasticRoundingCodec
impl<'de> Deserialize<'de> for StochasticRoundingCodec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for StochasticRoundingCodec
impl JsonSchema for StochasticRoundingCodec
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref
keyword. Read moreSource§impl Serialize for StochasticRoundingCodec
impl Serialize for StochasticRoundingCodec
Source§impl StaticCodec for StochasticRoundingCodec
impl StaticCodec for StochasticRoundingCodec
Source§type Config<'de> = StochasticRoundingCodec
type Config<'de> = StochasticRoundingCodec
Source§fn from_config(config: Self::Config<'_>) -> Self
fn from_config(config: Self::Config<'_>) -> Self
config
uration.Source§fn get_config(&self) -> StaticCodecConfig<'_, Self>
fn get_config(&self) -> StaticCodecConfig<'_, Self>
Auto Trait Implementations§
impl Freeze for StochasticRoundingCodec
impl RefUnwindSafe for StochasticRoundingCodec
impl Send for StochasticRoundingCodec
impl Sync for StochasticRoundingCodec
impl Unpin for StochasticRoundingCodec
impl UnwindSafe for StochasticRoundingCodec
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,
Source§impl<T> DynCodec for Twhere
T: StaticCodec,
impl<T> DynCodec for Twhere
T: StaticCodec,
Source§type Type = StaticCodecType<T>
type Type = StaticCodecType<T>
Source§fn get_config<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn get_config<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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