Struct concrete::encoder::Encoder[][src]

pub struct Encoder {
    pub o: f64,
    pub delta: f64,
    pub nb_bit_precision: usize,
    pub nb_bit_padding: usize,
    pub round: bool,
}
Expand description

Structure describing one particular Encoding

Attributes

  • o - the offset of the encoding
  • delta - the delta of the encoding
  • nb_bit_precision - the minimum number of bits to represent a plaintext
  • nb_bit_padding - the number of bits set to zero in the MSB

Fields

o: f64delta: f64nb_bit_precision: usizenb_bit_padding: usizeround: bool

Implementations

Instantiate a new Encoder with the provided interval as [min,max[ This encoder is meant to be use in an approximate context.

Arguments
  • min- the minimum real value of the interval
  • max- the maximum real value of the interval
  • nb_bit_precision - number of bits to represent a plaintext
  • nb_bit_padding - number of bits for left padding with zeros
Output
  • a new instantiation of an Encoder
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// instantiation
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

Instantiate a new Encoder with the provided interval as [min,max[ This encoder is meant to be use in an exact computation context. It will round at encode and at decode.

Arguments
  • min- the minimum real value of the interval
  • max- the maximum real value of the interval
  • nb_bit_precision - number of bits to represent a plaintext
  • nb_bit_padding - number of bits for left padding with zeros
Output
  • a new instantiation of an Encoder
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// instantiation
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

After an homomorphic operation, update an encoder using the variance

Arguments
  • variance - variance
Output
  • return the number of bits of precision affected by the noise
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// instantiation
let mut encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();
let variance: f64 = f64::powi(2., -30);
let nb_bit_overlap: usize = encoder.update_precision_from_variance(variance).unwrap();

Instantiate a new Encoder with the provided interval as [center-radius,center+radius[

Arguments
  • center - the center value of the interval
  • radius - the distance between the center and the endpoints of the interval
  • nb_bit_precision - number of bits to represent a plaintext
  • nb_bit_padding - number of bits for left padding with zeros
Output
  • a new instantiation of an Encoder
Example
use concrete::Encoder;

// parameters
let center: f64 = 0.;
let radius: f64 = 5.4;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// instantiation
let encoder = Encoder::new_centered(center, radius, nb_bit_precision, nb_bit_padding).unwrap();

Encode one single message according to this Encoder parameters

Arguments
  • message - a message as a f64
Output
  • a new instantiation of an Plaintext containing only one encoded value (the one we just computed with this function)
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;
let message = 0.6;

// creation of the encoder
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

// encoding
let m = encoder.encode_single(message).unwrap();

Decode one single plaintext according to this Encoder parameters

Arguments
  • ec - an plaintext
Output
  • the decoded value as a f64
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;
let message = 0.6;

// creation of the encoder
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

// encoding
let m = encoder.encode_single(message).unwrap();

// decoding
let new_message = encoder.decode_single(m.plaintexts[0]).unwrap();

Instantiate a new empty Encoder (set to zero)

Output
  • a new instantiation of an empty Encoder (set to zero)
Example
use concrete::Encoder;
let encoder = Encoder::zero();

Encode several message according to this (one) Encoder parameters The output Plaintext will have plaintexts all computed with the same Encoder parameters

Arguments
  • messages- a list of messages as a f64
Example
use concrete::Encoder;
// parameters
let (min, max): (f64, f64) = (0.2, 0.4);
let (precision, padding): (usize, usize) = (8, 4);
let messages: Vec<f64> = vec![0.3, 0.34];
let encoder = Encoder::new(min, max, precision, padding).unwrap();
let plaintexts = encoder.encode(&messages).unwrap();

Computes the smallest real number that this encoding can handle

Copy the content of the input encoder inside the self encoder

Argument
  • encoder- the encoder to be copied
Example
use concrete::Encoder;
// parameters
let (min, max): (f64, f64) = (0.2, 0.4);
let (precision, padding): (usize, usize) = (8, 4);

let encoder_1 = Encoder::new(min, max, precision, padding).unwrap();
let mut encoder_2 = Encoder::zero();
encoder_2.copy(&encoder_1);

Crete a new encoder as if one computes a square function divided by 4

Argument
  • nb_bit_padding- number of bits for left padding with zeros
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// instantiation
let encoder_in = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();
let encoder_out = encoder_in
    .new_square_divided_by_four(nb_bit_padding)
    .unwrap();

Wrap the core_api encode function with the padding

Argument
  • m - the message to encode
Example
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// message
let m = 0.3;
// instantiation
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

let plaintext = encoder.encode_core(m).unwrap();

Wrap the core_api encode function with the padding and allows to encode a message that is outside of the interval of the encoder It is used for correction after homomorphic computation

Argument
  • m - the message to encode
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// message
let m = 1.2;
// instantiation
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

let plaintext = encoder.encode_outside_interval_operators(m).unwrap();

Wrap the core_api decode function with the padding and the rounding

Argument
  • pt - the noisy plaintext
use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// message
let m = 0.3;
// instantiation
let encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

let plaintext = encoder.encode_core(m).unwrap();
let new_message = encoder.decode_core(plaintext).unwrap();

Check if the Encoder looks valid or not

Output

return a boolean, true means that it is valid

Modify the encoding to be use after an homomorphic opposite

use concrete::Encoder;

// parameters
let min: f64 = 0.2;
let max: f64 = 0.8;
let nb_bit_precision = 8;
let nb_bit_padding = 4;

// message
let m = 0.3;
// instantiation
let mut encoder = Encoder::new(min, max, nb_bit_precision, nb_bit_padding).unwrap();

encoder.opposite_inplace();

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Print needed pieces of information about an Encoder

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.