From 6e8db2509b93dd290a2b0dc6cf6da1a4d28a0600 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:34:42 +0100 Subject: [PATCH 1/2] feat: update `coeffs` correct --- Cargo.toml | 2 +- src/poly/dcrt/poly.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e9fba28..3065f4be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ test = [] parallel = ["rayon"] [dependencies] -openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git", branch = "refactor2" } +openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git", branch = "feat/get_coeffs_to_bytes" } digest = "0.10" num-bigint = { version = "0.4", default-features = false } num-traits = "0.2" diff --git a/src/poly/dcrt/poly.rs b/src/poly/dcrt/poly.rs index 08cff0bb..08663358 100644 --- a/src/poly/dcrt/poly.rs +++ b/src/poly/dcrt/poly.rs @@ -11,6 +11,7 @@ use num_bigint::BigUint; use openfhe::{ cxx::UniquePtr, ffi::{self, DCRTPoly as DCRTPolyCxx}, + parse_coefficients_bytes, }; use std::{ @@ -75,10 +76,13 @@ impl Poly for DCRTPoly { type Params = DCRTPolyParams; fn coeffs(&self) -> Vec { - let coeffs = self.ptr_poly.GetCoefficients(); - let modulus = self.ptr_poly.GetModulus(); + let poly_encoding = self.ptr_poly.GetCoefficientsBytes(); + let parsed_values = parse_coefficients_bytes(&poly_encoding); + let coeffs = &parsed_values[..parsed_values.len() - 1]; + let modulus = &parsed_values[parsed_values.len() - 1]; + // TODO: avoid cloning parallel_iter!(coeffs) - .map(|s| FinRingElem::from_str(&s, &modulus).expect("invalid string")) + .map(|s| FinRingElem::new(s.clone(), Arc::new(modulus.clone()))) .collect() } From 04f4d9d7e31dd9965c7740864f175557eb3a3391 Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:54:59 +0100 Subject: [PATCH 2/2] feat: update `coeffs` --- Cargo.toml | 2 +- src/poly/dcrt/poly.rs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3065f4be..bce848bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ test = [] parallel = ["rayon"] [dependencies] -openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git", branch = "feat/get_coeffs_to_bytes" } +openfhe = { git = "https://github.com/MachinaIO/openfhe-rs.git", branch = "feat/get_coeffs_to_bytes_perf" } digest = "0.10" num-bigint = { version = "0.4", default-features = false } num-traits = "0.2" diff --git a/src/poly/dcrt/poly.rs b/src/poly/dcrt/poly.rs index 08663358..6c32f4dd 100644 --- a/src/poly/dcrt/poly.rs +++ b/src/poly/dcrt/poly.rs @@ -78,12 +78,9 @@ impl Poly for DCRTPoly { fn coeffs(&self) -> Vec { let poly_encoding = self.ptr_poly.GetCoefficientsBytes(); let parsed_values = parse_coefficients_bytes(&poly_encoding); - let coeffs = &parsed_values[..parsed_values.len() - 1]; - let modulus = &parsed_values[parsed_values.len() - 1]; - // TODO: avoid cloning - parallel_iter!(coeffs) - .map(|s| FinRingElem::new(s.clone(), Arc::new(modulus.clone()))) - .collect() + let coeffs = parsed_values.coefficients; + let modulus = parsed_values.modulus; + parallel_iter!(coeffs).map(|s| FinRingElem::new(s, Arc::new(modulus.clone()))).collect() } fn from_coeffs(params: &Self::Params, coeffs: &[Self::Elem]) -> Self {