Skip to content

Commit

Permalink
chore(hlapi): add tests for fhe_bool
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Feb 16, 2024
1 parent 3c69e8e commit 42117a1
Show file tree
Hide file tree
Showing 4 changed files with 681 additions and 136 deletions.
11 changes: 5 additions & 6 deletions tfhe/src/high_level_api/booleans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,10 @@ where
fn bitand(self, rhs: B) -> Self::Output {
let ciphertext = global_state::with_internal_keys(|key| match key {
InternalServerKey::Cpu(key) => {
let inner_ct = key.pbs_key().key.bitand(
self.ciphertext.on_cpu().as_ref(),
rhs.borrow().ciphertext.on_cpu().as_ref(),
);
InnerBoolean::Cpu(BooleanBlock::new_unchecked(inner_ct))
let inner_ct = key
.pbs_key()
.boolean_bitand(&self.ciphertext.on_cpu(), &rhs.borrow().ciphertext.on_cpu());
InnerBoolean::Cpu(inner_ct)
}
#[cfg(feature = "gpu")]
InternalServerKey::Cuda(cuda_key) => with_thread_local_cuda_stream(|stream| {
Expand Down Expand Up @@ -1245,7 +1244,7 @@ impl std::ops::Not for &FheBool {
}
#[cfg(feature = "gpu")]
InternalServerKey::Cuda(cuda_key) => with_thread_local_cuda_stream(|stream| {
let mut inner = cuda_key
let inner = cuda_key
.key
.scalar_bitxor(&self.ciphertext.on_gpu(), 1, stream);
InnerBoolean::Cuda(inner)
Expand Down
7 changes: 5 additions & 2 deletions tfhe/src/high_level_api/booleans/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::integer::parameters::{
};
use crate::integer::BooleanBlock;
use crate::named::Named;
use crate::shortint::ciphertext::Degree;
use crate::CompactPublicKey;

/// Compact [FheBool]
Expand Down Expand Up @@ -45,7 +46,8 @@ impl CompactFheBool {
pub fn expand(&self) -> FheBool {
let ct: crate::integer::RadixCiphertext = self.list.expand_one();
assert_eq!(ct.blocks.len(), 1);
let block = BooleanBlock::new_unchecked(ct.blocks.into_iter().next().unwrap());
let mut block = BooleanBlock::new_unchecked(ct.blocks.into_iter().next().unwrap());
block.0.degree = Degree::new(1);
FheBool::new(block)
}
}
Expand Down Expand Up @@ -127,7 +129,8 @@ impl CompactFheBoolList {
.into_iter()
.map(|ct: crate::integer::RadixCiphertext| {
assert_eq!(ct.blocks.len(), 1);
let block = BooleanBlock::new_unchecked(ct.blocks.into_iter().next().unwrap());
let mut block = BooleanBlock::new_unchecked(ct.blocks.into_iter().next().unwrap());
block.0.degree = Degree::new(1);
FheBool::new(block)
})
.collect::<Vec<_>>()
Expand Down
4 changes: 3 additions & 1 deletion tfhe/src/high_level_api/booleans/compressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::conformance::ParameterSetConformant;
use crate::integer::BooleanBlock;
use crate::named::Named;
use crate::prelude::FheTryEncrypt;
use crate::shortint::ciphertext::Degree;
use crate::shortint::parameters::CiphertextConformanceParams;
use crate::shortint::CompressedCiphertext;
use crate::{ClientKey, FheBool};
Expand Down Expand Up @@ -53,7 +54,8 @@ impl FheTryEncrypt<bool, ClientKey> for CompressedFheBool {

/// Creates a compressed encryption of a boolean value
fn try_encrypt(value: bool, key: &ClientKey) -> Result<Self, Self::Error> {
let ciphertext = key.key.key.key.encrypt_compressed(u64::from(value));
let mut ciphertext = key.key.key.key.encrypt_compressed(u64::from(value));
ciphertext.degree = Degree::new(1);
Ok(Self::new(ciphertext))
}
}
Expand Down
Loading

0 comments on commit 42117a1

Please sign in to comment.