Struct concrete_core::crypto::lwe::LweList [−][src]
A list of ciphertext encoded with the LWE scheme.
Implementations
impl<Scalar> LweList<Vec<Scalar>> where
Scalar: Copy,
[src]
Scalar: Copy,
pub fn allocate(
value: Scalar,
lwe_size: LweSize,
lwe_count: CiphertextCount
) -> Self
[src]
value: Scalar,
lwe_size: LweSize,
lwe_count: CiphertextCount
) -> Self
Allocates a list of lwe ciphertext whose all masks and bodies have the value value
.
Example
use concrete_core::crypto::{*, lwe::LweList}; let list = LweList::allocate(0 as u8, LweSize(10), CiphertextCount(20)); assert_eq!(list.count(), CiphertextCount(20)); assert_eq!(list.lwe_size(), LweSize(10));
impl<Cont> LweList<Cont>
[src]
pub fn from_container(cont: Cont, lwe_size: LweSize) -> Self where
Cont: AsRefSlice,
[src]
Cont: AsRefSlice,
Creates a list from a container and a lwe size.
Example:
use concrete_core::crypto::{*, lwe::LweList}; 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));
pub fn count(&self) -> CiphertextCount where
Self: AsRefTensor,
[src]
Self: AsRefTensor,
Returns the number of ciphertexts in the list.
Example
use concrete_core::crypto::{*, lwe::LweList}; let list = LweList::from_container(vec![0 as u8; 200], LweSize(10)); assert_eq!(list.count(), CiphertextCount(20));
pub fn lwe_size(&self) -> LweSize where
Self: AsRefTensor,
[src]
Self: AsRefTensor,
Returns the size of the ciphertexts in the list.
Example
use concrete_core::crypto::{*, lwe::LweList}; let list = LweList::from_container(vec![0 as u8; 200], LweSize(10)); assert_eq!(list.lwe_size(), LweSize(10));
pub fn mask_size(&self) -> LweDimension where
Self: AsRefTensor,
[src]
Self: AsRefTensor,
Returns the number of masks of the ciphertexts in the list.
Example
use concrete_core::crypto::{*, lwe::LweList}; 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::Element]>> where
Self: AsRefTensor,
[src]
&self
) -> impl Iterator<Item = LweCiphertext<&[Self::Element]>> where
Self: AsRefTensor,
Returns an iterator over ciphertexts borrowed from the list.
Example
use concrete_core::crypto::{*, lwe::*}; 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::Element]>> where
Self: AsMutTensor,
[src]
&mut self
) -> impl Iterator<Item = LweCiphertext<&mut [Self::Element]>> where
Self: AsMutTensor,
Returns an iterator over ciphers mutably borrowed from the list.
Example
use concrete_core::crypto::{*, lwe::*}; 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::Element]>> where
Self: AsRefTensor,
[src]
&self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&[Self::Element]>> where
Self: AsRefTensor,
Returns an iterator over sub lists borrowed from the list.
Example
use concrete_core::crypto::{*, lwe::*}; 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::Element]>> where
Self: AsMutTensor,
[src]
&mut self,
sub_len: CiphertextCount
) -> impl Iterator<Item = LweList<&mut [Self::Element]>> where
Self: AsMutTensor,
Returns an iterator over sub lists borrowed from the list.
Example
use concrete_core::crypto::{*, lwe::*}; 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>,
CleartextList<&'a [Scalar]>: AsRefTensor<Element = Scalar>,
Scalar: UnsignedTorus,
[src]
&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>,
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_core::crypto::{*, lwe::*, secret::*}; use concrete_core::crypto::encoding::*; use concrete_core::math::tensor::AsRefTensor; use concrete_core::math::dispersion::LogStandardDev; let secret_key = LweSecretKey::generate(LweDimension(4)); 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); 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
impl<Element> AsMutTensor for LweList<Vec<Element>>
[src]
type Element = Element
The element type.
type Container = Vec<Element>
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsMutTensor for LweList<[Element; 1]>
[src]
type Element = Element
The element type.
type Container = [Element; 1]
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsMutTensor for LweList<AlignedVec<Element>>
[src]
type Element = Element
The element type.
type Container = AlignedVec<Element>
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<'a, Element> AsMutTensor for LweList<&'a mut [Element]>
[src]
type Element = Element
The element type.
type Container = &'a mut [Element]
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweList<Vec<Element>>
[src]
type Element = Element
The element type.
type Container = Vec<Element>
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweList<AlignedVec<Element>>
[src]
type Element = Element
The element type.
type Container = AlignedVec<Element>
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweList<[Element; 1]>
[src]
type Element = Element
The element type.
type Container = [Element; 1]
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<'a, Element> AsRefTensor for LweList<&'a [Element]>
[src]
type Element = Element
The element type.
type Container = &'a [Element]
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<'a, Element> AsRefTensor for LweList<&'a mut [Element]>
[src]
type Element = Element
The element type.
type Container = &'a mut [Element]
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Cont: Clone> Clone for LweList<Cont>
[src]
impl<Cont: Debug> Debug for LweList<Cont>
[src]
impl<'de, Cont> Deserialize<'de> for LweList<Cont> where
Cont: Deserialize<'de>,
[src]
Cont: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<Element> IntoTensor for LweList<Vec<Element>>
[src]
type Element = Element
The element type of the collection container.
type Container = Vec<Element>
The type of the collection container.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<Element> IntoTensor for LweList<AlignedVec<Element>>
[src]
type Element = Element
The element type of the collection container.
type Container = AlignedVec<Element>
The type of the collection container.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<Element> IntoTensor for LweList<[Element; 1]>
[src]
type Element = Element
The element type of the collection container.
type Container = [Element; 1]
The type of the collection container.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<'a, Element> IntoTensor for LweList<&'a [Element]>
[src]
type Element = Element
The element type of the collection container.
type Container = &'a [Element]
The type of the collection container.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<'a, Element> IntoTensor for LweList<&'a mut [Element]>
[src]
type Element = Element
The element type of the collection container.
type Container = &'a mut [Element]
The type of the collection container.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<Cont: PartialEq> PartialEq<LweList<Cont>> for LweList<Cont>
[src]
impl<Cont> Serialize for LweList<Cont> where
Cont: Serialize,
[src]
Cont: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<Cont> StructuralPartialEq for LweList<Cont>
[src]
Auto Trait Implementations
impl<Cont> RefUnwindSafe for LweList<Cont> where
Cont: RefUnwindSafe,
Cont: RefUnwindSafe,
impl<Cont> Send for LweList<Cont> where
Cont: Send,
Cont: Send,
impl<Cont> Sync for LweList<Cont> where
Cont: Sync,
Cont: Sync,
impl<Cont> Unpin for LweList<Cont> where
Cont: Unpin,
Cont: Unpin,
impl<Cont> UnwindSafe for LweList<Cont> where
Cont: UnwindSafe,
Cont: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Input, Output> CastInto<Output> for Input where
Output: CastFrom<Input>,
[src]
Output: CastFrom<Input>,
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,