mirror of
https://github.com/arnaucube/phantom-zone.git
synced 2026-01-18 20:01:34 +01:00
move fhe uint8 api tests
This commit is contained in:
@@ -1,12 +1,3 @@
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
bool::{parameters::CiphertextModulus, ClientKey, PublicKey},
|
||||
random::{DefaultSecureRng, NewWithSeed, RandomFillUniformInModulus},
|
||||
utils::{TryConvertFrom1, WithLocal},
|
||||
Decryptor, Encryptor, Matrix, MatrixEntity, MatrixMut, MultiPartyDecryptor, Row, RowMut,
|
||||
};
|
||||
|
||||
mod enc_dec;
|
||||
mod ops;
|
||||
mod types;
|
||||
@@ -14,6 +5,8 @@ mod types;
|
||||
pub type FheUint8 = enc_dec::FheUint8<Vec<u64>>;
|
||||
pub type FheBool = Vec<u64>;
|
||||
|
||||
use crate::bool::{evaluator::BooleanGates, BoolEvaluator, RuntimeServerKey};
|
||||
|
||||
mod frontend {
|
||||
use super::ops::{
|
||||
arbitrary_bit_adder, arbitrary_bit_division_for_quotient_and_rem, arbitrary_bit_subtractor,
|
||||
@@ -24,7 +17,6 @@ mod frontend {
|
||||
use super::*;
|
||||
|
||||
mod arithetic {
|
||||
use crate::bool::{evaluator::BooleanGates, BoolEvaluator, RuntimeServerKey};
|
||||
|
||||
use super::*;
|
||||
use std::ops::{Add, AddAssign, Div, Mul, Rem, Sub};
|
||||
@@ -149,11 +141,8 @@ mod frontend {
|
||||
}
|
||||
|
||||
mod booleans {
|
||||
use crate::{
|
||||
bool::{evaluator::BooleanGates, BoolEvaluator, RuntimeServerKey},
|
||||
shortint::ops::{
|
||||
arbitrary_bit_comparator, arbitrary_bit_equality, arbitrary_signed_bit_comparator,
|
||||
},
|
||||
use crate::shortint::ops::{
|
||||
arbitrary_bit_comparator, arbitrary_bit_equality, arbitrary_signed_bit_comparator,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
@@ -223,155 +212,9 @@ mod tests {
|
||||
use num_traits::Euclid;
|
||||
|
||||
use crate::{
|
||||
bool::set_parameter_set, shortint::enc_dec::FheUint8, Decryptor, Encryptor,
|
||||
MultiPartyDecryptor,
|
||||
bool::set_parameter_set, shortint::enc_dec::FheUint8, utils::WithLocal, Decryptor,
|
||||
Encryptor, MultiPartyDecryptor,
|
||||
};
|
||||
|
||||
// #[test]
|
||||
// fn all_uint8_apis() {
|
||||
// set_parameter_set(crate::ParameterSelector::MultiPartyLessThanOrEqualTo16);
|
||||
|
||||
// let (ck, sk) = gen_keys();
|
||||
// sk.set_server_key();
|
||||
|
||||
// for i in 144..=255 {
|
||||
// for j in 100..=255 {
|
||||
// let m0 = i;
|
||||
// let m1 = j;
|
||||
// let c0 = ck.encrypt(&m0);
|
||||
// let c1 = ck.encrypt(&m1);
|
||||
|
||||
// assert!(ck.decrypt(&c0) == m0);
|
||||
// assert!(ck.decrypt(&c1) == m1);
|
||||
|
||||
// // Arithmetic
|
||||
// {
|
||||
// {
|
||||
// // Add
|
||||
// let mut c_m0_plus_m1 = FheUint8 {
|
||||
// data: c0.data().to_vec(),
|
||||
// };
|
||||
// c_m0_plus_m1 += &c1;
|
||||
// let m0_plus_m1 = ck.decrypt(&c_m0_plus_m1);
|
||||
// assert_eq!(
|
||||
// m0_plus_m1,
|
||||
// m0.wrapping_add(m1),
|
||||
// "Expected {} but got {m0_plus_m1} for {i}+{j}",
|
||||
// m0.wrapping_add(m1)
|
||||
// );
|
||||
// }
|
||||
// {
|
||||
// // Sub
|
||||
// let c_sub = &c0 - &c1;
|
||||
// let m0_sub_m1 = ck.decrypt(&c_sub);
|
||||
// assert_eq!(
|
||||
// m0_sub_m1,
|
||||
// m0.wrapping_sub(m1),
|
||||
// "Expected {} but got {m0_sub_m1} for {i}-{j}",
|
||||
// m0.wrapping_sub(m1)
|
||||
// );
|
||||
// }
|
||||
|
||||
// {
|
||||
// // Mul
|
||||
// let c_m0m1 = &c0 * &c1;
|
||||
// let m0m1 = ck.decrypt(&c_m0m1);
|
||||
// assert_eq!(
|
||||
// m0m1,
|
||||
// m0.wrapping_mul(m1),
|
||||
// "Expected {} but got {m0m1} for {i}x{j}",
|
||||
// m0.wrapping_mul(m1)
|
||||
// );
|
||||
// }
|
||||
|
||||
// // Div & Rem
|
||||
// {
|
||||
// let (c_quotient, c_rem) = c0.div_rem(&c1);
|
||||
// let m_quotient = ck.decrypt(&c_quotient);
|
||||
// let m_remainder = ck.decrypt(&c_rem);
|
||||
// if j != 0 {
|
||||
// let (q, r) = i.div_rem_euclid(&j);
|
||||
// assert_eq!(
|
||||
// m_quotient, q,
|
||||
// "Expected {} but got {m_quotient} for
|
||||
// {i}/{j}", q
|
||||
// );
|
||||
// assert_eq!(
|
||||
// m_remainder, r,
|
||||
// "Expected {} but got {m_quotient} for
|
||||
// {i}%{j}", r
|
||||
// );
|
||||
// } else {
|
||||
// assert_eq!(
|
||||
// m_quotient, 255,
|
||||
// "Expected 255 but got {m_quotient}. Case div
|
||||
// by zero" );
|
||||
// assert_eq!(
|
||||
// m_remainder, i,
|
||||
// "Expected {i} but got {m_quotient}. Case div
|
||||
// by zero" )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Comparisons
|
||||
// {
|
||||
// {
|
||||
// let c_eq = c0.eq(&c1);
|
||||
// let is_eq = ck.decrypt(&c_eq);
|
||||
// assert_eq!(
|
||||
// is_eq,
|
||||
// i == j,
|
||||
// "Expected {} but got {is_eq} for {i}=={j}",
|
||||
// i == j
|
||||
// );
|
||||
// }
|
||||
|
||||
// {
|
||||
// let c_gt = c0.gt(&c1);
|
||||
// let is_gt = ck.decrypt(&c_gt);
|
||||
// assert_eq!(
|
||||
// is_gt,
|
||||
// i > j,
|
||||
// "Expected {} but got {is_gt} for {i}>{j}",
|
||||
// i > j
|
||||
// );
|
||||
// }
|
||||
|
||||
// {
|
||||
// let c_lt = c0.lt(&c1);
|
||||
// let is_lt = ck.decrypt(&c_lt);
|
||||
// assert_eq!(
|
||||
// is_lt,
|
||||
// i < j,
|
||||
// "Expected {} but got {is_lt} for {i}<{j}",
|
||||
// i < j
|
||||
// );
|
||||
// }
|
||||
|
||||
// {
|
||||
// let c_ge = c0.ge(&c1);
|
||||
// let is_ge = ck.decrypt(&c_ge);
|
||||
// assert_eq!(
|
||||
// is_ge,
|
||||
// i >= j,
|
||||
// "Expected {} but got {is_ge} for {i}>={j}",
|
||||
// i >= j
|
||||
// );
|
||||
// }
|
||||
|
||||
// {
|
||||
// let c_le = c0.le(&c1);
|
||||
// let is_le = ck.decrypt(&c_le);
|
||||
// assert_eq!(
|
||||
// is_le,
|
||||
// i <= j,
|
||||
// "Expected {} but got {is_le} for {i}<={j}",
|
||||
// i <= j
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
use super::*;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user