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));
pub fn ciphertext_iter(
&self
) -> impl Iterator<Item = LweCiphertext<&[<Self as AsRefTensor>::Element]>> where
Self: AsRefTensor,
pub fn ciphertext_iter(
&self
) -> impl Iterator<Item = LweCiphertext<&[<Self as AsRefTensor>::Element]>> where
Self: AsRefTensor,
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);
pub fn ciphertext_iter_mut(
&mut self
) -> impl Iterator<Item = LweCiphertext<&mut [<Self as AsMutTensor>::Element]>> where
Self: AsMutTensor,
pub fn ciphertext_iter_mut(
&mut self
) -> impl Iterator<Item = LweCiphertext<&mut [<Self as AsMutTensor>::Element]>> where
Self: AsMutTensor,
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);
pub fn sublist_iter(
&self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&[<Self as AsRefTensor>::Element]>> where
Self: AsRefTensor,
pub fn sublist_iter(
&self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&[<Self as AsRefTensor>::Element]>> where
Self: AsRefTensor,
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);
pub fn sublist_iter_mut(
&mut self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&mut [<Self as AsMutTensor>::Element]>> where
Self: AsMutTensor,
pub fn sublist_iter_mut(
&mut self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&mut [<Self as AsMutTensor>::Element]>> where
Self: AsMutTensor,
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);
pub fn fill_with_multisums_with_biases<Scalar, InputCont, WeightCont, BiasesCont>(
&mut self,
input_list: &LweList<InputCont>,
weights_list: &CleartextList<WeightCont>,
biases_list: &PlaintextList<BiasesCont>
) where
Self: AsMutTensor<Element = Scalar>,
LweList<InputCont>: AsRefTensor<Element = Scalar>,
CleartextList<WeightCont>: AsRefTensor<Element = Scalar>,
PlaintextList<BiasesCont>: AsRefTensor<Element = Scalar>,
for<'a> CleartextList<&'a [Scalar]>: AsRefTensor<Element = Scalar>,
Scalar: UnsignedTorus,
pub fn fill_with_multisums_with_biases<Scalar, InputCont, WeightCont, BiasesCont>(
&mut self,
input_list: &LweList<InputCont>,
weights_list: &CleartextList<WeightCont>,
biases_list: &PlaintextList<BiasesCont>
) where
Self: AsMutTensor<Element = Scalar>,
LweList<InputCont>: AsRefTensor<Element = Scalar>,
CleartextList<WeightCont>: AsRefTensor<Element = Scalar>,
PlaintextList<BiasesCont>: AsRefTensor<Element = Scalar>,
for<'a> CleartextList<&'a [Scalar]>: AsRefTensor<Element = Scalar>,
Scalar: UnsignedTorus,
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
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
type Element = <Cont as AsRefSlice>::Element
type Element = <Cont as AsRefSlice>::Element
The element type of the collection container.
type Container = Cont
type Container = Cont
The type of the collection container.
Consumes self
and returns an owned tensor.
Auto Trait Implementations
impl<Cont> RefUnwindSafe for LweList<Cont> where
Cont: RefUnwindSafe,
impl<Cont> UnwindSafe for LweList<Cont> where
Cont: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more