Skip to content

Commit

Permalink
chore: clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jimouris committed May 29, 2024
1 parent 82e1b97 commit 7bd7bf8
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 21 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ num-integer = "0.1.46"
statrs = "0.16.0"
libm = "0.2.8"
csv = "1.3"
debug_print = "1.0.0"
dwt = "0.5.2"
linfa-datasets = { version = "0.7", features = ["iris", "winequality"] }
rayon = "1.7.0"
serde = { version = "1.0.114", features = ["derive"] }
serde_json = "1.0.114"
tfhe = { version = "0.6", features = ["boolean", "shortint", "integer"] }
ndarray = "0.15"

[features]
x86 = ["tfhe/x86_64-unix"]
Expand Down
8 changes: 4 additions & 4 deletions src/correlation_bior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ fn main() {
let (div_lut_lsb_2, div_lut_msb_2) =
bior("data/bior_lut_div_16_2.json", wave_depth as u8, bit_width);

let sqrt_luts = vec![
let sqrt_luts = [
&sqrt_lut_lsb,
&sqrt_lut_lsb_2,
&sqrt_lut_msb,
&sqrt_lut_msb_2,
];
let div_luts = vec![&div_lut_lsb, &div_lut_lsb_2, &div_lut_msb, &div_lut_msb_2];
let div_luts = [&div_lut_lsb, &div_lut_lsb_2, &div_lut_msb, &div_lut_msb_2];

// Number of blocks per ciphertext
let nb_blocks = bit_width / 2;
Expand Down Expand Up @@ -71,7 +71,7 @@ fn main() {
let start = Instant::now();
let encrypted_salaries: Vec<_> = salaries_sorted
.par_iter() // Use par_iter() for parallel iteration
.map(|&salary| client_key.encrypt(quantize(salary as f64, precision, bit_width as u8)))
.map(|&salary| client_key.encrypt(quantize(salary as f64, precision, bit_width)))
.collect();
println!(
"Encryption done in {:?} sec.",
Expand Down Expand Up @@ -178,7 +178,7 @@ fn main() {

// ------- Client side ------- //
let correlation: u64 = client_key.decrypt(&correlation_enc);
let correlation_final: f64 = unquantize(correlation, precision, bit_width as u8);
let correlation_final: f64 = unquantize(correlation, precision, bit_width);

println!("Correlation: {}", correlation_final / (scale as f64));
}
2 changes: 1 addition & 1 deletion src/correlation_lut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() {
// Offline: LUT genaration is offline cost.
let lut_gen_start = Instant::now();
println!("Generating LUT.");
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, (nb_blocks).into());
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, nb_blocks);
dummy = wopbs_key.keyswitch_to_wopbs_params(&server_key, &dummy);
let mut dummy_blocks = dummy.clone().into_blocks().to_vec();
for block in &mut dummy_blocks {
Expand Down
4 changes: 2 additions & 2 deletions src/correlation_quantized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ fn main() {
// Offline: LUT genaration is offline cost.
let lut_gen_start = Instant::now();
println!("Generating LUT.");
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, (nb_blocks).into());
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, nb_blocks);
dummy = wopbs_key.keyswitch_to_wopbs_params(&server_key, &dummy);
let mut dummy_blocks = dummy.clone().into_blocks().to_vec();
for block in &mut dummy_blocks {
block.degree = Degree::new(3);
}
dummy = RadixCiphertext::from_blocks(dummy_blocks[0..(nb_blocks as usize >> 1)].to_vec());
dummy = RadixCiphertext::from_blocks(dummy_blocks[0..(nb_blocks >> 1)].to_vec());
let sqrt_lut = wopbs_key.generate_lut_radix(&dummy, |x: u64| {
if x == 0 {
1 // avoid division with zero error.
Expand Down
3 changes: 1 addition & 2 deletions src/edge_detection_quantized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ fn main() {

let lut_gen_start = Instant::now();
println!("Generating LUT.");
let mut dummy: RadixCiphertext =
server_key.create_trivial_radix(2_u64, (nb_blocks >> 1).into());
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, nb_blocks >> 1);
dummy = wopbs_key.keyswitch_to_wopbs_params(&server_key, &dummy);
let mut dummy_blocks = dummy.clone().into_blocks().to_vec();
for block in &mut dummy_blocks {
Expand Down
2 changes: 1 addition & 1 deletion src/euclidean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn main() {
// ------- Server side ------- //
let lut_gen_start = Instant::now();
println!("Generating LUT.");
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, (nb_blocks).into());
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, nb_blocks);
dummy = wopbs_key.keyswitch_to_wopbs_params(&server_key, &dummy);
let mut dummy_blocks = dummy.clone().into_blocks().to_vec();
for block in &mut dummy_blocks {
Expand Down
8 changes: 4 additions & 4 deletions src/euclidean_bior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ fn main() {
let (div_lut_lsb, div_lut_msb) = bior("data/bior_lut_div_16.json", j as u8, bit_width);
let (div_lut_lsb_2, div_lut_msb_2) = bior("data/bior_lut_div_16_2.json", j as u8, bit_width);

let sqrt_luts = vec![
let sqrt_luts = [
&sqrt_lut_lsb,
&sqrt_lut_lsb_2,
&sqrt_lut_msb,
&sqrt_lut_msb_2,
];
let div_luts = vec![&div_lut_lsb, &div_lut_lsb_2, &div_lut_msb, &div_lut_msb_2];
let div_luts = [&div_lut_lsb, &div_lut_lsb_2, &div_lut_msb, &div_lut_msb_2];

// Number of blocks per ciphertext
let nb_blocks = bit_width / 2;
Expand All @@ -59,7 +59,7 @@ fn main() {
let start = Instant::now();
let xs_enc: Vec<_> = xs
.par_iter() // Use par_iter() for parallel iteration
.map(|&x| client_key.encrypt(quantize(x as f64, precision, bit_width as u8)))
.map(|&x| client_key.encrypt(quantize(x as f64, precision, bit_width)))
.collect();
println!(
"Encryption done in {:?} sec.",
Expand Down Expand Up @@ -165,7 +165,7 @@ fn main() {

// ------- Client side ------- //
let mean_distance: u64 = client_key.decrypt(&dists_mean_enc);
let mean_distance: f64 = unquantize(mean_distance, precision, bit_width as u8);
let mean_distance: f64 = unquantize(mean_distance, precision, bit_width);

println!(
"Mean of {} Euclidean distances: {}",
Expand Down
4 changes: 2 additions & 2 deletions src/euclidean_quantized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ fn main() {
// ------- Server side ------- //
let lut_gen_start = Instant::now();
println!("Generating LUT.");
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, (nb_blocks).into());
let mut dummy: RadixCiphertext = server_key.create_trivial_radix(2_u64, nb_blocks);
dummy = wopbs_key.keyswitch_to_wopbs_params(&server_key, &dummy);
let mut dummy_blocks = dummy.clone().into_blocks().to_vec();
for block in &mut dummy_blocks {
block.degree = Degree::new(3);
}
dummy = RadixCiphertext::from_blocks(dummy_blocks[0..(nb_blocks as usize >> 1)].to_vec());
dummy = RadixCiphertext::from_blocks(dummy_blocks[0..(nb_blocks >> 1)].to_vec());
let sqrt_lut = wopbs_key.generate_lut_radix(&dummy, |x: u64| x.sqrt());
let div_lut = wopbs_key.generate_lut_radix(&dummy, |x: u64| x / (num_iter as u64));
println!(
Expand Down
1 change: 0 additions & 1 deletion src/lr_haar_ptxt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// use debug_print::debug_println;
use rayon::prelude::*;
use ripple::common::*;

Expand Down
1 change: 0 additions & 1 deletion src/lr_ptxt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// use debug_print::debug_println;
use rayon::prelude::*;
use ripple::common::*;

Expand Down

0 comments on commit 7bd7bf8

Please sign in to comment.