Struct concrete::plaintext::Plaintext [−][src]
pub struct Plaintext {
pub encoders: Vec<Encoder>,
pub plaintexts: Vec<Torus>,
pub nb_plaintexts: usize,
}
Expand description
Structure describing a list of plaintext values with their respective Encoder
Attributes
encoder
- the list of the encoders (one for each plaintext)plaintexts
- the list of plaintextsnb_plaintexts
- the size of both lists
Fields
encoders: Vec<Encoder>
plaintexts: Vec<Torus>
nb_plaintexts: usize
Implementations
Instantiate a new empty Plaintext (set to zero) of a certain size
Argument
nb_plaintexts
- the number of plaintext that would be in the Plaintext instance
Output
- a new instantiation of an empty Plaintext (set to zero) of a certain size
Example
use concrete::Plaintext;
let nb_ct: usize = 100;
let plaintexts = Plaintext::zero(nb_ct);
Instantiate a new Plaintext filled with plaintexts
Argument
messages
- a list of messages as u64encoder
- an encoder
Output
- a new instance of Plaintext containing the plaintext of each message with respect to encoder
Example
use concrete::{Encoder, Plaintext};
// create an Encoder instance where messages are in the interval [-5, 5[
let encoder = Encoder::new(-5., 5., 8, 0).unwrap();
// create a list of messages in our interval
let messages: Vec<f64> = vec![-3.2, 4.3, 0.12, -1.1, 2.78];
// create a new Plaintext instance filled with the plaintexts we want
let pt = Plaintext::encode(&messages, &encoder).unwrap();
// print the Plaintext
println!("ec = {}", pt);
Decode one single plaintext (from the list of plaintexts in this Plaintext instance) according to its own encoder
Arguments
nth
- the index of the plaintext to decode
Output
- the decoded value as a f64
Example
use concrete::{Encoder, Plaintext};
// create an Encoder instance where messages are in the interval [-5, 5[
let encoder = Encoder::new(-5., 5., 8, 0).unwrap();
// create a list of messages in our interval
let messages: Vec<f64> = vec![-3.2, 4.3, 0.12, -1.1, 2.78];
// create a new Plaintext instance filled with the plaintexts we want
let pt = Plaintext::encode(&messages, &encoder).unwrap();
let n: usize = 2;
let m = pt.decode_nth(n).unwrap();
Encode several messages according to the list of Encoders in this instance
Arguments
messages
- a list of messages as f64
Example
use concrete::{Encoder, Plaintext};
// create a list of 5 Encoder instances where messages are in the interval [-5, 5[
let encoders = vec![Encoder::new(-5., 5., 8, 0).unwrap(); 5];
// create a list of messages in our interval
let messages: Vec<f64> = vec![-3.2, 4.3, 0.12, -1.1, 2.78];
// create a new Plaintext instance that can contain 5 plaintexts
let mut ec = Plaintext::zero(5);
// set the encoders
ec.set_encoders(&encoders);
// encode our messages
ec.encode_inplace(&messages);
Decode every plaintexts in this Plaintext instance according to its list of Encoders
Example
use concrete::{Encoder, Plaintext};
// create an Encoder instance where messages are in the interval [-5, 5[
let encoder = Encoder::new(-5., 5., 8, 0).unwrap();
// create a list of messages in our interval
let messages: Vec<f64> = vec![-3.2, 4.3, 0.12, -1.1, 2.78];
// create a new Plaintext instance filled with the plaintexts we want
let mut ec = Plaintext::encode(&messages, &encoder).unwrap();
let new_msgs: Vec<f64> = ec.decode().unwrap();
Set the encoder list of this instance from an input list of encoders
Argument
encoders
- a list of Encoder elements
Example
use concrete::{Encoder, Plaintext};
let nb_ct = 100;
let mut pt = Plaintext::zero(nb_ct);
let encoders = vec![Encoder::zero(); nb_ct];
// setting the encoders
pt.set_encoders(&encoders);
Set the nth encoder of the encoder list of this instance from an input encoder
Argument
encoder
- an Encoder
Example
use concrete::{Encoder, Plaintext};
let nb_ct = 100;
let mut pt = Plaintext::zero(nb_ct);
let encoder_1 = Encoder::zero();
let encoder_2 = Encoder::zero();
let n: usize = 2;
// setting the encoders
pt.set_encoders_from_one(&encoder_1);
pt.set_nth_encoder(n, &encoder_2);
Trait Implementations
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>,
Deserialize this value from the given Serde deserializer. Read more
Print needed pieces of information about this instance
Auto Trait Implementations
impl RefUnwindSafe for Plaintext
impl UnwindSafe for Plaintext
Blanket Implementations
Mutably borrows from an owned value. Read more