Skip to content

Commit

Permalink
fix(frontend-python): correct operator precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
aPere3 committed Dec 2, 2024
1 parent bb423df commit 27e56f0
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 @@ -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)]},
Expand All @@ -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)]},
Expand All @@ -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)]},
Expand All @@ -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)]},
Expand Down

0 comments on commit 27e56f0

Please sign in to comment.