From 93629e9a9c4890e2ba89561540e5eba3e53cf639 Mon Sep 17 00:00:00 2001 From: Ben <16917183+bencrts@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:31:31 +0000 Subject: [PATCH] bugfix(lwe_primal): fix precision error in log computation --- estimator/lwe_primal.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/estimator/lwe_primal.py b/estimator/lwe_primal.py index 80fed53..e545c59 100644 --- a/estimator/lwe_primal.py +++ b/estimator/lwe_primal.py @@ -310,7 +310,13 @@ def gaussian_heuristic_log_input(r): return exp(log_gh) d = len(r) - r = [log(x) for x in r] + try: + r = [log(x) for x in r] + except ValueError: + # shift and re-compute + c_shift = 1e-300 + r = [log(c_shift) + log(x / c_shift) for x in r] + print(r) if d > 4096: for i, _ in enumerate(r):