Skip to content

Commit

Permalink
Merge pull request #1155 from zama-ai/fix/test_modules_precedence_2
Browse files Browse the repository at this point in the history
fix(frontend-python): correct operator precedence
  • Loading branch information
aPere3 authored Dec 2, 2024
2 parents 819e6da + 27e56f0 commit 85f1643
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions frontends/concrete-python/tests/compilation/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,20 @@ 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(
{"inc": inputset},
)
helpers.check_str(
"""
%0 = x # EncryptedScalar<uint5> ∈ [0, 19]
%1 = 1 # ClearScalar<uint1> ∈ [1, 1]
%2 = add(%0, %1) # EncryptedScalar<uint5> ∈ [1, 20]
return %2
%0 = x # EncryptedScalar<uint5> ∈ [0, 19]
%1 = 1 # ClearScalar<uint1> ∈ [1, 1]
%2 = add(%0, %1) # EncryptedScalar<uint5> ∈ [1, 20]
%3 = 20 # ClearScalar<uint5> ∈ [20, 20]
%4 = remainder(%2, %3) # EncryptedScalar<uint5> ∈ [0, 19]
return %4
""",
str(module.inc),
)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -809,7 +811,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)]},
Expand All @@ -830,7 +832,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)]},
Expand All @@ -849,7 +851,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)]},
Expand All @@ -868,7 +870,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)]},
Expand Down

0 comments on commit 85f1643

Please sign in to comment.