From 27e56f02ca47c5b1b16a17e008f91b74078be259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20P=C3=A9r=C3=A9?= Date: Tue, 1 Oct 2024 16:14:06 +0200 Subject: [PATCH] fix(frontend-python): correct operator precedence --- .../tests/compilation/test_modules.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/frontends/concrete-python/tests/compilation/test_modules.py b/frontends/concrete-python/tests/compilation/test_modules.py index e3ea233c2d..6d9d6c0460 100644 --- a/frontends/concrete-python/tests/compilation/test_modules.py +++ b/frontends/concrete-python/tests/compilation/test_modules.py @@ -343,7 +343,7 @@ def test_print(helpers): class Module: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 inputset = list(range(20)) module = Module.compile( @@ -351,10 +351,12 @@ def inc(x): ) helpers.check_str( """ -%0 = x # EncryptedScalar ∈ [0, 19] -%1 = 1 # ClearScalar ∈ [1, 1] -%2 = add(%0, %1) # EncryptedScalar ∈ [1, 20] -return %2 +%0 = x # EncryptedScalar ∈ [0, 19] +%1 = 1 # ClearScalar ∈ [1, 1] +%2 = add(%0, %1) # EncryptedScalar ∈ [1, 20] +%3 = 20 # ClearScalar ∈ [20, 20] +%4 = remainder(%2, %3) # EncryptedScalar ∈ [0, 19] +return %4 """, str(module.inc), ) @@ -369,11 +371,11 @@ def test_encrypted_execution(): class Module: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 @fhe.function({"x": "encrypted"}) def dec(x): - return x - 1 % 20 + return (x - 1) % 20 inputset = [np.random.randint(1, 20, size=()) for _ in range(100)] module = Module.compile( @@ -407,11 +409,11 @@ def test_key_set(): class Module: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 @fhe.function({"x": "encrypted"}) def dec(x): - return x - 1 % 20 + return (x - 1) % 20 inputset = [np.random.randint(1, 20, size=()) for _ in range(100)] module = Module.compile( @@ -596,11 +598,11 @@ def test_simulate_encrypt_run_decrypt(helpers): class Module: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 @fhe.function({"x": "encrypted"}) def dec(x): - return x - 1 % 20 + return (x - 1) % 20 inputset = [np.random.randint(1, 20, size=()) for _ in range(100)] module = Module.compile( @@ -808,7 +810,7 @@ def test_lazy_simulation_execution(helpers): class Module1: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 module = Module1.compile( {"inc": [np.random.randint(1, 20, size=()) for _ in range(100)]}, @@ -829,7 +831,7 @@ def inc(x): class Module2: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 module = Module2.compile( {"inc": [np.random.randint(1, 20, size=()) for _ in range(100)]}, @@ -848,7 +850,7 @@ def inc(x): class Module3: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 module = Module3.compile( {"inc": [np.random.randint(1, 20, size=()) for _ in range(100)]}, @@ -867,7 +869,7 @@ def inc(x): class Module4: @fhe.function({"x": "encrypted"}) def inc(x): - return x + 1 % 20 + return (x + 1) % 20 module = Module4.compile( {"inc": [np.random.randint(1, 20, size=()) for _ in range(100)]},