Trait concrete_core::crypto::encoding::Encoder [−][src]
pub trait Encoder<Enc: Numeric> { type Raw: Numeric; fn encode(&self, raw: Cleartext<Self::Raw>) -> Plaintext<Enc>; fn decode(&self, encoded: Plaintext<Enc>) -> Cleartext<Self::Raw>; fn encode_list<RawCont, EncCont>(
&self,
encoded: &mut PlaintextList<EncCont>,
raw: &CleartextList<RawCont>
)
where
CleartextList<RawCont>: AsRefTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsMutTensor<Element = Enc>; fn decode_list<RawCont, EncCont>(
&self,
raw: &mut CleartextList<RawCont>,
encoded: &PlaintextList<EncCont>
)
where
CleartextList<RawCont>: AsMutTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsRefTensor<Element = Enc>; }
Expand description
A trait for types that encode cleartext to plaintext.
Examples use the [`RealEncoder’] type.
Associated Types
Required methods
Encodes a single cleartext.
Example
use concrete_core::crypto::encoding::*; let encoder = RealEncoder{ offset: 1. as f32, delta: 10.}; let cleartext = Cleartext(7. as f32); let encoded: Plaintext<u32> = encoder.encode(cleartext.clone()); let decoded = encoder.decode(encoded); assert!((cleartext.0 - decoded.0).abs() < 0.1);
Decodes a single encoded value.
See Encoder::encode
for an example.
fn encode_list<RawCont, EncCont>(
&self,
encoded: &mut PlaintextList<EncCont>,
raw: &CleartextList<RawCont>
) where
CleartextList<RawCont>: AsRefTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsMutTensor<Element = Enc>,
fn encode_list<RawCont, EncCont>(
&self,
encoded: &mut PlaintextList<EncCont>,
raw: &CleartextList<RawCont>
) where
CleartextList<RawCont>: AsRefTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsMutTensor<Element = Enc>,
Encodes a list of cleartexts to a list of plaintexts.
Example
use concrete_core::crypto::encoding::*; let encoder = RealEncoder{ offset: 1. as f32, delta: 10.}; let clear_values = CleartextList::from_container(vec![7. as f32;100]); let mut plain_values = PlaintextList::from_container(vec![0 as u32; 100]); encoder.encode_list(&mut plain_values, &clear_values); let mut decoded_values = CleartextList::from_container(vec![0. as f32; 100]); encoder.decode_list(&mut decoded_values, &plain_values); for (clear, decoded) in clear_values.cleartext_iter().zip(decoded_values.cleartext_iter()) { assert!((clear.0 - decoded.0).abs() < 0.1); }
fn decode_list<RawCont, EncCont>(
&self,
raw: &mut CleartextList<RawCont>,
encoded: &PlaintextList<EncCont>
) where
CleartextList<RawCont>: AsMutTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsRefTensor<Element = Enc>,
fn decode_list<RawCont, EncCont>(
&self,
raw: &mut CleartextList<RawCont>,
encoded: &PlaintextList<EncCont>
) where
CleartextList<RawCont>: AsMutTensor<Element = Self::Raw>,
PlaintextList<EncCont>: AsRefTensor<Element = Enc>,
Decodes a list of plaintexts into a list of cleartexts.
See Encoder::encode_list
for an example.
Implementors
impl<RawScalar, EncScalar> Encoder<EncScalar> for RealEncoder<RawScalar> where
EncScalar: UnsignedTorus + FromTorus<RawScalar> + IntoTorus<RawScalar>,
RawScalar: FloatingPoint,