1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
use crate::backends::core::implementation::engines::CoreEngine;
use crate::backends::core::implementation::entities::{PlaintextVector32, PlaintextVector64};
use crate::backends::core::private::crypto::encoding::PlaintextList as ImplPlaintextList;
use crate::specification::engines::{PlaintextVectorCreationEngine, PlaintextVectorCreationError};
/// # Description:
/// Implementation of [`PlaintextVectorCreationEngine`] for [`CoreEngine`] that operates on
/// 32 bits integers.
impl PlaintextVectorCreationEngine<u32, PlaintextVector32> for CoreEngine {
/// # Example:
/// ```
/// use concrete_commons::parameters::PlaintextCount;
/// use concrete_core::prelude::*;
/// # use std::error::Error;
///
/// # fn main() -> Result<(), Box<dyn Error>> {
/// // Here a hard-set encoding is applied (shift by 20 bits)
/// let input = vec![3_u32 << 20; 3];
///
/// let mut engine = CoreEngine::new()?;
/// let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector(&input)?;
/// #
/// assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(3));
/// engine.destroy(plaintext_vector)?;
/// #
/// # Ok(())
/// # }
/// ```
fn create_plaintext_vector(
&mut self,
input: &[u32],
) -> Result<PlaintextVector32, PlaintextVectorCreationError<Self::EngineError>> {
if input.is_empty() {
return Err(PlaintextVectorCreationError::EmptyInput);
}
Ok(unsafe { self.create_plaintext_vector_unchecked(input) })
}
unsafe fn create_plaintext_vector_unchecked(&mut self, input: &[u32]) -> PlaintextVector32 {
PlaintextVector32(ImplPlaintextList::from_container(input.to_vec()))
}
}
/// # Description:
/// Implementation of [`PlaintextVectorCreationEngine`] for [`CoreEngine`] that operates on
/// 64 bits integers.
impl PlaintextVectorCreationEngine<u64, PlaintextVector64> for CoreEngine {
/// # Example:
/// ```
/// use concrete_commons::parameters::PlaintextCount;
/// use concrete_core::prelude::*;
/// # use std::error::Error;
///
/// # fn main() -> Result<(), Box<dyn Error>> {
/// // Here a hard-set encoding is applied (shift by 50 bits)
/// let input = vec![3_u64 << 50; 3];
///
/// let mut engine = CoreEngine::new()?;
/// let plaintext_vector: PlaintextVector64 = engine.create_plaintext_vector(&input)?;
/// #
/// assert_eq!(plaintext_vector.plaintext_count(), PlaintextCount(3));
/// engine.destroy(plaintext_vector)?;
/// #
/// # Ok(())
/// # }
/// ```
fn create_plaintext_vector(
&mut self,
input: &[u64],
) -> Result<PlaintextVector64, PlaintextVectorCreationError<Self::EngineError>> {
if input.is_empty() {
return Err(PlaintextVectorCreationError::EmptyInput);
}
Ok(unsafe { self.create_plaintext_vector_unchecked(input) })
}
unsafe fn create_plaintext_vector_unchecked(&mut self, input: &[u64]) -> PlaintextVector64 {
PlaintextVector64(ImplPlaintextList::from_container(input.to_vec()))
}
}