From 949fb879cca0c5dd6d80149c27b11ca7086665eb Mon Sep 17 00:00:00 2001 From: BGluth Date: Fri, 14 May 2021 20:15:03 -0600 Subject: [PATCH 1/2] Switched over from OsRng --> thread_rng - At least on my Linux machine, a signiciant amount of time (> 50%) was spent inside OsRng. - Likely due to blocking behaviour of the rng devices on Linux. - thread_rng should not block, but at the same time should provide good enough rng. --- src/field/field.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/field/field.rs b/src/field/field.rs index 0249610f..4025c968 100644 --- a/src/field/field.rs +++ b/src/field/field.rs @@ -267,7 +267,7 @@ pub trait Field: } fn rand() -> Self { - Self::rand_from_rng(&mut OsRng) + Self::rand_from_rng(&mut rand::thread_rng()) } fn rand_vec(n: usize) -> Vec { From 1e5dfa405bba1cfab8a21b8d0d680f4f40e5aae9 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Mon, 17 May 2021 10:37:43 -0700 Subject: [PATCH 2/2] Fix intermittent inv_mod_xn failure My recent change made `padded` panic if the padded length is less than the current length. I figured that might indicate that something unexpected was going on, so might be good to fail fast. It looks like `inv_mod_xn` was relying on the old `padded` behavior, and it seems correct AFAIK, i.e. in this case it wasn't a symptom of anything going wrong. We could also restore the old behavior of `padded` if you prefer; let me know if you have a preferennce. --- src/polynomial/division.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/polynomial/division.rs b/src/polynomial/division.rs index a893c509..8e3c2676 100644 --- a/src/polynomial/division.rs +++ b/src/polynomial/division.rs @@ -128,7 +128,13 @@ impl PolynomialCoeffs { /// Computes the inverse of `self` modulo `x^n`. pub(crate) fn inv_mod_xn(&self, n: usize) -> Self { assert!(self.coeffs[0].is_nonzero(), "Inverse doesn't exist."); - let mut h = self.padded(n); + + let h = if self.len() < n { + self.padded(n) + } else { + self.clone() + }; + let mut a = Self::empty(); a.coeffs.push(h.coeffs[0].inverse()); for i in 0..log2_ceil(n) {