Struct concrete_core::crypto::lwe::LweList[][src]

pub struct LweList<Cont> { /* fields omitted */ }
Expand description

A list of ciphertext encoded with the LWE scheme.

Implementations

Allocates a list of lwe ciphertext whose all masks and bodies have the value value.

Example

use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::crypto::lwe::LweList;
use concrete_core::crypto::*;
let list = LweList::allocate(0 as u8, LweSize(10), CiphertextCount(20));
assert_eq!(list.count(), CiphertextCount(20));
assert_eq!(list.lwe_size(), LweSize(10));

Creates a list from a container and a lwe size.

Example:

use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::crypto::lwe::LweList;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
assert_eq!(list.count(), CiphertextCount(20));
assert_eq!(list.lwe_size(), LweSize(10));

Returns the number of ciphertexts in the list.

Example

use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::crypto::lwe::LweList;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
assert_eq!(list.count(), CiphertextCount(20));

Returns the size of the ciphertexts in the list.

Example

use concrete_commons::parameters::LweSize;
use concrete_core::crypto::lwe::LweList;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
assert_eq!(list.lwe_size(), LweSize(10));

Returns the number of masks of the ciphertexts in the list.

Example

use concrete_commons::parameters::{LweDimension, LweSize};
use concrete_core::crypto::lwe::LweList;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
assert_eq!(list.mask_size(), LweDimension(9));

Returns an iterator over ciphertexts borrowed from the list.

Example

use concrete_commons::parameters::LweSize;
use concrete_core::crypto::lwe::*;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
for ciphertext in list.ciphertext_iter() {
    let (body, masks) = ciphertext.get_body_and_mask();
    assert_eq!(body, &LweBody(0));
    assert_eq!(
        masks,
        LweMask::from_container(&[0 as u8, 0, 0, 0, 0, 0, 0, 0, 0][..])
    );
}
assert_eq!(list.ciphertext_iter().count(), 20);

Returns an iterator over ciphers mutably borrowed from the list.

Example

use concrete_commons::parameters::LweSize;
use concrete_core::crypto::lwe::*;
use concrete_core::crypto::*;
let mut list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
for mut ciphertext in list.ciphertext_iter_mut() {
    let body = ciphertext.get_mut_body();
    *body = LweBody(2);
}
for ciphertext in list.ciphertext_iter() {
    let body = ciphertext.get_body();
    assert_eq!(body, &LweBody(2));
}
assert_eq!(list.ciphertext_iter_mut().count(), 20);

Returns an iterator over sub lists borrowed from the list.

Example

use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::crypto::lwe::*;
use concrete_core::crypto::*;
let list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
for sublist in list.sublist_iter(CiphertextCount(5)) {
    assert_eq!(sublist.count(), CiphertextCount(5));
    for ciphertext in sublist.ciphertext_iter() {
        let (body, masks) = ciphertext.get_body_and_mask();
        assert_eq!(body, &LweBody(0));
        assert_eq!(
            masks,
            LweMask::from_container(&[0 as u8, 0, 0, 0, 0, 0, 0, 0, 0][..])
        );
    }
}
assert_eq!(list.sublist_iter(CiphertextCount(5)).count(), 4);

Returns an iterator over sub lists borrowed from the list.

Example

use concrete_commons::parameters::{CiphertextCount, LweSize};
use concrete_core::crypto::lwe::*;
use concrete_core::crypto::*;
let mut list = LweList::from_container(vec![0 as u8; 200], LweSize(10));
for mut sublist in list.sublist_iter_mut(CiphertextCount(5)) {
    assert_eq!(sublist.count(), CiphertextCount(5));
    for mut ciphertext in sublist.ciphertext_iter_mut() {
        let (body, mut masks) = ciphertext.get_mut_body_and_mask();
        *body = LweBody(9);
        for mut mask in masks.mask_element_iter_mut() {
            *mask = 8;
        }
    }
}
for ciphertext in list.ciphertext_iter() {
    let (body, masks) = ciphertext.get_body_and_mask();
    assert_eq!(body, &LweBody(9));
    assert_eq!(
        masks,
        LweMask::from_container(&[8 as u8, 8, 8, 8, 8, 8, 8, 8, 8][..])
    );
}
assert_eq!(list.sublist_iter_mut(CiphertextCount(5)).count(), 4);

Fills each ciphertexts of the list with the result of the multisum of a subpart of the input_list ciphers, with a subset of the weights_list values, and one value of biases_list.

Said differently, this function fills self with: $$ bias[i] + \sum_j input_list[i][j] * weights[i][j] $$

Example

use concrete_commons::dispersion::LogStandardDev;
use concrete_commons::parameters::{LweDimension, LweSize};
use concrete_core::crypto::encoding::*;
use concrete_core::crypto::lwe::*;
use concrete_core::crypto::secret::generators::{
    EncryptionRandomGenerator, SecretRandomGenerator,
};
use concrete_core::crypto::secret::*;
use concrete_core::crypto::*;
use concrete_core::math::tensor::AsRefTensor;

let mut secret_generator = SecretRandomGenerator::new(None);
let mut encryption_generator = EncryptionRandomGenerator::new(None);

let secret_key = LweSecretKey::generate_binary(LweDimension(4), &mut secret_generator);
let parameters = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder {
    offset: 0. as f32,
    delta: 200.,
};

let clear_values = CleartextList::from_container(vec![1f32, 2., 3., 4., 5., 6.]);
let mut plain_values = PlaintextList::from_container(vec![0u32; 6]);
encoder.encode_list(&mut plain_values, &clear_values);
let mut cipher_values = LweList::from_container(vec![0. as u32; 5 * 6], LweSize(5));
secret_key.encrypt_lwe_list(
    &mut cipher_values,
    &plain_values,
    parameters,
    &mut encryption_generator,
);

let mut output = LweList::from_container(vec![0u32; 5 * 2], LweSize(5));
let weights = CleartextList::from_container(vec![7, 8, 9, 10, 11, 12]);
let biases = PlaintextList::from_container(vec![
    encoder.encode(Cleartext(13.)).0,
    encoder.encode(Cleartext(14.)).0,
]);

output.fill_with_multisums_with_biases(&cipher_values, &weights, &biases);

let mut decrypted = PlaintextList::from_container(vec![0u32; 2]);
secret_key.decrypt_lwe_list(&mut decrypted, &output);
let mut decoded = CleartextList::from_container(vec![0f32; 2]);
encoder.decode_list(&mut decoded, &decrypted);
assert!((decoded.as_tensor().first() - 63.).abs() < 0.3);
assert!((decoded.as_tensor().last() - 181.).abs() < 0.3);

Trait Implementations

The element type.

The container used by the tensor.

Returns a mutable reference to the enclosed tensor.

The element type.

The container used by the tensor.

Returns a reference to the enclosed tensor.

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

The element type of the collection container.

The type of the collection container.

Consumes self and returns an owned tensor.

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

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.